The included set of the standard functions is implemented in many DBMS, but only small part of them is implemented in SQLite. The mechanism of User-Defined Functions can be used for solving this task. You can define your own implementation of necessary function with the help of this mechanism.
dotConnect for SQLite gives a set of the abstract classes (SQLiteFunction and its descendants). and method for their registration in DBMS - RegisterFunction method in the SQLiteConnection class.
These functions are described in the table below:
To simplify work with SQLite, we have defined the set of the standard SQL functions in the dotConnect for SQLite.
The tables below contain an information about implemented standard functions that were grouped by their purposes:
| Function | Definition | Example | Remarks |
|---|---|---|---|
| FLOOR(expession) | Returns the largest integer less than or equal to the specified numeric expression. |
The following example shows positive number, negative number, and string argument with the FLOOR function |
For integer arguments, the return value has integer type. |
| CEILING(expession) | Returns the smallest integer greater than, or equal to, the specified numeric expression. |
The following example shows positive number, negative number, and string argument with the CEILING function |
For integer arguments, the return value has integer type. |
| POWER(expression, y) | Returns the value of the specified expression to the specified power. |
The following example returns POWER results; |
expression is an expression of type floating-point or of a type that can be implicitly converted to floating-point type. |
| TRUNCATE(expression, digits) | Returns the value, truncated to the nearest specified digits. |
The following example returns truncated value to the one digit after decimal point; |
expression is an expression of type floating-point or of a type that can be implicitly converted to floating-point type. |
| SQRT(expression) | Returns the square root of the specified floating-point value |
The following example returns the square root of 16; |
expression is an expression of type floating-point or of a type that can be implicitly converted to floating-point type. |
| COS(expression) | Returns the trigonometric cosine of the specified angle, in radians, in the specified expression. |
The following example returns the COS of the specific angle. |
expression is an expression of type floating-point or of a type that can be implicitly converted to floating-point type. |
| SIN(expression) | Returns the trigonometric sine of the specified angle, in radians, in the specified expression. |
The following example returns the SIN of the specific angle. |
expression is an expression of type floating-point or of a type that can be implicitly converted to floating-point type. |
| ACOS(expression) | Returns the angle, in radians, whose cosine is the specified floating-point expression; also called arccosine. |
The following example returns the ACOS of the specified number |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type, with a value from -1 through 1. |
| ASIN(expression) | Returns the angle, in radians, whose sine is the specified floating-point expression; also called arcsine. |
The following example returns the ASIN of the specified number |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type,
with a value from -1 through 1. |
| ATAN(expression) | Returns the angle in radians whose tangent is a specified floating-point expression. This is also called arctangent. |
The following example returns the ATAN of the specified number |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| ATAN2(expression1, expression2) | Returns the angle, in radians, between the positive x-axis and the ray from the origin to the point (y, x), where x and y are the values of the two specified floating-point expressions. |
The following example calculates the ATN2 for the specified x = 1.5 and y =2.0 components |
expression1, expression1 are expressions of the float type or of a type that can be implicitly converted to floating-point type. |
| COT(expression) | Returns the trigonometric cotangent of the specified angle, in radians, in the specified floating-point expressions. |
The following example returns the COT for the specific angle. |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| PI() | Returns the constant value of PI. |
The following example returns the value of PI: |
Return Types: floating-point type. |
| DEGREES(expression) | Returns the corresponding angle in degrees for an angle specified in radians. |
The following example returns the number of degrees in an angle of PI/2 radians: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| EXP(expression) | Returns the exponential value of the specified floating-point expression. |
The following example returns the exponential value of the 10: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| LOG(expression) | Returns the natural logarithm of the specified floating-point expression. |
The following example calculates the LOG for the specified number 2.718: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| LOG(base,expression) | Returns the logarithm of the specified floating-point expression an arbitrary base. |
The following example calculates the base-2 LOG for the specified number 8: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| LOG10(expression) | Returns the base-10 logarithm of the specified floating-point expression. |
The following example calculates the LOG10 of the specified value: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| RADIANS(expression) | Returns radians when a numeric expression, in degrees, is entered. |
The following example returns the number of radians in an angle of 90 degrees: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| SIGN(expression) | Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression. |
The following example returns the SIGN values of number -2.34: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type. |
| TAN(expression) | Returns the tangent of the input expression. |
The following example returns the tangent of 2.5: |
expression is an expression of the type float or of a type that can be implicitly converted to floating-point type,
interpreted as number of radians. |
| Function | Definition | Example | Remarks |
|---|---|---|---|
| CONTAINS(substr, str) | Returns true if substr is contained in string. |
The following example returns 1: |
Returns 1 or 0 to indicate whether 'str' completely contains 'substr'. |
| INDEXOF(substr, str, pos) | Returns the position of the first occurrence of substring 'substr' in string 'str', starting at position 'pos'. |
The following example returns 4: |
Returns 0 if 'substr' is not in 'str'. |
| STARTSWITH(substr, str) | Returns 1 or 0 to indicate whether the beginning of 'str' matches the 'substr'. |
The following example returns 1: |
Returns 0 if 'substr' is not in 'str'. |
| ENDSWITH(substr, str) | Returns 1 or 0 to indicate whether the end of 'str' matches the 'substr'. |
The following example returns 1: |
Returns 0 if 'substr' is not in 'str'. |
| REVERSE(str) | Returns the string 'str' with the order of the characters reversed. |
The following example returns dcba: |
Returns 0 if 'substr' is not in 'str'. |
| Function | Definition | Example | Remarks |
|---|---|---|---|
| ADDNANOSECONDS (expression, number) | Adds the specified 'number' of nanoseconds to the 'expression'. |
The following example adding 500 nanoseconds to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDMICROSECONDS(expression, number) | Adds the specified 'number' of microseconds to the 'expression'. |
The following example adding 500 microseconds to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDMILLISECONDS (expression, number) | Adds the specified 'number' of milliseconds to the 'expression'. |
The following example adding 500 milliseconds to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDSECONDS (expression, number) | Adds the specified 'number' of seconds to the 'expression'. |
TThe following example adding -12 seconds to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDMINUTES (expression, number) | Adds the specified 'number' of minutes to the 'expression'. |
The following example adding 10 minutes to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDMINUTES (expression, number) | Adds the specified 'number' of minutes to the 'expression'. |
The following example adding 10 minutes to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDHOURS (expression, number) | Adds the specified 'number' of hours to the 'expression'. |
The following example adding -5 hours to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDDAYS (expression, number) | Adds the specified 'number' of days to the 'expression'. |
The following example adding 5 days to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDMONTHS (expression, number) | Adds the specified 'number' of months to the 'expression'. |
The following example adding 5 months to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| ADDYEARS (expression, number) | Adds the specified 'number' of years to the 'expression'. |
The following example adding 5 years to the specified time: |
expression is an expression of the string type that represents Datetime, Time or DateTimeOffset value. |
| CREATEDATETIME(year, month, day, hour, minute, second) | Returns a datetime value as the value calculated from the 'year', 'month', 'day', 'hour', 'minute', and 'second' arguments. |
The following example return new datetime value: |
year, month, day, hour, minute, second are values of integer type or values of a type that can be implicitly converted to integer type,
Returns NULL when any of arguments is NULL. |
| CREATEDATETIMEOFFSET(year, month, day, hour, minute, second, tzoffset) | Returns a datetime value as the current date and time relative to the Coordinated Universal Time (UTC). |
The following example return new datetimeoffset value: |
year, month, day, hour, minute, second, tzoffset are values of integer type or values of a type
that can be implicitly converted to integer type,
tzoffset = between from -840 to 840 minutes (-14 to +14 hours) |
| CREATETIME(year, month, day, hour, minute, second) | Returns a time value as the value calculated from the 'hour', 'minute', and 'second' arguments. |
The following example return new time value: |
hour, minute, second are values of integer type or values
of a type that can be implicitly converted to integer type. |
| CURRENTDATETIMEOFFSET() | Returns a datetime value as the current date and time relative to the Coordinated Universal Time (UTC). |
The following example return current datetimeoffset value: |
Return Value: a string representation of Time. |
| DATETIMEINTERVAL(startExpression, endExpression) | Returns the date and time interval between 'startExpression' and 'endExpression'. |
The following example return time interval between two datetime values: |
startExpression, endExpression are expressions of the string type
that represents Datetime, Time or DateTimeOffset value. |
| DIFFMONTHS(startExpression, endExpression) | Returns the difference, in months, between ''startExpression' and 'endExpression'. |
The following example return number of months between two datetime values: |
startExpression, endExpression are expressions of the string
type that represents Datetime, Time or DateTimeOffset value. |
| DIFFYEARS(startExpression, endExpression) | Returns the difference, in years, between ''startExpression' and 'endExpression'. |
The following example return number of years between two datetime values: |
startExpression, endExpression are expressions of the string type that
represents Datetime, Time or DateTimeOffset value. |
| GETTOTALOFFSETMINUTES(datetimeoffset) | Returns the number of minutes that the datetimeoffset is offset from GMT. This is generally between +840 and -840 (+ or - 14 hrs). |
The following example return offset minutes from specified datetimeoffset: |
datetimeoffset is an expression of the string type that represents DateTimeOffset value. |
| TRUNCATE(expression) | Returns the expression, with the time values truncated. |
The following example return truncated datetime: |
expression is an expression of the string type
that represents Datetime, Time or DateTimeOffset value. |
| Function | Definition | Example | Remarks |
|---|---|---|---|
| BITWISEAND(x_expr, y_expr) | Returns the bitwise conjunction of 'x_expr' and 'y_expr'. |
The following example return bitwise conjunction of two integer numbers: |
x_expr, y_expr are expressions of the integer types or expressions of a type
that can be implicitly converted to integer types. |
| BITWISEOR(x_expr, y_expr) | Returns the bitwise disjunction of 'x_expr' and 'y_expr'. |
The following example return bitwise disjunction of two integer numbers: |
x_expr, y_expr - are expressions of the integer types or expressions of a type that can be implicitly converted to integer types. |
| BITWISEXOR(x_expr, y_expr) | Returns the bitwise exclusive disjunction of 'x_expr' and 'y_expr'. |
The following example return bitwise exclusive disjunction of two integer numbers: |
x_expr, y_expr are expressions of the integer types or expressions of a type that
can be implicitly converted to integer types. |
| BITWISENOT(x_expr) | Returns the bitwise negation of 'x_expr'. |
The following example return bitwise bitwise negation integer number: |
x_expr is an expression of the integer types or expression of a type that can
be implicitly converted to integer types. |
| Function | Definition | Example | Remarks |
|---|---|---|---|
| NEWGUID(x_expr) | Returns a new GUID as string. |
The following example return bitwise bitwise negation integer number: |