FunctionsIndexAggregate Functions
Numeric FunctionsString FunctionsTime and Date Functions
System FunctionsDetailsClick on the header to switch between railroad diagram and BNF. AVG
The average (mean) value. If no rows are selected, the result is Example: AVG(X) BOOL_AND
Returns true if all expressions are true. If no rows are selected, the result is Example: BOOL_AND(ID>10) BOOL_OR
Returns true if any expression is true. If no rows are selected, the result is Example: BOOL_OR(NAME LIKE 'W%') COUNT
The count of all row, or of the non-null values. This method returns a long. If no rows are selected, the result is 0. Aggregates are only allowed in select statements. Example: COUNT(*) GROUP_CONCATConcatenates strings with a separator. The default separator is a ',' (without space). This method returns a string. If no rows are selected, the result is Example: GROUP_CONCAT(NAME ORDER BY ID SEPARATOR ', ') MAX
The highest value. If no rows are selected, the result is Example: MAX(NAME) MIN
The lowest value. If no rows are selected, the result is Example: MIN(NAME) SUM
The sum of all values. If no rows are selected, the result is Example: SUM(X) SELECTIVITY
Estimates the selectivity (0-100) of a value. The value is defined as (100 * distinctCount / rowCount). The selectivity of 0 rows is 0 (unknown). Up to 10000 values are kept in memory. Aggregates are only allowed in select statements. Example: SELECT SELECTIVITY(FIRSTNAME), SELECTIVITY(NAME) FROM TEST WHERE ROWNUM()<20000 STDDEV_POP
The population standard deviation. This method returns a double. If no rows are selected, the result is Example: STDDEV_POP(X) STDDEV_SAMP
The sample standard deviation. This method returns a double. If no rows are selected, the result is Example: STDDEV(X) VAR_POP
The population variance (square of the population standard deviation). This method returns a double. If no rows are selected, the result is Example: VAR_POP(X) VAR_SAMP
The sample variance (square of the sample standard deviation). This method returns a double. If no rows are selected, the result is Example: VAR_SAMP(X) ABS
See also Java Example: ABS(ID) ACOS
Calculate the arc cosine. See also Java Example: ACOS(D) ASIN
Calculate the arc sine. See also Java Example: ASIN(D) ATAN
Calculate the arc tangent. See also Java Example: ATAN(D) COS
Calculate the trigonometric cosine. See also Java Example: COS(ANGLE) COSH
Calculate the hyperbolic cosine. See also Java Example: COSH(X) COT
Calculate the trigonometric cotangent ( Example: COT(ANGLE) SIN
Calculate the trigonometric sine. See also Java Example: SIN(ANGLE) SINH
Calculate the hyperbolic sine. See also Java Example: SINH(ANGLE) TAN
Calculate the trigonometric tangent. See also Java Example: TAN(ANGLE) TANH
Calculate the hyperbolic tangent. See also Java Example: TANH(X) ATAN2Calculate the angle when converting the rectangular coordinates to polar coordinates. See also Java Example: ATAN2(X, Y) BITANDThe bitwise Example: BITAND(A, B) BITORThe bitwise Example: BITOR(A, B) BITXORThe bitwise Example: BITXOR(A, B) MODThe modulo operation. This method returns a long. See also Java operator %. Example: MOD(A, B) CEILING
See also Java Example: CEIL(A) DEGREES
See also Java Example: DEGREES(A) EXP
See also Java Example: EXP(A) FLOOR
See also Java Example: FLOOR(A) LOG
See also Java Example: LOG(A) LOG10
See also Java Example: LOG10(A) RADIANS
See also Java Example: RADIANS(A) SQRT
See also Java Example: SQRT(A) PI
See also Java Example: PI() POWERSee also Java Example: POWER(A, B) RAND
Calling the function without parameter returns the next a pseudo random number. Calling it with an parameter seeds the session's random number generator. This method returns a double between 0 (including) and 1 (excluding). Example: RAND() RANDOM_UUID
Returns a new Please note that using an index on randomly generated data will result on poor performance once there are millions of rows in a table. The reason is that the cache behavior is very bad with randomly distributed data. This is a problem for any database system. Example: RANDOM_UUID() ROUNDRounds to a number of digits, or to the nearest long if the number of digits if not set. This method returns a double. Example: ROUND(VALUE, 2) ROUNDMAGIC
This function rounds numbers in a good way, but it is slow. It has a special handling for numbers around 0. Only numbers smaller or equal +/-1000000000000 are supported. The value is converted to a String internally, and then the last last 4 characters are checked. '000x' becomes '0000' and '999x' becomes '999999', which is rounded automatically. This method returns a double. Example: ROUNDMAGIC(VALUE/3*3) SECURE_RAND
Generates a number of cryptographically secure random numbers. This method returns bytes. Example: CALL SECURE_RAND(16) SIGN
Returns -1 if the value is smaller 0, 0 if zero, and otherwise 1. Example: SIGN(VALUE) ENCRYPT
Encrypts data using a key. The supported algorithm is Example: CALL ENCRYPT('AES', '00', STRINGTOUTF8('Test')) DECRYPT
Decrypts data using a key. The supported algorithm is Example: CALL TRIM(CHAR(0) FROM UTF8TOSTRING( HASH
Calculate the hash value using an algorithm, and repeat this process for a number of iterations. Currently, the only algorithm supported is Example: CALL HASH('SHA256', STRINGTOUTF8('Password'), 1000) TRUNCATETruncates to a number of digits (to the next value closer to 0). This method returns a double. When used with a timestamp, truncates a timestamp to a date (day) value. Example: TRUNCATE(VALUE, 2) COMPRESS
Compresses the data using the specified compression algorithm. Supported algorithms are: Example: COMPRESS(STRINGTOUTF8('Test')) EXPAND
Expands data that was compressed using the Example: UTF8TOSTRING(EXPAND(COMPRESS(STRINGTOUTF8('Test')))) ZERO
Returns the value 0. This function can be used even if numeric literals are disabled. Example: ZERO() ASCII
Returns the Example: ASCII('Hi') BIT_LENGTH
Returns the number of bits in a string. This method returns a long. For Example: BIT_LENGTH(NAME) LENGTH
Returns the number of characters in a string. This method returns a long. For Example: LENGTH(NAME) OCTET_LENGTH
Returns the number of bytes in a string. This method returns a long. For Example: OCTET_LENGTH(NAME) CHAR
Returns the character that represents the Example: CHAR(65) CONCATCombines strings. Unlike with the operator Example: CONCAT(NAME, '!') CONCAT_WS
Combines strings with separator. Unlike with the operator Example: CONCAT_WS(',', NAME, '!') DIFFERENCEReturns the difference between the sounds of two strings. This method returns an int. Example: DIFFERENCE(T1.NAME, T2.NAME) HEXTORAW
Converts a hex representation of a string to a string. 4 hex characters per string character are used. Example: HEXTORAW(DATA) RAWTOHEX
Converts a string to the hex representation. 4 hex characters per string character are used. This method returns a string. Example: RAWTOHEX(DATA) INSTR
Returns the location of a search string in a string. If a start position is used, the characters before it are ignored. If position is negative, the rightmost location is returned. 0 is returned if the search string is not found. Example: INSTR(EMAIL,'@') INSERT Function
Inserts a additional string into the original string at a specified start position. The length specifies the number of characters that are removed at the start position in the original string. This method returns a string. Example: INSERT(NAME, 1, 1, ' ') LOWER
Converts a string to lowercase. Example: LOWER(NAME) UPPER
Converts a string to uppercase. Example: UPPER(NAME) LEFTReturns the leftmost number of characters. Example: LEFT(NAME, 3) RIGHTReturns the rightmost number of characters. Example: RIGHT(NAME, 3) LOCATE
Returns the location of a search string in a string. If a start position is used, the characters before it are ignored. If position is negative, the rightmost location is returned. 0 is returned if the search string is not found. Example: LOCATE('.', NAME) POSITION
Returns the location of a search string in a string. See also Example: POSITION('.', NAME) LPAD
Left pad the string to the specified length. If the length is shorter than the string, it will be truncated at the end. If the padding string is not set, spaces will be used. Example: LPAD(AMOUNT, 10, '*') RPAD
Right pad the string to the specified length. If the length is shorter than the string, it will be truncated. If the padding string is not set, spaces will be used. Example: RPAD(TEXT, 10, '-') LTRIM
Removes all leading spaces from a string. Example: LTRIM(NAME) RTRIM
Removes all trailing spaces from a string. Example: RTRIM(NAME) TRIMRemoves all leading spaces, trailing spaces, or spaces at both ends, from a string. Other characters can be removed as well. Example: TRIM(BOTH '_' FROM NAME) REGEXP_REPLACE
Replaces each substring that matches a regular expression. For details, see the Java Example: REGEXP_REPLACE('Hello World', ' +', ' ') REPEATReturns a string repeated some number of times. Example: REPEAT(NAME || ' ', 10) REPLACE
Replaces all occurrences of a search string in a text with another string. If no replacement is specified, the search string is removed from the original string. If any parameter is null, the result is null. Example: REPLACE(NAME, ' ') SOUNDEX
Returns a four character code representing the sound of a string. See also http://www.archives.gov/genealogy/census/soundex.html . This method returns a string. Example: SOUNDEX(NAME) SPACE
Returns a string consisting of a number of spaces. Example: SPACE(80) STRINGDECODE
Converts a encoded string using the Java string literal encoding format. Special characters are \b, \t, \n, \f, \r, \", \\, \<octal>, \u<unicode>. This method returns a string. Example: CALL STRINGENCODE(STRINGDECODE('Lines 1\nLine 2')) STRINGENCODE
Encodes special characters in a string using the Java string literal encoding format. Special characters are \b, \t, \n, \f, \r, \", \\, \<octal>, \u<unicode>. This method returns a string. Example: CALL STRINGENCODE(STRINGDECODE('Lines 1\nLine 2')) STRINGTOUTF8
Encodes a string to a byte array using the Example: CALL UTF8TOSTRING(STRINGTOUTF8('This is a test')) SUBSTRINGReturns a substring of a string starting at a position. If the start index is negative, then the start index is relative to the end of the string. The length is optional. Also supported is: Example: CALL SUBSTR('[Hello]', 2, 5); UTF8TOSTRING
Decodes a byte array in the Example: CALL UTF8TOSTRING(STRINGTOUTF8('This is a test')) XMLATTR
Creates an XML attribute element of the form Example: CALL XMLNODE('a', XMLATTR('href', 'http://lealone.com')) XMLNODE
Create an XML node element. An empty or null attribute string means no attributes are set. An empty or null content string means the node is empty. The content is indented by default if it contains a newline. This method returns a string. Example: CALL XMLNODE('a', XMLATTR('href', 'http://lealone.com'), 'lealone') XMLCOMMENT
Creates an XML comment. Two dashes ( Example: CALL XMLCOMMENT('Test') XMLCDATA
Creates an Example: CALL XMLCDATA('data') XMLSTARTDOC
Returns the XML declaration. The result is always Example: CALL XMLSTARTDOC() XMLTEXT
Creates an XML text element. If enabled, newline and linefeed is converted to an XML entity (&#). This method returns a string. Example: CALL XMLTEXT('test') TO_CHAR
Oracle-compatible Example: CALL TO_CHAR(TIMESTAMP '2010-01-01 00:00:00', 'DD MON, YYYY') TRANSLATE
Oracle-compatible Example: CALL TRANSLATE('Hello world', 'eo', 'EO') ARRAY_GET
Returns one element of an array. This method returns a string. Example: CALL ARRAY_GET(('Hello', 'World'), 2) ARRAY_LENGTH
Returns the length of an array. Example: CALL ARRAY_LENGTH(('Hello', 'World')) ARRAY_CONTAINS
Returns a boolean true if the array contains the value. Example: CALL ARRAY_CONTAINS(('Hello', 'World'), 'Hello') AUTOCOMMIT
Returns true if auto commit is switched on for this session. Example: AUTOCOMMIT() CANCEL_SESSION
Cancels the currently executing statement of another session. The method only works if the multithreaded kernel is enabled (see Admin rights are required to execute this command. Example: CANCEL_SESSION(3) CASEWHEN FunctionReturns 'a' if the boolean expression is true, otherwise 'b'. Returns the same data type as the parameter. Example: CASEWHEN(ID=1, 'A', 'B') CASTConverts a value to another data type. The following conversion rules are used: When converting a number to a boolean, 0 is false and every other value is true. When converting a boolean to a number, false is 0 and true is 1. When converting a number to a number of another type, the value is checked for overflow. When converting a number to binary, the number of bytes matches the precision. When converting a string to binary, it is hex encoded (every byte two characters); a hex string can be converted to a number by first converting it to binary. If a direct conversion is not possible, the value is first converted to a string. Example: CAST(NAME AS INT); COALESCEReturns the first value that is not null. Example: COALESCE(A, B, C) CONVERTConverts a value to another data type. Example: CONVERT(NAME, INT) CURRVAL
Returns the current (last) value of the sequence, independent of the session. If the sequence was just created, the method returns (start - interval). If the schema name is not set, the current schema is used. If the schema name is not set, the sequence name is converted to uppercase (for compatibility). This method returns a long. Example: CURRVAL('TEST_SEQ') CSVREAD
Returns the result set of reading the If the column names are specified (a list of column names separated with the fieldSeparator), those are used, otherwise (or if they are set to The default charset is the default value for this system, and the default field separator is a comma. Missing unquoted values as well as data that matches nullString is parsed as The This function can be used like a table: Instead of a file, an URL may be used, for example For performance reason, Admin rights are required to execute this command. Example: CALL CSVREAD('test.csv'); CSVWRITE
Writes a The values are converted to text using the default string representation; if another conversion is required you need to change the select statement accordingly. The parameter nullString is used when writing The returned value is the number or rows written. Admin rights are required to execute this command. Example: CALL CSVWRITE('data/test.csv', 'SELECT * FROM TEST'); DATABASE
Returns the name of the database. Example: CALL DATABASE(); DATABASE_PATH
Returns the directory of the database files and the database name, if it is file based. Returns Example: CALL DATABASE_PATH(); DECODEReturns the first matching value. Example: CALL DECODE(RAND()>0.5, 0, 'Red', 1, 'Black'); DISK_SPACE_USED
Returns the approximate amount of space used by the table specified. Does not currently take into account indexes or Example: CALL DISK_SPACE_USED('my_table'); FILE_READ
Returns the contents of a file. If only one parameter is supplied, the data are returned as a File names and URLs are supported. To read a stream from the classpath, use the prefix Admin rights are required to execute this command. Example: SELECT LENGTH(FILE_READ('~/.lealone.server.properties')) LEN; GREATESTReturns the largest value that is not Example: CALL GREATEST(1, 2, 3); IDENTITY
Returns the last inserted identity value for this session. This value changes whenever a new sequence number was generated, even within a trigger or Java function. See also Example: CALL IDENTITY(); IFNULLReturns the value of 'a' if it is not null, otherwise 'b'. Example: CALL IFNULL(NULL, ''); LEASTReturns the smallest value that is not Example: CALL LEAST(1, 2, 3); LOCK_MODE
Returns the current lock mode. See Example: CALL LOCK_MODE(); LOCK_TIMEOUT
Returns the lock timeout of the current session (in milliseconds). Example: LOCK_TIMEOUT() MEMORY_FREE
Returns the free memory in KB (where 1024 bytes is a KB). This method returns an int. The garbage is run before returning the value. Admin rights are required to execute this command. Example: MEMORY_FREE() MEMORY_USED
Returns the used memory in KB (where 1024 bytes is a KB). This method returns an int. The garbage is run before returning the value. Admin rights are required to execute this command. Example: MEMORY_USED() NEXTVAL
Returns the next value of the sequence. Used values are never re-used, even when the transaction is rolled back. If the schema name is not set, the current schema is used, and the sequence name is converted to uppercase (for compatibility). This method returns a long. Example: NEXTVAL('TEST_SEQ') NULLIFReturns Example: NULLIF(A, B) NVL2If the test value is null, then 'b' is returned. Otherwise, 'a' is returned. The data type of the returned value is the data type of 'a' if this is a text type. Example: NVL2(X, 'not null', 'null') READONLY
Returns true if the database is read-only. Example: READONLY() ROWNUM
Returns the number of the current row. This method returns a long. It is supported for Example: SELECT ROWNUM(), * FROM TEST; SCHEMA
Returns the name of the default schema for this session. Example: CALL SCHEMA() SCOPE_IDENTITY
Returns the last inserted identity value for this session for the current scope. Changes within triggers and Java functions are ignored. See also Example: CALL SCOPE_IDENTITY(); SESSION_ID
Returns the unique session id number for the current database connection. This id stays the same while the connection is open. This method returns an int. The database engine may re-use a session id after the connection is closed. Example: CALL SESSION_ID() SET
Updates a variable with the given value. The new value is returned. When used in a query, the value is updated in the order the rows are read. When used in a subquery, not all rows might be read depending on the query plan. This can be used to implement running totals / cumulative sums. Example: SELECT X, SET(@I, IFNULL(@I, 0)+X) RUNNING_TOTAL FROM SYSTEM_RANGE(1, 10) TABLE
Returns the result set. Example: SELECT * FROM TABLE(ID INT=(1, 2), NAME VARCHAR=('Hello', 'World')) TRANSACTION_ID
Returns the current transaction id for this session. This method returns Example: CALL TRANSACTION_ID() TRUNCATE_VALUE
Truncate a value to the required precision. The precision of the returned value may be a bit larger than requested, because fixed precision values are not truncated (unlike the numeric Example: CALL TRUNCATE_VALUE(X, 10, TRUE); USER
Returns the name of the current user of this session. Example: CURRENT_USER() LEALONE_VERSION
Returns the lealone version as a String. Example: LEALONE_VERSION() CURRENT_DATE
Returns the current date. This method always returns the same value within a transaction. Example: CURRENT_DATE() CURRENT_TIME
Returns the current time. This method always returns the same value within a transaction. Example: CURRENT_TIME() CURRENT_TIMESTAMPReturns the current timestamp. The precision parameter for nanoseconds precision is optional. This method always returns the same value within a transaction. Example: CURRENT_TIMESTAMP() DATEADD
Adds units to a timestamp. The string indicates the unit. Use negative values to subtract units. The same units as in the Example: DATEADD('MONTH', 1, DATE '2001-01-31') DATEDIFF
Returns the the number of crossed unit boundaries between two timestamps. This method returns a long. The string indicates the unit. The same units as in the Example: DATEDIFF('YEAR', T1.CREATED, T2.CREATED) DAYNAME
Returns the name of the day (in English). Example: DAYNAME(CREATED) DAY_OF_MONTH
Returns the day of the month (1-31). Example: DAY_OF_MONTH(CREATED) DAY_OF_WEEK
Returns the day of the week (1 means Sunday). Example: DAY_OF_WEEK(CREATED) DAY_OF_YEAR
Returns the day of the year (1-366). Example: DAY_OF_YEAR(CREATED) EXTRACT
Returns a specific value from a timestamps. This method returns an int. Example: EXTRACT(SECOND FROM CURRENT_TIMESTAMP) FORMATDATETIMEFormats a date, time or timestamp as a string. The most important format characters are: y year, M month, d day, H hour, m minute, s second. For details of the format, see Example: CALL FORMATDATETIME(TIMESTAMP '2001-02-03 04:05:06', HOUR
Returns the hour (0-23) from a timestamp. Example: HOUR(CREATED) MINUTE
Returns the minute (0-59) from a timestamp. Example: MINUTE(CREATED) MONTH
Returns the month (1-12) from a timestamp. Example: MONTH(CREATED) MONTHNAME
Returns the name of the month (in English). Example: MONTHNAME(CREATED) PARSEDATETIMEParses a string and returns a timestamp. The most important format characters are: y year, M month, d day, H hour, m minute, s second. For details of the format, see Example: CALL PARSEDATETIME('Sat, 3 Feb 2001 03:05:06 GMT', QUARTER
Returns the quarter (1-4) from a timestamp. Example: QUARTER(CREATED) SECOND
Returns the second (0-59) from a timestamp. Example: SECOND(CREATED) WEEK
Returns the week (1-53) from a timestamp. This method uses the current system locale. Example: WEEK(CREATED) YEAR
Returns the year from a timestamp. Example: YEAR(CREATED) |