Standard functions

Read(443) Label: standard functions,

DQL query syntax supports the following functions:

String functions

Standard functions

Description

LOWER(str)

Convert into lower case.

UPPER(str)

Convert into upper case.

ISDIGIT(str)

Judge whether parameter str consists entirely of digits.

ISALPHA(str)

Judge whether parameter str consists entirely of letters.

LTRIM(str)

Delete whitespaces on the leftmost side.

RTRIM(str)

Delete whitespaces on the rightmost side.

TRIM(str)

Delete whitespaces on both sides.

SUBSTR(str,start[,len])

Starting from the startth character in string str, get a substring whose length is specified by parameter len; When len is absent, get the substring from the specified character through to end..

SPLIT(s,d,n)

Use separator d to split string s and return the nth substring; n starts from 1.

LEN(str)

Return the length of a string.

INDEXOF(sub,str[,start])

Starting from the left startth character in string sub, search for substring str and return its position of a substring. Default value of n is 1; case-sensitive..

IPOS(str1,str2[,n])

In string str1, search for substring str2 starting from the nth character from the left and return the position of str2. Default value of n is 1; the function is case-insensitive.

GETSUBS(str1,str2[,n])

In string str1, search for the nth substring str2 starting from the left and return the substring after str2. Default value of n is 1.

IGETSUBS (str1,str2[,n])

In string str1, search for the nth substring str2 starting from the left and return the substring after str2. Default value of n is 1; the function is case-insensitive.

LEFT(str,len)

Return the substring in the left of a specified string.

RIGHT(str,len)

Return the substring in the right of a specified string.

CONCAT(str1,str2)

Concatenate two strings.

CONCAT(str1,str2,str3…)

Concatenate three or more strings.

CONCAT_WS(d,str1,str2,…)

Concatenate multiple strings with delimiter d.

REPLACE(str,sub,rplc)

Replace a substring by another string.

Datetime functions

Standard functions

Description

YEAR(d)

Return the year.

MONTH(d)

Return the month.

DAY(d)

Return the day.

HOUR(d)

Return the hour.

MINUTE(d)

Return the minute.

SECOND(d)

Return the second.

QUARTER(d)

Return the quarter.

TODAY()

Return the current date.

NOW()

Return the current time.

ADDYEARS(d, n)

Add years.

ADDMONTHS(d, n)

Add months.

ADDDAYS(d, n)

Add days.

ADDHOURS(d, n)

Add hours.

ADDMINUTES(d, n)

Add minutes.

ADDSECONDS(d, n)

Add seconds.

DAYOFYEAR(d)

Return the day of year.

WEEKOFYEAR(d)

Return the calendar week for the date in the current year.

YEARSDIFF(d1,d2)

Calculate the number of years between two dates.

MONTHSDIFF(d1,d2)

Calculate the number of months between two dates.

DAYSDIFF(d1,d2)

Calculate the number of days between two dates.

HOURSDIFF(d1,d2)

Calculate the number of hours between two dates.

MINUTESDIFF(d1,d2)

Calculate the number of minutes between two dates.

SECONDSDIFF(d1,d2)

Calculate the number of seconds between two dates.

TRUNCHOUR(d)

Truncate to the hour.

TRUNCMINUTE(d)

Truncate to the minute.

TRUNCSECOND(d)

Truncate to the second.

MONTHSTART(d)

Get the first day of the current month.

MONTHEND(d)

Get the last day of the current month.

WEEKSTART(d)

Get the first day of the current week, where Monday is the start day.

WEEKEND(d)

Get the last day of the current week, where Monday is the start day.

QUARTERSTART(d)

Get the first day of the current quarter.

QUARTEREND(d)

Get the last day of the current quarter.

YEARSTART(d)

Get the first day of the current year.

YEAREND(d)

Get the last day of the current year.

MONTHDAYS(d)

Calculate the number of days in the current month.

QUARTERDAYS(d)

Calculate the number of days in the current quarter.

YEARDAYS(d)

Calculate the number of days in the current year.

ITX(s)

Generate a time interval constant according to the time component; s represents second.

ITX (null,d)

Generate a time interval constant according to the time component; d represents day; value of the first parameter is always null.

ITX(null,d,m)

Generate a time interval constant according to the time component; d represents day and m represents month; value of the first parameter is always null.

ADDX(t,k)

Perform addition operation between two dates.

k can be a time interval constant returned by ITX().

When t is a date/datetime value and k is a numeric value, k represents the day.

Perform the addition operation when both t or k are of any of the other data type.

SUBX(t1,t2)

Perform subtraction operation between two dates.

When t1 is a date/datetime value and t2 is a numeric value, t2 represents the day.

Perform the subtraction operation when both t1 or t2 is of any of the other data type.

CMPX(it1,it2)

Perform comparison between two dates.

it1 and it2 can be a date, time, datetime, time interval constant, or numerical value.

Numeric functions

Standard functions

Description

ABS(x)

Return absolute value.

ACOS(x)

Return arc cosine.

ASIN(x)

Return arc sine.

ATAN(x)

Return arc tangent.

ATAN2(x,y)

Return arc tangent.

CEIL(x)

Return the smallest integer that is not less than x.

CEIL(x,n) 

Round x up according to precision n. Default value of n is 0. Keep n decimal places if n>0; round up to the nearest whole number if n=0; round up to the nearest tens, hundreds, thousands, or other integer place values if n<0.

COS(x)

Return cosine value.

EXP(x)

Return the base of e to the power of x.

FLOOR(x)

Return the biggest integer that not greater than x.

FLOOR(x,n)

Round x down according to precision n. Default value of n is 0. Keep n decimal places if n>0; round down to the nearest whole number if n=0; round down to the nearest tens, hundreds, thousands, or other integer place values if n<0.

LN(x)

Return the natural logarithm.

LOG10(x)

Return the logarithm with base 10.

MOD(x,m)

Return the remainder of x divided by m.

POWER(x,y)

Return the value of x raised to the power of y.

ROUND(x,n)

Return x rounded to n digits from the decimal point.

SIGN(x)

Return the sign for x.

SIN(x)

Return the sine value.

SQRT(x)

Return the square root of x.

TAN(x)

Return the tangent value.

TRUNC(x,n)

Return x truncated to n decimal places.

RAND(seed)

Return a random integer between 0 and seed.

RAND()

Return a random floating-point number between 0 and 1.

PI() 

Calculate the value of pi.

Conversion functions

Standard functions

Description

ASCII(str)

Return numeric value of left-most character.

CHR(n)

Return the character for integer n.

INT(x)

Return an integer for string or number x.

DECIMAL(x,len,scale)

Return the numeric value for a string or number.

TIMESTAMP(d[,str])

Convert d to the datetime type according to the format string str, which by default is yyyy-MM-dd HH:mm:ss.

NUMTOCHAR(d)

Return a string for number d.

DATETOCHAR(date)

Convert date to a string whose format is yyyy-MM-dd HH:mm:ss.

DATETIME(date,time)

Concatenate the date and time into a datetime value.

DATE(sd[,fd])

Convert sd to the date type according to format string fd, which is by default yyyy-MM-dd.

DATE(y,m,d)

Convert integers y, m, d to date type; return null if the conversion fails。

TIME(sdt[,fd])

Convert sdt to the time type according to format string fd, which is by default HH:mm:ss.

TIME(h,m,s)

Convert integers h, m, s to time type.

CAST(x,y)

Convert x to data type y.

CHN(n)  

Convert number n to the corresponding Chinese numeral representation.

STRING(exp[,format][,loc])

Convert exp to the string type. f is the format string according to which the result is formatted, and loc specifies a language; both can be omitted.

 

Aggregate functions

Standard functions

Description

GCONCAT([distinct ]x[,d])

Concatenate values in column x within each group into a single string, using separator d.

distinct is a keyword and is optional. When placed before x, it removes duplicate values before concatenation.

d specifies the separator and is optional. If omitted, the values are concatenated directly without a separator.

 

Other functions

Standard functions

Description

NULLIF(x1,x2)

Return null if x1=x2, otherwise return x1.

COALESCE(x1,…)

Return the first non-null parameter.

NVL(x1,…)

Return the first non-null, non-empty string parameter.

CASE(when1,then1,…[,else])

If when=true, return the corresponding then, otherwise return else.

DECODE(x,k1,v1,k2,v2, ...., else )

Compare x with k. If a match is found, return the corresponding v value; if none of the values match, return else.