未验证 提交 b0088cbc 编写于 作者: Y Yuting 提交者: GitHub

docs(Functions): Update documentation for supported functions (#258)

#257
Co-authored-by: Nmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
上级 816c25aa
......@@ -3,4 +3,26 @@ id: advanced-functions
sidebar_position: 6.44
---
# Advanced Functions
\ No newline at end of file
# Advanced Functions
This topic describes the advanced functions supported by StoneDB.
| **Function** | **Description** | **Example** |
| --- | --- | :-- |
| BIN(x) | Returns the binary string equivalent to _x_. | SELECT BIN(28);<br /><br />->11100 |
| BINARY(s) | Converts string _s_ to a binary string. | SELECT BINARY('STONEDB');<br /><br />-> STONEDB |
| CASE expression<br />WHEN condition1 THEN result1<br />WHEN condition2 THEN result2<br />...<br />WHEN conditionN THEN resultN<br />ELSE result<br />END | **CASE** specifies the start of the function and **END** specifies the end of the function. <br />If _condition1_ is met, _result1_ is returned. If _condition2_ is met, _result2_ is returned. If all conditions are not met, _result_ is returned. <br />This function stops checking subsequent conditions immediately after a condition is met and returns the corresponding result. | SELECT CASE <br />WHEN 1>0<br />THEN '1 > 0'<br />WHEN 2>0<br />THEN '2 > 0'<br />ELSE '3 > 0'<br />END;<br /><br />->1>0 |
| CAST(x AS type) | Converts the data type of _x_. | SELECT CAST('2022-06-11' AS DATE);<br /><br />->2022-06-11 |
| COALESCE(expr1, expr2, ...., expr_n) | Returns the first non-null value in the specified list. | SELECT COALESCE(NULL, NULL,'CHINA', NULL, NULL,'STONEDB');<br /><br />->CHINA |
| CONNECTION_ID() | Returns the ID of the current connection. | SELECT CONNECTION_ID();<br /><br />->5 |
| CONV(x,f1,f2) | Converts _x_ from base _f1_ to_ f2_. | SELECT CONV(28,10,16);<br /><br />->1C |
| CONVERT(s USING cs) | Changes the character set of string _s_ to character set _cs_. | SELECT CHARSET('ABC');<br /><br />->utf8 <br /><br />SELECT CHARSET(CONVERT('ABC' USING gbk));<br /><br />->gbk |
| CURRENT_USER() | Returns the current user. | SELECT CURRENT_USER();<br /><br />->root@localhost |
| DATABASE() | Returns the name of the current database. | SELECT DATABASE(); <br /><br />->test |
| IF(expr,v1,v2) | Returns value _v1_ if expression _expr_ is true or value _v2_ if expression _expr_ is false. | SELECT IF(1>10,'true','false') ;<br /><br />->false |
| IFNULL(v1,v2) | Returns value _v1_ if value _v1_ is not **null**. Otherwise, value _v2_ is returned. | SELECT IFNULL(null,'Hello Word');<br /><br />->HelloWord |
| ISNULL(expression) | Checks whether _expression_ is **NULL**. | SELECT ISNULL(NULL);<br /><br />->1 |
| LAST_INSERT_ID() | Returns the last AUTO_INCREMENT value. | SELECT LAST_INSERT_ID();<br /><br />->0 |
| NULLIF(expr1, expr2) | Compares two strings _expr1_ and _expr2_.<br />If they are the same, **NULL** is returned. Otherwise, _expr1_ is returned. | SELECT NULLIF(25,25);<br /><br />->NULL |
| SESSION_USER()<br />SYSTEM_USER()<br />USER() | Returns the current user. | SELECT SESSION_USER();<br /><br />->root@localhost |
| VERSION() | Returns the version number of the database. | SELECT VERSION();<br /><br />->5.6.24-StoneDB-log |
\ No newline at end of file
......@@ -3,4 +3,13 @@ id: aggregate-functions
sidebar_position: 6.45
---
# Aggregate Functions
\ No newline at end of file
# Aggregate Functions
This topic describes the aggregate functions supported by StoneDB.
| **Function** | **Description** | **Example** |
| --- | --- | --- |
| SUM(expression) | Returns the sum of values in field _expression_. | SELECT SUM(money) FROM account; |
| AVG(expression) | Returns the average value of field _expression_. | SELECT AVG(money) FROM account; |
| COUNT(expression) | Returns a count of the number of returned records. _expression_ can be set to a field or an asterisk (*). | SELECT COUNT(*) FROM account; |
| MAX(expression) | Returns the maximum value in field _expression_. | SELECT MAX(money) FROM account; |
| MIN(expression) | Returns the minimum value in field _expression_. | SELECT MIN(money) FROM account; |
\ No newline at end of file
......@@ -3,4 +3,56 @@ id: date-and-time-functions
sidebar_position: 6.41
---
# Date and Time Functions
\ No newline at end of file
# Date and Time Functions
This topic describes the date and time functions supported by StoneDB.
This topic describes the date and time functions supported by StoneDB.
| **Function** | **Description** | **Example** |
| --- | --- | --- |
| ADDDATE(d,n) | Adds time value (interval) _n_ to date _d_. | SELECT ADDDATE('2022-06-10', INTERVAL 5 DAY);<br /><br />->2022-06-15 |
| ADDTIME(t,n) | Adds time _n_ to time _t_. | SELECT ADDTIME('2022-06-10 10:00:00',5);<br /><br />->2022-06-10 10:00:05 |
| CURDATE()<br />CURRENT_DATE() | Returns the current date. | SELECT CURDATE();<br /><br />->2022-06-10 |
| CURRENT_TIME<br />CURTIME() | Returns the current time. | SELECT CURRENT_TIME();<br /><br />->17:10:31 |
| CURRENT_TIMESTAMP()<br />LOCALTIME()<br />LOCALTIMESTAMP()<br />NOW()<br />SYSDATE() | Returns the current date and time. | SELECT CURRENT_TIMESTAMP();<br /><br />->2022-06-10 17:11:06 |
| DATE() | Extracts the date part of a date or datetime expression. | SELECT DATE('2022-06-10'); <br /><br />->2022-06-10 |
| DATEDIFF(d1,d2) | Subtracts two dates. _d1_ and _d2_ each specify a date. | SELECT DATEDIFF('2022-06-10','2021-06-10');<br /><br />->365 |
| DATE_ADD(d,INTERVAL expr type) | Add time values (intervals) to date _d_. <br />_type_ can be set to **SECOND**, **MINUTE**, **HOUR**, **DAY**, **WEEK**, **MONTH**, and **YEAR**. | SELECT DATE_ADD('2022-06-10 17:17:21', INTERVAL -3 HOUR); <br /><br />->2022-06-10 14:17:21 |
| DATE_FORMAT(d,f) | Formats date _d_ based on expression _f_. | SELECT DATE_FORMAT('2022-06-10 17:21:11','%Y-%m-%d %r');<br /><br />->2022-06-10 05:21:11 PM |
| DATE_SUB(date,INTERVAL expr type) | Subtracts a time value (interval) from date _date_.<br />_type_ can be set to **SECOND**, **MINUTE**, **HOUR**, **DAY**, **WEEK**, **MONTH**, and **YEAR**. | SELECT DATE_SUB(<br />CURRENT_DATE(),INTERVAL 2 DAY);<br /><br />->2022-06-08 |
| DAY(d) | Returns the day in date _d_. | SELECT DAY('2022-06-10'); <br /><br />->10 |
| DAYNAME(d) | Returns the name of the weekday from date** **_d_, for example, **Monday**. | SELECT DAYNAME('2022-06-10 17:30:30');<br /><br />->Friday |
| DAYOFMONTH(d) | Returns the day of the month from date _d_. | SELECT DAYOFMONTH('2022-06-10 17:31:11');<br /><br />->10 |
| DAYOFWEEK(d) | Returns the weekday index from date _d_. <br />The return value ranges from 1 to 7 and value 1 indicates Sunday. | SELECT DAYOFWEEK('2022-06-10 17:35:11');<br /><br />->6 |
| DAYOFYEAR(d) | Returns the day of the year from date _d_. | SELECT DAYOFYEAR('2022-06-10 18:02:11');<br /><br />->161 |
| EXTRACT(type FROM d) | Extracts part of date _d_. <br />_type_ can be set to **SECOND**, **MINUTE**, **HOUR**, **DAY**, **WEEK**, **MONTH**, and **YEAR**. | SELECT EXTRACT(MONTH FROM '2022-06-10 18:02:33') ;<br /><br />->6 |
| HOUR(t) | Extracts the hour from time _t_. | SELECT HOUR('18:06:31');<br /><br />->18 |
| LAST_DAY(d) | Returns the last day of the month from date _d_. | SELECT LAST_DAY("2022-06-10");<br /><br />->2022-06-30 |
| MAKEDATE(year, day-of-year) | Creates a date based on the given year and day of year. <br />_year_ specifies the year. _day-of-year_ specifies the day of year. | SELECT MAKEDATE(2022,161);<br /><br />->2022-06-10 |
| MAKETIME(hour, minute, second) | Creates time based on the given hour, minute, and second. | SELECT MAKETIME(11,35,4);<br /><br />->11:35:04 |
| MICROSECOND(date) | Returns the microseconds from date _date_. | SELECT MICROSECOND('2022-06-10 18:12:00.000023');<br /><br />->23 |
| MINUTE(t) | Returns the minute from time _t_. | SELECT MINUTE('18:12:31');<br /><br />->12 |
| MONTHNAME(d) | Returns the name of the month from date _d_, such as **November**. | SELECT MONTHNAME('2022-06-10 18:13:19');<br /><br />->June |
| MONTH(d) | Returns the month from date _d_. <br />The return value ranges from 1 to 12. | SELECT MONTH('2022-06-10 18:14:11');<br /><br />->6 |
| PERIOD_ADD(period, number) | Adds a period (expressed in months) to a year-month. <br />_period_ specifies the year-month. _number_ specifies the period to add. | SELECT PERIOD_ADD(202206,5); <br /><br />->202211 |
| PERIOD_DIFF(period1, period2) | Returns the number of months between periods. | SELECT PERIOD_DIFF(202204,202012);<br /><br />->16 |
| QUARTER(d) | Returns the quarter from date _d_. <br />The return value ranges from 1 to 4. | SELECT QUARTER('2022-06-10 18:16:29');<br /><br />->2 |
| SECOND(t) | Returns the second from time _t_. | SELECT SECOND('18:17:36');<br /><br />->36 |
| SEC_TO_TIME(s) | Converts time _s_ which is expressed in seconds to the hh:mm:ss format. | SELECT SEC_TO_TIME(4320);<br /><br />->01:12:00 |
| STR_TO_DATE(string, format_mask) | Converts a string to a date. | SELECT STR_TO_DATE('June 10 2022','%M %d %Y');<br /><br />->2022-06-10 |
| SUBDATE(d,n) | Subtracts interval _n_ from date _d_. | SELECT SUBDATE('2022-06-10 18:19:27',15);<br /><br />->2022-05-26 18:19:27 |
| SUBTIME(t,n) | Subtracts period_ n_ from time _t_. n is expressed in seconds. | SELECT SUBTIME('2022-06-10 18:21:11',5);<br /><br />->2022-06-10 18:21:06 |
| TIME(expression) | Extracts the time portion of an expression. | SELECT TIME('18:22:10');<br /><br />->18:22:10 |
| TIME_FORMAT(t,f) | Formats time _t_ based on expression _f_. | SELECT TIME_FORMAT('18:22:59','%r');<br /><br />->06:22:59 PM |
| TIME_TO_SEC(t) | Converts time _t_ to seconds. | SELECT TIME_TO_SEC('18:24:00');<br /><br />->66240 |
| TIMEDIFF(time1, time2) | Subtracts two points in time. <br />_time1_ and _time2_ each specify a point in time. | SELECT TIMEDIFF('18:24:11','13:10:10');<br /><br />->05:14:01 |
| TIMESTAMP(expression, interval) | With a single argument, this function returns the date or datetime expression. With two arguments, this function returns the sum of the arguments. | SELECT TIMESTAMP('2022-06-10', '18:25:17');<br /><br />->2022-06-10 18:25:17 |
| TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) | Subtracts two datetime expressions. <br />_datetime_expr1_ and _datetime_expr2_ each specify a datetime expression. _unit_ specifies the unit of the return value. | <br />1. SELECT TIMESTAMPDIFF(DAY,'2020-12-23','2022-04-02');<br /> ->465<br /><br /><br />2. SELECT TIMESTAMPDIFF(MONTH,'2020-12-23','2022-04-02'); <br /> ->15<br /> |
| TO_DAYS(d) | Converts date _d_ to the number of days since date 0000-01-01. | SELECT TO_DAYS('2022-06-10 00:00:00');<br /><br />->738681 |
| WEEK(d) | Returns the week number of date_ d_. <br />The return value ranges from 0 to 53. | SELECT WEEK('2022-06-10 00:00:00');<br /><br />->23 |
| WEEKDAY(d) | Returns the weekday index of date _d_. <br />For example, return value **0** indicates Monday and **1** indicates Tuesday. | SELECT WEEKDAY('2022-06-10');<br /><br />->4 |
| WEEKOFYEAR(d) | Returns the calendar week of date _d_. <br />The return value ranges from 0 to 53. | SELECT WEEKOFYEAR('2022-06-10 11:11:11');<br /><br />->23 |
| YEAR(d) | Returns the year of date _d_. | SELECT YEAR('2022-06-10');<br /><br />->2022 |
| YEARWEEK(date, mode) | Returns the year and week number (value range: 0 to 53). <br />_mode_ is optional and specifies what day a week starts on. For example, return value **0** indicates Sunday and **1** indicates Monday. | SELECT YEARWEEK('2022-06-10');<br /><br />->202223 |
......@@ -3,4 +3,34 @@ id: mathematical-functions
sidebar_position: 6.43
---
# Mathematical Functions
\ No newline at end of file
# Mathematical Functions
This topic describes the mathematical functions supported by StoneDB.
| **Function** | **Description** | **Example** |
| --- | --- | --- |
| ABS(x) | Returns the absolute value. | SELECT ABS(-1);<br /><br />->1 |
| ACOS(x) | Returns the arc cosine of numeral value _x_. | SELECT ACOS(0.5);<br /><br />->1.0471975511965979 |
| ASIN(x) | Returns the arc sine of numeral value _x_. | SELECT ASIN(0.5);<br /><br />->0.5235987755982989 |
| ATAN(x) | Returns the arc tangent of numeral value _x_. | SELECT ATAN(2.5);<br /><br />->1.1902899496825317 |
| ATAN2(n, m) | Returns the arc tangent of two numeral values. | SELECT ATAN2(1,2);<br /><br />->0.4636476090008061 |
| COS(x) | Returns the cosine of radian _x_. | SELECT COS(2);<br /><br />->-0.4161468365471424 |
| COT(x) | Returns the cotangent of radian _x_. | SELECT COT(2);<br /><br />->-0.45765755436028577 |
| TAN(x) | Returns the tangent of radian _x_. | SELECT TAN(45); <br /><br />->1.6197751905438615 |
| SIN(x) | Returns the sine of radian _x_. | SELECT SIN(RADIANS(30));<br /><br />->0.49999999999999994 |
| CEIL(x)<br />CEILING(x) | Returns the smallest integer value that is not smaller than _x_. | SELECT CEIL(4.19);<br /><br />->5 |
| DEGREES(x) | Converts radian _x_ to a degree. | SELECT DEGREES(3.1415926535898);<br /><br />->180.0000000000004 |
| EXP(x) | Returns the natural exponential of _x_. | SELECT EXP(2);<br /><br />->7.38905609893065 |
| FLOOR(x) | Returns the largest integer value that is not greater than _x_. | SELECT FLOOR(3.24);<br /><br />->3 |
| GREATEST(expr1, expr2, expr3, ...) | Returns the greatest value within the specified list. | SELECT GREATEST(79,36,3,8,1);<br /><br />->79<br /><br />SELECT GREATEST('Hello','CHINA','STONEDB'); <br /><br />->STONEDB |
| LEAST(expr1, expr2, expr3, ...) | Returns the smallest value within the specified list. | SELECT LEAST(79,36,3,8,1);<br />->1<br /><br />SELECT LEAST('Hello','CHINA','STONEDB'); <br />->CHINA |
| LN(x) | Returns the natural logarithm of _x_. | SELECT LN(3); <br /><br />->1.0986122886681098 |
| LOG(x,y) | Returns the base-x logarithm of_ y_. | SELECT LOG(3,81);<br /><br />->4 |
| LOG2(x) | Returns the base-2 logarithm of_ x_. | SELECT LOG2(64); <br /><br />->6 |
| PI() | Returns the value of pi. | SELECT PI();<br /><br />->3.141593 |
| POW(x,y),<br />POWER(x,y) | Returns _x_ raised to the specified power of _y_. | SELECT POW(2,4);<br /><br />->16 |
| RAND() | Returns a random number between 0 and 1. | SELECT RAND();<br /><br />->0.12216221831940322 |
| ROUND(x) | Returns the value of _x_ rounded to the nearest integer. | SELECT ROUND(-5.26);<br /><br />->-5 |
| SIGN(x) | Returns the sign of _x_. <br />- If _x_ is a negative value, **-1** is returned. <br />- If_ x_ is 0, **0** is returned. <br />- If _x_ is a positive value, **1** is returned.<br /> | SELECT SIGN(-10);<br /><br />->(-1) |
| SQRT(x) | Returns the square root of _x_. | SELECT SQRT(81);<br /><br />->9 |
| TRUNCATE(x,y) | Truncates _x_ to retain _y_ decimal places. | SELECT TRUNCATE(2.2849106,3);<br /><br />->2.284 |
......@@ -3,4 +3,35 @@ id: string-functions
sidebar_position: 6.42
---
# String Functions
\ No newline at end of file
# String Functions
This topic describes the string functions supported by StoneDB.
| **Function** | **Description** | **Example** |
| --- | --- | --- |
| ASCII(s) | Returns the numeric value of the leftmost character of string _s_. | select ASCII('CHINA');<br /><br />->67 |
| CHAR_LENGTH(s)<br />CHARACTER_LENGTH(s) | Returns the number of characters in string _s_. | SELECT CHAR_LENGTH('CHINA');<br /><br />->5 |
| CONCAT(s1,s2...sn)<br />CONCAT_WS(x, s1,s2...sn) | Concatenates strings _s1_, _s2_, … _Sn_. | SELECT CONCAT('Welcome to ','CHINA');<br /><br />->Welcome to CHINA |
| FIELD(s,s1,s2...) | Returns the index of the first string _s_ in the list of subsequent strings (_s1_, _s2_, …). | SELECT FIELD("c","a","b","c","d","e");<br /><br />->3 |
| FIND_IN_SET(s1,s2) | Returns the index of the first string _s1_ within the second string _s2_. | SELECT FIND_IN_SET("c","a,b,c,d,e");<br /><br />->3 |
| FORMAT(x,n) | Returns a number formatted to _n_ decimal places. <br />_x_ specifies the number to format. The return value is in the #,###.## format. | SELECT FORMAT(9105885500.534,2); <br /><br />->9,105,885,500.53 |
| INSERT(s1,x,len,s2) | Inserts substring _s2_ at a given position up to the specified number of characters in string _s1_. <br />_x_ specifies position to insert. _len_ specifies the number of characters. | SELECT INSERT('Welcome to CHINA',1,6,'I love');<br /><br />->I lovee to CHINA |
| LOCATE(s1,s) | Returns the position of the first occurrence of substring s1 in string s. | SELECT LOCATE('db','stonedb'); <br /><br />->6 |
| LCASE(s)<br />LOWER(s) | Returns every character in string _s_ in lowercase. | SELECT LCASE('STONEDB');<br /><br />->stonedb |
| LEFT(s,n) | Returns the leftmost n characters in string_ s_. | SELECT LEFT('stonedb',5);<br /><br />->stone |
| LPAD(s1,len,s2) | Left-pads string _s2_ with string _s1_ to the specified length _len_. | SELECT LPAD('one',5,'st');<br /><br />->stone |
| LTRIM(s) | Remove leading spaces in string _s_. | SELECT LTRIM(' STONEDB');<br /><br />->STONEDB |
| MID(s,n,len) | Returns a substring of string s starting from a given position. <br />_n_ specifies the position. _len_ specifies the length of the substring. This function is the Synonym for SUBSTRING(s,n,len). | SELECT MID('stonedb',2,3);<br /><br />->ton |
| POSITION(s1 IN s) | Returns the position of the first occurrence of substring _s1_ in string _s_. | SELECT POSITION('db'in'stonedb');<br /><br />->6 |
| REPEAT(s,n) | Repeats string _s_ for _n_ times. | SELECT REPEAT('hello',3);<br /><br />->hellohellohello |
| REPLACE(s,s1,s2) | Replaces substring _s1_ in string _s_ with substring _s2_. | SELECT REPLACE('stonedb','db','x');<br /><br />->stonex |
| REVERSE(s) | Reverses the characters in string _s_. | SELECT REVERSE('stonedb');<br /><br />->bdenots |
| RIGHT(s,n) | Returns _n_ rightmost characters in string _s_. | SELECT RIGHT('stonedb',5);<br /><br />->onedb |
| RPAD(s1,len,s2) | Right-pads string _s2_ to string _s1_ to the specified length _len_. | SELECT RPAD('stone',7,'db');<br /><br />->stonedb |
| RTRIM(s) | Remove trailing spaces in string _s_. | SELECT RTRIM('STONEDB ');<br /><br />->STONEDB |
| SPACE(n) | Returns _n_ spaces. | SELECT SPACE(10);<br /><br />-> |
| STRCMP(s1,s2) | Compares the lengths of strings _s1_ and_ s2_. <br />- If _s1_ = _s2_, **0** is returned. <br />- If _s1_ > _s2_, **1** is returned. <br />- If _s1_ < _s2_, **-1** is returned.<br /> | SELECT STRCMP('stonedb','stone'); <br /><br />->1 |
| SUBSTR(s, start, length) | Returns a substring of the specified length within string _s_. <br />_start_ specifies the position from which the substring starts. | SELECT SUBSTR('STONEDB',2,3);<br /><br />->TON |
| SUBSTRING_INDEX(s, delimiter, number) | Returns a substring from string _s_ before the specified number of occurrences of the delimiter. | SELECT SUBSTRING_INDEX('stonedb','n',1);<br /><br />->sto |
| TRIM(s) | Removes leading and trailing spaces in string _s_. | SELECT TRIM(' STONEDB ');<br /><br />->STONEDB |
| UCASE(s)<br />UPPER(s) | Returns every character in string _s_ in uppercase. | SELECT UCASE('stonedb');<br /><br />->STONEDB |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册