|
|
Scalar Functions
The following sections describe Mimer SQL's scalar functions.
ABS
Returns the absolute value of the given numeric expression.
Syntax
valueis a numeric or an interval value expression.Rules
- The function returns the absolute value of
value.- If the value of
valueisNULL, then the result of the function isNULL.Example
SET INT_VAL = ABS(-15); -- sets INT_VAL to 15ASCII_CHAR
Returns the character that has the given ASCII code value. The given ASCII code value should be in the range 0-255.Syntax
Syntax for the
ASCII_CHARfunction:
codeis a numeric expression representing an ASCII value.Rules
- If the value of
codeis between 0 and 255, the function returns a single character value, i.e.CHAR(1), otherwise the function returnsNULL.- If the value of
codeisNULL, then the result of the function isNULL.Example
SET CHR_VAL = ASCII_CHAR(65); -- sets CHR_VAL to 'A'ASCII_CODE
Returns the ASCII code value of the leftmost character in the given string expression, as an integer.Syntax
Syntax for the
ASCII_CODEfunction:
source-stringis a character or binary string expression.Rules
- A single
INTEGERvalue is returned, representing an ASCII code.- If the
source-stringcontains more than one character, the ASCII code of the left-most octet is returned.- If the length of
source-stringis zero, then the result of the function isNULL.- If the value of
source-stringisNULL, then the result of the function isNULL.Example
SET INT_VAL = ASCII_CODE('A'); -- sets INT_VAL to 65BIT_LENGTH
Returns the number of bits in a string.Syntax
Syntax for the
BIT_LENGTHfunction:
source-stringis a character or binary string expression.Rules
BIT_LENGTHreturns anINTEGERvalue.- If the data type of
source-stringis variable-length character or variable-length binary, then the result ofBIT_LENGTHis the same as the actual length ofsource-stringmultiplied by 8 (the number of bits in an octet.)- If the data type of
source-stringis fixed-length character or fixed-length binary, then the result ofBIT_LENGTHis the same as the fixed-length ofsource-stringmultiplied by 8.- If the data type of
source-stringis fixed-length national character (i.e.NCHAR), then the result ofBIT_LENGTHis the same as the fixed-length ofsource-stringmultiplied by 32 (the number of bits used to store a national character.)- If the data type of
source-stringis variable-length national character, then the result ofBIT_LENGTHis the same as the actual length ofsource-stringmultiplied by 32.- If the value of
source-stringisNULL, then the result of the function isNULL.Example
SET INT_VAL = BIT_LENGTH(X'4142'); -- sets INT_VAL to 16CHAR_LENGTH or CHARACTER_LENGTH
Returns the length of a string.Syntax
Syntax for the
CHAR_LENGTH(orCHARACTER_LENGTH) function:
source-stringis a character or binary string expression.Rules
CHAR_LENGTHreturns anINTEGERvalue.- If the data type of
source-stringis variable-length character or variable-length binary, then the result ofCHAR_LENGTHis the same as the actual length ofsource-string.- If the data type of
source-stringis fixed-length character or fixed-length binary, then the result ofCHAR_LENGTHis the same as the fixed-length ofsource-string.- If the value of
source-stringisNULL, then the result of the function isNULL.Example
SET INT_VAL = CHAR_LENGTH('TEST STRING'); -- sets INT_VAL to 11CEILING
Returns the smallest integer greater than or equal to a numeric expression.Syntax
Syntax for the
CEILINGfunction:
valueis a numeric value expression.Rules
- The function returns the nearest integer value that is equal or higher to
value.- If the value of
valueisNULL, then the result of the function isNULL.Example
SET :i = CEILING(3.57); -- sets :i to 4 SET :i = CEILING(-3.57); -- sets :i to -3CURRENT_DATE
Returns aDATEvalue denoting the current date (i.e. today).Syntax
Syntax for theCURRENT_DATEfunction:Rules
- The result is the current date (i.e. today) as a
DATEvalue.- All references to
CURRENT_DATEare effectively evaluated simultaneously from a single reading of the server clock. Thus the conditional expressionCURRENT_DATE = CURRENT_DATEis guaranteed to always evaluate to true.- The value of
CURRENT_DATEwill always be equal to theDATEportion ofLOCALTIMESTAMP.Example
UPDATE sometable SET usercnt = 13, updated = CURRENT_DATE;CURRENT_PROGRAM
Returns the name of an entered program.Syntax
Syntax for the
CURRENT_PROGRAMfunction:Rules
- The function returns the value of the most recently entered program as character varying value with a maximum length of 128.
- If no program has been entered the result of the function is
NULL.Example
The following example returns the
PROGRAMident if entered, otherwise the session ident:SET CHR_STR = COALESCE(CURRENT_PROGRAM(), SESSION_USER);CURRENT_USER
Returns the name of the currently connectedUSERorOS_USERident or thePROGRAMident that is currently entered.When used in a routine or trigger, it returns the name of the creator of the schema to which the routine or trigger belongs.Syntax
Syntax for the
CURRENT_USERfunction:Rules
- When used in a routine or trigger, the result is the name of the creator of the schema to which the routine or trigger belongs, otherwise the value is the name of the connected ident or the program that was entered.
- The data type of the returned value is character varying with a maximum length of 128.
Example
CREATE DOMAIN NAME AS CHAR(128) DEFAULT CURRENT_USER;CURRENT_VALUE
Returns the current value of a sequence.Syntax
Syntax for the
CURRENT_VALUEfunction:Rules
- The result is the current value of the sequence specified in
sequence-name. This is the value that was returned when theNEXT_VALUEfunction was used for this sequence in this session.- This function cannot be used until the initial value has been established for the sequence by using
NEXT_VALUE(i.e. using it immediately after the sequence has been created will raise an error).- The function can be used where a value-expression would normally be used. It can also be used after the
DEFAULTclause in theCREATE DOMAIN,CREATE TABLEandALTER TABLEstatements.USAGEprivilege must be held on the sequence in order to use it.Example
CREATE DOMAIN CHARGE_PERIOD_VALUE AS INTEGER DEFAULT CURRENT_VALUE OF CHARGE_PERIOD_NO_SEQUENCE;DACOS
Returns the arccosine for a numeric expression.
Syntax
Syntax for the
DACOSfunction:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The functions returns the arccosine for the value expressed as radians. The data type for the result is double precision. Valid input values are in the range -1 to 1.
- If the value of
valueis NULL, then the result of the function is NULL.DASIN
Returns the arcsine for a numeric expression.
Syntax
Syntax for the
DASINfunction:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The functions returns the arcsine for the value expressed as radians. The data type for the result is double precision. Valid input values are in the range -1 to 1.
- If the value of
valueis NULL, then the result of the function is NULL.DATAN
Returns the arctangent for a numeric expression.
Syntax
Syntax for the
DATANfunction:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The functions returns the arctangent for the value expressed as radians. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.DATAN2
Returns the arctangent for the tangent between 2 numeric expressions.
Syntax
Syntax for the
DATAN2function:
value-1 and value-2are numeric value expressions. The function handles values that are within the range of a double precision expression.The
DATAN2function calculates the arctangent of the two parametersvalue-1andvalue-2. It is similar to calculating the arctangent ofvalue-2/value-1, except that the signs of both arguments are used to determine the quadrant of the result. Effectively, this means thatDATAN2(value-1, value-2)finds the counterclockwise angle in radians between the x-axis and the vector <value-2,value-1> in 2-dimensional Euclidean space.Rules
- Returns the angle, in radians, whose tangent is between the two given value expressions. The data type for the result is double precision.
- If the value of
value-1orvalue-2is NULL, then the result of the function is NULL.DAYOFWEEK
Returns the day of the week for the given date expression, expressed as an integer value in the range 1-7, where 1 represents Monday.Syntax
Syntax for the
DAYOFWEEKfunction:
date-or-timestampis a date or timestamp value expression.Rules
- The result is an integer value, 1 through 7, where
1= Monday,2= Tuesday and so on.- If the value of
date-or-timestampisNULL, then the result of the function isNULL.DAYOFYEAR
Returns the day of the year for the given date expression, expressed as an integer in the range 1-366.Syntax
Syntax for the
DAYOFYEARfunction:
date-or-timestampis a date or timestamp value expression.Rules
- The result is an integer value, 1 through 366, where
1= January 1st.- The value for a day after February 28th depends on whether the year is a leap year or not.
- If the value of
date-or-timestampisNULL, then the result of the function isNULL.Example
SET INT_VAL = DAYOFYEAR(CURRENT_DATE); -- sets INT_VAL to the -- day number of the current year SET INT_VAL = DAYOFYEAR(DATE'2007-11-10'); -- sets INT_VAL to 314 SET INT_VAL = DAYOFYEAR(DATE'2008-11-10'); -- sets INT_VAL to 315DCOS
Returns the cosine for a numeric expression.
Syntax
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The functions returns the cosine for the values expressed as radians. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.DCOT
Returns the cotangent for a numeric expression.
Syntax
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns the cotangent for the value, expressed as radians. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.DDEGREES
Returns an angle expressed in radians as degrees.
Syntax
Syntax for the
DDEGREESfunction:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function converts a numeric expression in radians to the corresponding values expressed in degrees. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.DEXP
Returns the exponential value for a numeric expression.
Syntax
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns exponential value for the value expression. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.DLOG
Returns the natural logarithm for a numeric expression.
Syntax
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns the natural logarithm for the value expression. The data type for the result is double precision. Valid input values are > 0.
- If the value of
valueis NULL, then the result of the function is NULL.DLOG10
Returns the base-10 logarithm for a numeric expression.
Syntax
Syntax for the
DLOG10function:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns the base-10 logarithm for the value expression. The data type for the result is double precision. Valid input values are > 0.
- If the value of
valueis NULL, then the result of the function is NULL.DPOWER
Returns the specified numeric expression, raised to the power of the given value.
Syntax
Syntax for the
DPOWERfunction:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns the value of the first argument raised to the power of the second argument. The data type for the result is double precision.
- If the value of
valueorinteger-valueis NULL, then the result of the function is NULL.DRADIANS
Returns an angle expressed in degrees as radians.
Syntax
Syntax for the
DRADIANSfunction:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function converts a value expressed in degrees to the corresponding value expressed as radians. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.DSIN
Returns the sine for a numeric expression.
Syntax
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns the sine for the value expressed as radians. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.DSQRT
Returns the square root of a numeric expression.
Syntax
Syntax for the
DSQRTfunction:
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns the square root of the value. The data type for the result is double precision. Valid input values are greater than or equal to 0.
- If the value of
valueis NULL, then the result of the function is NULL.DTAN
Returns the tangent for a numeric expression.
Syntax
valueis a numeric value expression. The function handles values that are within the range of a double precision expression.Rules
- The function returns the tangent for the value expressed as radians. The data type for the result is double precision.
- If the value of
valueis NULL, then the result of the function is NULL.EXTRACT
Extracts a single field from aDATETIMEorINTERVALvalue.Syntax
Syntax for the
EXTRACTfunction:Rules
field-nameis one of:YEAR,MONTH,DAY,HOUR,MINUTEorSECOND.valuemust be of typeDATETIMEorINTERVALand it must contain the field specified byfield-name, otherwise an error is raised.- The data type of the result is exact numeric with a precision equal to the leading precision of
valueand a scale of 0.The exception is when
field-nameisSECOND, in which case the precision is equal to the sum of the leading precision and the seconds precision ofvalue, with a scale equal to the seconds precision.- When
valueis a negativeINTERVAL, the result is a negative value. In all other cases the result is a positive value.- If the value of
valueisNULL, then the result of the function isNULL.Example
SELECT CASE EXTRACT (MONTH FROM ARRIVE) WHEN 1 THEN 'JANUARY'FLOOR
Returns the largest integer less than or equal to a numeric expression.Syntax
Syntax for the
FLOORfunction:
valueis a numeric value expression.Rules
- The function returns the nearest integer value that is equal or lower to
value.- If the value of
valueisNULL, then the result of the function isNULL.Example
SET INT_VAL = FLOOR(13.13); -- sets INT_VAL to 13 SET INT_VAL = FLOOR(-13.13); -- sets INT_VAL to -14IRAND
Returns a random integer number.Syntax
Syntax for the
IRANDfunction:
seedis an integer value expressionRules
- The result is a random integer value, in the range 0 to 2 147 483 647.
- If a
seedis given, this value is used to calculate the random value. If noseedis given, the value is calculated from the previous value. It is thus possible to generate the same random sequence by using the sameseed.Example
SET INT_VAL = MOD(IRAND(), 5); -- sets INT_VAL to a random -- value between 0 and 4LOCALTIME
Returns aTIMEvalue denoting the current time (i.e. now).Syntax
Syntax for theLOCALTIMEfunction:
seconds-precisionis an unsigned integer value denoting the seconds precision for the returnedTIMEvalue.Rules
- The result is the current time (i.e. now) as a
TIMEvalue.- The value of
seconds-precisionmust be between 0 and 9.- If
seconds-precisionis not specified, the default value of 0 is assumed.- All references to
LOCALTIMEare effectively evaluated simultaneously from a single reading of the server clock. Thus the conditional expressionLOCALTIME = LOCALTIMEis guaranteed to always evaluate to true.- The value of
LOCALTIMEwill always be equal to theTIMEportion ofLOCALTIMESTAMP.Example
UPDATE EVENTS SET ADJUSTED = LOCALTIME -- sets ADJUSTED to current time WHERE ID = 81; -- (e.g. 15:45:02)LOCALTIMESTAMP
Returns aTIMESTAMPdenoting the current date and time.Syntax
Syntax for the
LOCALTIMESTAMPfunction:
seconds-precisionis an unsigned integer value denoting the seconds precision for the returnedTIMESTAMPvalue.Rules
- The result is the current date and time as a
TIMESTAMPvalue.- The value of
seconds-precisionmust be between 0 and 9.- If
seconds-precisionis not specified, the default value of 6 is assumed.- All references to
LOCALTIMESTAMPare effectively evaluated simultaneously from a single reading of the server clock. Thus the conditional expressionLOCALTIMESTAMP = LOCALTIMESTAMPis guaranteed to always evaluate to true.- The value of
LOCALTIMESTAMPwill always be equal to the combined value ofCURRENT_DATEandLOCALTIME.Example
CREATE TABLE EVENTS(ID INTEGER PRIMARY KEY, TS TIMESTAMP DEFAULT LOCALTIMESTAMP); INSERT INTO EVENTS(ID) VALUES (1); -- default value for TS inserted -- (e.g. 2003-01-18 13:25:07.230000) UPDATE EVENTS SET TS = LOCALTIMESTAMP WHERE ID <= 10;LOWER
Converts all uppercase letters in a character string to lowercase.Syntax
Syntax for the
LOWERfunction:
source-stringis a character string expression.Rules
- The data type of the result is the same as the data type of
source-string.source-stringis assumed to be in character or national character (i.e. Unicode) format.- If the value of
source-stringisNULL, then the result of the function isNULL.Note: The length of the result may be longer or shorter than the input value. This means that using LOWER (or UPPER) on a column may cause data truncation.
Example
SELECT CHAR_LENGTH(TRIM(DESCRIPTION)), LOWER(TRIM(DESCRIPTION)) FROM CHARGES;MOD
Returns the remainder (modulus) of a specified integer expression divided by a second specified integer expression.Syntax
integer-expression-1andinteger-expression-2are integer value expressions.Rules
- The result is the remainder of
integer-expression-1divided byinteger-expression-2.- If the value of
integer-expression-2is zero, a divide-by-zero error will be raised.- The sign of the result is the same as the sign of
integer-expression-1.- If the value of either operand is
NULL, then the result of the function isNULL.Example
SET INT_VAL = MOD(IRAND(), 5); -- sets INT_VAL to a random -- value between 0 and 4NEXT_VALUE
Returns the next value in the series of values defined by a sequence, provided that the last value in that series has not already been reached.Syntax
Syntax for the
NEXT_VALUEfunction:Rules
- The result will be the next value in the series of the values defined by the sequence specified in
sequence-name(this value will then become the current value for the sequence).- If the sequence is unique and the current value of the sequence specified in
sequence-nameis already equal to the last value in the series of the values defined by it an error will be raised and the current value of the sequence will remain unchanged.- If the sequence is non-unique, the function will always succeed. If the current value of the sequence specified in
sequence-nameis equal to the last value in the series of values generated by the sequence, the initial value of the sequence will be returned.- The function can be used where a value-expression would normally be used. It can also be used after the
DEFAULTclause in theCREATE DOMAIN,CREATE TABLEandALTER TABLEstatements.- This function is used to establish the initial value of the sequence after it has been created using the
CREATE SEQUENCEstatement.USAGEprivilege must be held on the sequence in order to use it.Example
SET Z = NEXT_VALUE OF Z_SEQUENCE;Note: If the NEXT_VALUE function is used in a select clause the sequence will be incremented for each row returned by the query.
OCTET_LENGTH
Returns the octet (byte) length of a string. For single-octet character sets this is the same asCHARACTER_LENGTH.Syntax
Syntax for the
OCTET_LENGTHfunction:
source-stringis a character or binary string expression.Rules
OCTET_LENGTHreturns anINTEGERvalue.- If the data type of
source-stringis variable-length character or variable length binary, then the result ofOCTET_LENGTHis the same as the actual length ofsource-stringin octets.- If the data type of
source-stringis fixed-length character or fixed-length binary, then the result ofOCTET_LENGTHis the same as the fixed-length ofsource-string.- If the data type of
source-stringis variable-length national character, then the result ofOCTET_LENGTHis the same as the actual length ofsource-stringin octets, i.e. 4 times the actual number of characters.- If the data type of
source-stringis fixed-length national character, then the result ofOCTET_LENGTHis the same as 4 times the fixed-length ofsource-string.- If the value of
source-stringisNULL, then the result of the function isNULL.Example
SET INT_VAL = OCTET_LENGTH(X'4142'); -- sets INT_VAL to 2 SET INT_VAL = OCTET_LENGTH('ABC'); -- sets INT_VAL to 3 SET INT_VAL = OCTET_LENGTH(n'ABC'); -- sets INT_VAL to 12PASTE
Returns a character string where a specified number of characters, beginning at a given position, have been deleted from a character string and replaced with a given string expression.Syntax
Syntax for the
PASTEfunction:
string-1andstring-2are character or binary string expressions.
string-1andstring-2must be of the same type, i.e. either both character or both binary.
start-positionandstring-lengthare integer value expressions.Rules
- The
string-lengthnumber of characters instring-1, starting from positionstart-positionare deleted fromstring-1. Thenstring-2is inserted intostring-1, at the `point of deletion'. The resulting character or binary string is returned.- If the value of
string-lengthis positive, thestring-lengthnumber of characters to the right ofstart-positionare deleted. If the value ofstring-lengthis negative, thestring-lengthnumber of characters to the left ofstart-positionare deleted.The point-of-deletion is where the cursor would be if you had just used a text editor to select the characters, as described, and performed an edit-cut operation.
- A value for
start-positionof less than 1 (zero or negative) specifies a position to the left of the beginning ofstring-1.It is possible that the specified deletion may not actually affect any of the characters of
string-1, in which case the paste operation produces the effect of a prepend.- If the value of any operand is
NULL, then the result of the function isNULL.string-2must not contain Unicode characters outside the Latin1 repertoire ifstring-1is of character type.Example
SET CHR_STR = PASTE('TEST STRING', 6, 3, 'P'); -- sets CHR_STR to 'TEST PING'POSITION
Returns the starting position of the first occurrence of a specified string expression in a given character string, starting from the left of the character string.Syntax
Syntax for thePOSITIONfunction:
sub-stringandsource-stringare character or binary string expressions.
sub-stringandsource-stringmust be of the same type, i.e. either both character or both binary.Rules
- The position of the first occurrence of
sub-stringinsource-stringis returned, starting from position 1 insource-string(the left-most position).- If
sub-stringdoes not occur insource-string, the functions returns zero.- If the length of
source-stringis zero, the function returns zero.- If the length of
sub-stringis zero, the function returns 1.- If the value of either operand is
NULL, then the result of the function isNULL.Example
SET INT_VAL = POSITION('STR' IN 'TEST STRING'); -- sets INT_VAL to 6REPEAT
Returns a character string composed of a specified string expression repeated a given number of times.Syntax
Syntax for the
REPEATfunction:
sub-stringis a character or binary string expression.
repeat-countis an integer expression.Rules
- The result is a character or binary string consisting of
sub-stringrepeatedrepeat-counttimes.- If the value of
repeat-countis zero, then the result of the function is a character or binary string of length zero.- If the value of
repeat-countis less than zero, then the result of the function isNULL.- If the value of either operand is
NULL, then the result of the function isNULL.Example
SET CHR_STR = REPEAT('ABC', 3); -- sets CHR_STR to 'ABCABCABC'REPLACE
Replaces all occurrences of a given string expression with another string expression in a character string.Syntax
Syntax for the
REPLACEfunction:
source-string,string-1andstring-2are character or binary string expressions.
source-string,string-1andstring-2must be of equal type, i.e. either all are character or all are binary.Rules
- All occurrences of
string-1found insource-stringare replaced withstring-2, the resulting character or binary string is returned.- If the value of any of the operands is
NULL, then the result of the function isNULL.string-2must not contain Unicode characters outside the Latin1 repertoire ifsource-stringis of character type.Example
SET CHR_STR = REPLACE('TEST STRING', 'ST', 'NOR'); -- sets CHR_STR to -- 'TENOR NORRING'ROUND
Returns the given numeric expression rounded to the number of places to the right of the decimal point specified by a given integer expression.If the integer expression is negative, the numeric expression is rounded to a number of places to the left of the decimal point specified by the absolute value of the integer expression.Syntax
Syntax for the
ROUNDfunction:
numeric-valueis an integer or a float value expression.
integer-valueis an integer value expression.Rules
- If
integer-valueis positive, the value describes the number of digits permitted innumeric-value, after rounding, to the right of the decimal point, if it is negative it describes the number of digits allowed to the left of the decimal point.- The value returned depends on the data type of
numeric-value.- If the value of either operand is
NULL, then the result of the function isNULL.Examples
SET NUM_VAL = ROUND(762.847, 2); -- sets NUM_VAL to 762.850 SET NUM_VAL = ROUND(762.847, 1); -- sets NUM_VAL to 762.800 SET NUM_VAL = ROUND(762.847, 0); -- sets NUM_VAL to 763.000 SET NUM_VAL = ROUND(762.847, -1); -- sets NUM_VAL to 760.000 SET NUM_VAL = ROUND(762.847, -2); -- sets NUM_VAL to 800.000SESSION_USER
Returns the name of the currently connected ident.Syntax
Syntax for the
SESSION_USERfunction:Rules
- The result is the name of the current ident (i.e. the ident who established the current database connection).
- The data type of the returned value is character varying with a maximum length of 128.
Example
The following example returns the Program ident if entered, otherwise the session ident:
SET CHR_STR = COALESCE(CURRENT_PROGRAM(), SESSION_USER);SIGN
Returns an indicator of the sign of the given numeric expression.If the numeric expression is less than zero, -1 is returned. If the numeric expression is equal to zero, 0 is returned. If the numeric expression is greater than zero, 1 is returned.Syntax
numeric-valueis an integer or a float value expression.Rules
- The function returns an indicator of the sign of
numeric-value. Ifnumeric-valueis less than zero, -1 is returned. Ifnumeric-valueequals zero, 0 is returned. Ifnumeric-valueis greater than zero, 1 is returned.- If the value of
numeric-valueisNULL, then the result of the function isNULL.Examples
SET INT_VAL = SIGN(-12); -- sets INT_VAL to -1 SET INT_VAL = SIGN(0); -- sets INT_VAL to 0 SET INT_VAL = SIGN(12); -- sets INT_VAL to 1SOUNDEX
Returns a character string value containing six digits that represent an encoding of the sound of the given string expression.Syntax
Syntax for theSOUNDEXfunction:
source-stringis a character string expression.Rules
- The function returns a character string value containing six digits that represent an encoding of the sound of
source-string.- If
source-stringcontains two or more words, they are effectively concatenated into a single word by ignoring the separating space characters.- If the
SOUNDEXvalues for two strings compare to be equal then they sound the same.- If the value of
source-stringisNULL, then the result of the function isNULL.SUBSTRING
Extracts a substring from a given string, according to specified start position and length of the substring.Syntax
Syntax for theSUBSTRINGfunction:
source-stringis a character or binary string expression.
start-positionandstring-lengthare integer value expressions.Rules
SUBSTRINGreturns a character or binary string containingstring-lengthcharacters ofsource-string, starting at the character specified bystart-position, and in the same sequence as they appear insource-string.If any of these positions are before the start or after the end of
source-string, then no character is returned for that position. If all positions are outside the source string, an empty string is returned.- The first character in
source-stringhas position 1.- If the data type of
source-stringis variable-length character, then the result of theSUBSTRINGfunction is a variable-length character with maximum string length equal to the maximum length ofsource-string. If the data type ofsource-stringis fixed-length character, then the result of theSUBSTRINGfunction is a variable-length character with maximum string length equal to the fixed length ofsource-string.- If the data type of
source-stringis variable-length binary, then the result of theSUBSTRINGfunction is a variable-length binary with maximum string length equal to the maximum length ofsource-string. If the data type ofsource-stringis fixed-length binary, then the result of theSUBSTRINGfunction is a variable-length binary with maximum string length equal to the fixed length ofsource-string.- If
string-lengthis negative, or ifstart-positionis greater than the number of characters insource-string, the function fails and an error is returned.- If
string-lengthis omitted then it is assumed to be:CHAR_LENGTH(source-string) + 1 - start-positioni.e. the remainder of
source-string, starting atstart-position, is returned.
- If the value of any operand is
NULL, then the result of the function isNULL.- Character strings returned from a
SUBSTRINGfunction, inherit the collation from the source string.Example
SET CHR_STR = SUBSTRING('Whatever' FROM 3 FOR 3); -- sets CHR_STR to 'ate'TAIL
Returns the specified number of rightmost characters in a given character string.Syntax
source-stringis a character or binary string expression.
countis an integer value expression.Rules
- The right-most
countcharacters ofsource-stringare returned.- If
countis zero, an empty string is returned.- If
countis less than zero, then the result of the function isNULL.- If the value of either operand is
NULL, then the result of the function isNULL.Example
SET CHR_STR = TAIL('TEST STRING', 3); -- sets CHR_STR to 'ING'TRIM
Removes leading and/or trailing instances of a specified character from a string.Syntax
trim-characteris a character or binary string expression of length 1.
source-stringis a character or binary string expression.
source-stringandtrim-charactermust be of equal type, i.e. either must both be character or both binary.Note: LEADING, TRAILING or BOTH is referred to as the trim-specification below.
Rules
- If the data type of
source-stringis variable-length character, then the result of theTRIMfunction is a variable-length character with maximum string length equal to the maximum length ofsource-string. If the data type ofsource-stringis fixed-length character, then the result of theTRIMfunction is a variable-length character with maximum string length equal to the length ofsource-string.- If the data type of
source-stringis variable-length binary, then the result of theTRIMfunction is a variable-length binary with maximum string length equal to the maximum length ofsource-string. If the data type ofsource-stringis fixed-length binary, then the result of theTRIMfunction is a variable-length binary with maximum string length equal to the length ofsource-string.- If
trim-specificationis not specified,BOTHis implicit.- If
trim-characteris not specified, '' (space) is implicit.- If the length of
trim-characteris not 1, an error is returned.- If the value of either operand is
NULL, then the result of the function isNULL.- Character strings returned from a
TRIMfunction, inherit the collation from the source string.Examples
SET CHR_STR = TRIM('T' FROM 'TEST'); -- sets CHR_STR to 'ES' SET CHR_STR = TRIM(LEADING 'T' FROM 'TEST'); -- sets CHR_STR to 'EST' SET CHR_STR = TRIM(TRAILING 'T' FROM 'TEST'); -- sets CHR_STR to 'TES'TRUNCATE
Returns the given numeric expression truncated to a number of places to the right of the decimal point specified by a given integer expression.If the integer expression is negative, the numeric expression is truncated to a number of places to the left of the decimal point specified by the absolute value of the integer expression.Syntax
Syntax for the
TRUNCATEfunction:
numeric-valueis an integer or a float value expression.
integer-valueis an integer value expression.Rules
- If
integer-valueis positive, the value describes the number of digits permitted innumeric-value, after truncation, to the right of the decimal point.If it is negative, it describes the number of digits allowed to the left of the decimal point.
- The value returned depends on the data type of
numeric-value.- If the value of either operand is
NULL, then the result of the function isNULL.Examples
SET NUM_VAL = TRUNCATE(25.89, 1); -- sets NUM_VAL to 25.80 SET NUM_VAL = TRUNCATE(25.89, -1); -- sets NUM_VAL to 20.00UNICODE_CHAR
Returns the character that has the given Unicode scalar value.Syntax
Syntax for the
UNICODE_CHARfunction:
codeis a numeric expression representing a Unicode scalar value.Rules
- If the value of
coderepresents a valid Unicode character, the function returns a single national character value, i.e.NCHAR(1), otherwise an error is raised.- If the value of
codeisNULL, then the result of the function isNULL.Example
SET NCHR_VAL = UNICODE_CHAR(65); -- sets NCHR_VAL to 'A'UNICODE_CODE
Returns the Unicode scalar value of the leftmost character in the given string expression, as an integer.Syntax
Syntax for the
UNICODE_CODEfunction:
source-stringis a character or binary string expression.Rules
- A single
INTEGERvalue is returned, representing a Unicode scalar value.- If the
source-stringcontains more than one character, the Unicode scalar value of the left-most character is returned.- If the length of
source-stringis zero, then the result of the function isNULL.- If the value of
source-stringisNULL, then the result of the function isNULL.Example
SET INT_VAL = UNICODE_CODE(n'A'); -- sets INT_VAL to 65UPPER
Converts all lowercase letters in a character string to uppercase.Syntax
Syntax for the
UPPERfunction:
source-stringis a character string expression.Rules
- The data type of the result is the same as the data type of
source-string.source-stringis assumed to be in character or national character (i.e. Unicode) format.- If the value of
source-stringisNULL, then the result of the function isNULL.Note: The length of a result may be longer or shorter than the input value. This means that using UPPER on a column may cause data truncation.
USER
WEEK
Returns the week of the year for the given date expression, expressed as an integer value in the range 1-53.Syntax
Syntax for theWEEKfunction:
date-or-timestampis a date or timestamp value expression.Rules
- The result is an integer value, 1 through 53, representing the week number in the year, calculated in accordance with the ISO 8601 standard. (The year's first week with 4 or more days is week 1.)
- If the value of
date-or-timestampisNULL, then the result of the function isNULL.Example
SET INT_VAL = WEEK(CURRENT_DATE); -- sets INT_VAL to the week number -- of the current year
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|