diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md index a24aea386d65e..18db3df46e894 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin +## Description -### description -#### Syntax +Converts decimal numbers to binary text. -`STRING bin(BIGINT x)` -Convert the decimal number `x` to binary. +## Syntax -### example +```sql +BIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Decimal value to be converted | + +## Return Value +The binary representation of the parameter ``. When `` is negative, the result is its 64-bit complement. + +## Examples + +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md index 96c4edb104021..e9440f32bc7aa 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt +## Description -### description -#### Syntax +Calculate the cube root of the parameter -`DOUBLE cbrt(DOUBLE x)` -Returns the cube root of x. +## Syntax -### example +```sql +CBRT() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating point parameter | + +## Return Value + +Cubic root of parameter ``, a floating point number. + +## Examples + +```sql +select cbrt(0); +``` + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` +```sql +select cbrt(-111); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ ``` -### keywords - CBRT +```sql +select cbrt(1234); +``` + +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md index c91a10e91d3ad..39f28ca7784ed 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md @@ -22,66 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil +## Description -### description -#### Syntax +Round up floating-point and fixed-point decimals to a specific number of places and return the rounded floating-point or fixed-point number. -`T ceil(T x[, d])` +## Syntax -If not specified `d`: returns the smallest integer value less than or equal to `x`, which is **the most common usage**. -Otherwise, returns the smallest round number that is less than or equal to `x` and flowing the rules: +```sql +CEIL([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the smallest rounded number greater than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. -If `d` is specified as literal: -`d` = 0: just like without `d` -`d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact. +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` -:::tip -The other alias for this function are `dceil` and `ceiling`. -::: +## Alias -### example +- DCEIL +- CEILING +## Examples + +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ ``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -mysql> select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); + +```sql +select ceil(123.456, 2); +``` + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text +-----------------+--------------+-----------------+------------------+ | ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | +-----------------+--------------+-----------------+------------------+ | 123.5 | 124 | 124 | 130 | +-----------------+--------------+-----------------+------------------+ -mysql> SELECT number - -> , ceil(number * 2.5, number - 1) AS c_decimal_column - -> , ceil(number * 2.5, 0) AS c_decimal_literal - -> , ceil(cast(number * 2.5 AS DOUBLE), number - 1) AS c_double_column - -> , ceil(cast(number * 2.5 AS DOUBLE), 0) AS c_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | c_decimal_column | c_decimal_literal | c_double_column | c_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 3.0 | 3 | 3 | 3 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - CEIL, DCEIL, CEILING +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md index d585beaa2b36b..e65c214563a3b 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv +## Description -### description -#### Syntax +Do radix conversion for input parameter. + +## Syntax ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -Convert the input number to the target base. The input base range should be within `[2,36]`. -### example +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Parameters to be converted, either as strings or integers | +| `` | Numeric, the source base, within `[2,36]`. | +| `` | Numeric, the target base, within `[2,36]`. | + +## Return Value + +The number under the converted target binary `` is returned as a string. +## Examples + +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md index 44ea2564fb6a9..3e97c98cae225 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos +## Description -### description -#### Syntax +Calculate the cosine of the parameter -`DOUBLE cos(DOUBLE x)` -Returns the cosine of `x`, where `x` is in radians +## Syntax -### example +```sql +COS() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value +The cosine of the parameter ``, expressed in radians. + +## Examples + +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md index dad824eaaa75e..b37b050594832 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md @@ -22,66 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor +## Description -### description -#### Syntax +Round down floating-point and fixed-point decimals to a specific number of digits and return the rounded floating-point or fixed-point number. -`T floor(T x[, d])` +## Syntax -If not specified `d`: returns the largest integer value less than or equal to `x`, which is **the most common usage**. -Otherwise, returns the largest round number that is less than or equal to `x` and flowing the rules: +```sql +FLOOR([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the largest rounded number less than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. -If `d` is specified as literal: -`d` = 0: just like without `d` -`d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact. +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` -:::tip -Another alias for this function is `dfloor`. -::: +## Alias -### example +- DFLOOR +## Examples + +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ ``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); + +```sql +select floor(123.456, 2); +``` + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text +------------------+---------------+------------------+-------------------+ | floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | +------------------+---------------+------------------+-------------------+ | 123.4 | 123 | 123 | 120 | +------------------+---------------+------------------+-------------------+ -mysql> SELECT number - -> , floor(number * 2.5, number - 1) AS f_decimal_column - -> , floor(number * 2.5, 0) AS f_decimal_literal - -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column - -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 2.0 | 2 | 2 | 2 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - FLOOR, DFLOOR +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index d49a17b070b65..eb0e8807d5e84 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin +## Description -### description -#### Syntax +Calculate the sine of the parameter -`DOUBLE sin(DOUBLE x)` -Returns the sine of `x`, where `x` is in radians +## Syntax -### example +```sql +SIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value + +The sine of the parameter ``, expressed in radians. + +## Examples + +```sql +select sin(1); +``` + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` +```sql +select sin(0); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ ``` -### keywords - SIN +```sql +select sin(Pi()); +``` + +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md index 0029eefb346f9..0463171f60716 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin - ## 描述 + +将十进制数字转换为二进制文本。 + ## 语法 -`STRING bin(BIGINT x)` -将十进制数`x`转换为二进制数. +```sql +bin() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要转换的十进制值 | + +## 返回值 + +参数 `` 的二进制表示。当 `` 为负数时,结果为其 64 位补码表示。 ## 举例 +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md index d81a0cd5b1f22..48a8c03e1b11a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt - ## 描述 + +计算参数的立方根 + ## 语法 -`DOUBLE cbrt(DOUBLE x)` -返回`x`的立方根. +```sql +cbrt() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点参数 | + +## 返回值 + +参数 `` 的立方根,浮点数。 ## 举例 +```sql +select cbrt(0); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` + +```sql +select cbrt(-111); +``` + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ +``` + +```sql +select cbrt(1234); ``` -### keywords - CBRT +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md index e24de762f203d..3380c6b3e7b56 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md @@ -22,66 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil - ## 描述 + +对浮点及定点小数按特定位数向上取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT ceil(DOUBLE x)` +```sql +CEIL([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 -如果不指定`d`: 返回大于或等于`x`的最大整数值, 这也是**最常见的用法**. -否则, 按照下面规则返回最小的大于或者等于`x`的舍入数字: +按照下面规则返回最小的大于或者等于 `` 的舍入数字: -如 `d` 是字面量(不是列): -`d` = 0: 等同于没有 `d` -`d` > 0 or `d` < 0: 舍入数是 `1/(10^d)` 的倍数,如果 `1/(10^d)` 不精确,则为相应数据类型的最接近的数字。 +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 -如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: -:::tip -该函数的其他别名为 `dceil` 和 `ceiling`。 -::: +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DCEIL +- CEILING ## 举例 +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ +``` + +```sql +select ceil(123.456, 2); ``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -mysql> select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text +-----------------+--------------+-----------------+------------------+ | ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | +-----------------+--------------+-----------------+------------------+ | 123.5 | 124 | 124 | 130 | +-----------------+--------------+-----------------+------------------+ -mysql> SELECT number - -> , ceil(number * 2.5, number - 1) AS c_decimal_column - -> , ceil(number * 2.5, 0) AS c_decimal_literal - -> , ceil(cast(number * 2.5 AS DOUBLE), number - 1) AS c_double_column - -> , ceil(cast(number * 2.5 AS DOUBLE), 0) AS c_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | c_decimal_column | c_decimal_literal | c_double_column | c_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 3.0 | 3 | 3 | 3 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - CEIL, DCEIL, CEILING +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md index eb61848318361..13cd5f3a23d85 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv - ## 描述 + +对输入的数字进行进制转换 + ## 语法 ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -对输入的数字进行进制转换,输入的进制范围应该在`[2,36]`以内。 + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要进行进制转换的参数,可为字符串或整数 | +| `` | 数字,原始进制,范围应在 `[2,36]` 以内 | +| `` | 数字,目标进制,范围应在 `[2,36]` 以内 | + +## 返回值 + +转换后目标进制 `` 下的数字,以字符串形式返回。 ## 举例 +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md index d7f4369dd7331..593eaff6076c6 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos - ## 描述 + +计算参数的余弦值 + ## 语法 -`DOUBLE cos(DOUBLE x)` -返回`x`的余弦值,`x` 为弧度值. +```sql +COS() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的余弦值,弧度制表示。 ## 举例 +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md index 6bc426e6b4857..6fb2b46db883e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md @@ -22,66 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor - ## 描述 + +对浮点及定点小数按特定位数向下取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT floor(DOUBLE x)` +```sql +FLOOR([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 -如果不指定`d`: 返回小于或等于`x`的最大整数值, 这也是**最常见的用法**. -否则, 按照下面规则返回最大的小于或者等于`x`的舍入数字: +按照下面规则返回最大的小于或者等于 `` 的舍入数字: -如 `d` 是字面量(不是列): -`d` = 0: 等同于没有 `d` -`d` > 0 or `d` < 0: 舍入数是 `1/(10^d)` 的倍数,如果 `1/(10^d)` 不精确,则为相应数据类型的最接近的数字。 +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 -如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: -:::tip -该函数的另一个别名为 `dfloor`。 -::: +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DFLOOR ## 举例 +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ +``` + +```sql +select floor(123.456, 2); ``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text +------------------+---------------+------------------+-------------------+ | floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | +------------------+---------------+------------------+-------------------+ | 123.4 | 123 | 123 | 120 | +------------------+---------------+------------------+-------------------+ -mysql> SELECT number - -> , floor(number * 2.5, number - 1) AS f_decimal_column - -> , floor(number * 2.5, 0) AS f_decimal_literal - -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column - -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 2.0 | 2 | 2 | 2 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - FLOOR, DFLOOR +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index 120e96e6b8dcd..a98e2eece7ede 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin - ## 描述 + +计算参数的正弦值 + ## 语法 -`DOUBLE sin(DOUBLE x)` -返回`x`的正弦值,`x` 为弧度值. +```sql +SIN() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的正弦值,弧度制表示。 ## 举例 +```sql +select sin(1); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` + +```sql +select sin(0); +``` + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ +``` + +```sql +select sin(Pi()); ``` -### keywords - SIN +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md index 0029eefb346f9..0463171f60716 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin - ## 描述 + +将十进制数字转换为二进制文本。 + ## 语法 -`STRING bin(BIGINT x)` -将十进制数`x`转换为二进制数. +```sql +bin() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要转换的十进制值 | + +## 返回值 + +参数 `` 的二进制表示。当 `` 为负数时,结果为其 64 位补码表示。 ## 举例 +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md index d81a0cd5b1f22..48a8c03e1b11a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt - ## 描述 + +计算参数的立方根 + ## 语法 -`DOUBLE cbrt(DOUBLE x)` -返回`x`的立方根. +```sql +cbrt() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点参数 | + +## 返回值 + +参数 `` 的立方根,浮点数。 ## 举例 +```sql +select cbrt(0); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` + +```sql +select cbrt(-111); +``` + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ +``` + +```sql +select cbrt(1234); ``` -### keywords - CBRT +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md index c11e907762030..3380c6b3e7b56 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md @@ -22,40 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil - ## 描述 + +对浮点及定点小数按特定位数向上取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT ceil(DOUBLE x)` -返回大于或等于`x`的最小整数值. +```sql +CEIL([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 + +按照下面规则返回最小的大于或者等于 `` 的舍入数字: -:::tip -该函数的其他别名为 `dceil` 和 `ceiling`。 -::: +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 + +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: + +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DCEIL +- CEILING ## 举例 +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ +``` + +```sql +select ceil(123.456, 2); +``` + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text ++-----------------+--------------+-----------------+------------------+ +| ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | ++-----------------+--------------+-----------------+------------------+ +| 123.5 | 124 | 124 | 130 | ++-----------------+--------------+-----------------+------------------+ +``` + +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ ``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -``` - -### keywords - CEIL, DCEIL, CEILING diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md index eb61848318361..13cd5f3a23d85 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv - ## 描述 + +对输入的数字进行进制转换 + ## 语法 ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -对输入的数字进行进制转换,输入的进制范围应该在`[2,36]`以内。 + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要进行进制转换的参数,可为字符串或整数 | +| `` | 数字,原始进制,范围应在 `[2,36]` 以内 | +| `` | 数字,目标进制,范围应在 `[2,36]` 以内 | + +## 返回值 + +转换后目标进制 `` 下的数字,以字符串形式返回。 ## 举例 +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md index d7f4369dd7331..593eaff6076c6 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos - ## 描述 + +计算参数的余弦值 + ## 语法 -`DOUBLE cos(DOUBLE x)` -返回`x`的余弦值,`x` 为弧度值. +```sql +COS() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的余弦值,弧度制表示。 ## 举例 +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md index 43bd2c5771dea..6fb2b46db883e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md @@ -22,40 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor - ## 描述 + +对浮点及定点小数按特定位数向下取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT floor(DOUBLE x)` -返回小于或等于`x`的最大整数值. +```sql +FLOOR([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 + +按照下面规则返回最大的小于或者等于 `` 的舍入数字: -:::tip -该函数的另一个别名为 `dfloor`。 -::: +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 + +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: + +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DFLOOR ## 举例 +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ +``` + +```sql +select floor(123.456, 2); +``` + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text ++------------------+---------------+------------------+-------------------+ +| floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | ++------------------+---------------+------------------+-------------------+ +| 123.4 | 123 | 123 | 120 | ++------------------+---------------+------------------+-------------------+ +``` + +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ ``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -``` - -### keywords - FLOOR, DFLOOR diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md index 120e96e6b8dcd..a98e2eece7ede 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin - ## 描述 + +计算参数的正弦值 + ## 语法 -`DOUBLE sin(DOUBLE x)` -返回`x`的正弦值,`x` 为弧度值. +```sql +SIN() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的正弦值,弧度制表示。 ## 举例 +```sql +select sin(1); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` + +```sql +select sin(0); +``` + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ +``` + +```sql +select sin(Pi()); ``` -### keywords - SIN +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md index 0029eefb346f9..0463171f60716 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin - ## 描述 + +将十进制数字转换为二进制文本。 + ## 语法 -`STRING bin(BIGINT x)` -将十进制数`x`转换为二进制数. +```sql +bin() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要转换的十进制值 | + +## 返回值 + +参数 `` 的二进制表示。当 `` 为负数时,结果为其 64 位补码表示。 ## 举例 +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md index d81a0cd5b1f22..48a8c03e1b11a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt - ## 描述 + +计算参数的立方根 + ## 语法 -`DOUBLE cbrt(DOUBLE x)` -返回`x`的立方根. +```sql +cbrt() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点参数 | + +## 返回值 + +参数 `` 的立方根,浮点数。 ## 举例 +```sql +select cbrt(0); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` + +```sql +select cbrt(-111); +``` + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ +``` + +```sql +select cbrt(1234); ``` -### keywords - CBRT +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md index e24de762f203d..3380c6b3e7b56 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md @@ -22,66 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil - ## 描述 + +对浮点及定点小数按特定位数向上取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT ceil(DOUBLE x)` +```sql +CEIL([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 -如果不指定`d`: 返回大于或等于`x`的最大整数值, 这也是**最常见的用法**. -否则, 按照下面规则返回最小的大于或者等于`x`的舍入数字: +按照下面规则返回最小的大于或者等于 `` 的舍入数字: -如 `d` 是字面量(不是列): -`d` = 0: 等同于没有 `d` -`d` > 0 or `d` < 0: 舍入数是 `1/(10^d)` 的倍数,如果 `1/(10^d)` 不精确,则为相应数据类型的最接近的数字。 +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 -如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: -:::tip -该函数的其他别名为 `dceil` 和 `ceiling`。 -::: +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DCEIL +- CEILING ## 举例 +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ +``` + +```sql +select ceil(123.456, 2); ``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -mysql> select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text +-----------------+--------------+-----------------+------------------+ | ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | +-----------------+--------------+-----------------+------------------+ | 123.5 | 124 | 124 | 130 | +-----------------+--------------+-----------------+------------------+ -mysql> SELECT number - -> , ceil(number * 2.5, number - 1) AS c_decimal_column - -> , ceil(number * 2.5, 0) AS c_decimal_literal - -> , ceil(cast(number * 2.5 AS DOUBLE), number - 1) AS c_double_column - -> , ceil(cast(number * 2.5 AS DOUBLE), 0) AS c_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | c_decimal_column | c_decimal_literal | c_double_column | c_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 3.0 | 3 | 3 | 3 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - CEIL, DCEIL, CEILING +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md index eb61848318361..13cd5f3a23d85 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv - ## 描述 + +对输入的数字进行进制转换 + ## 语法 ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -对输入的数字进行进制转换,输入的进制范围应该在`[2,36]`以内。 + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要进行进制转换的参数,可为字符串或整数 | +| `` | 数字,原始进制,范围应在 `[2,36]` 以内 | +| `` | 数字,目标进制,范围应在 `[2,36]` 以内 | + +## 返回值 + +转换后目标进制 `` 下的数字,以字符串形式返回。 ## 举例 +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md index d7f4369dd7331..593eaff6076c6 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos - ## 描述 + +计算参数的余弦值 + ## 语法 -`DOUBLE cos(DOUBLE x)` -返回`x`的余弦值,`x` 为弧度值. +```sql +COS() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的余弦值,弧度制表示。 ## 举例 +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md index 6bc426e6b4857..6fb2b46db883e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md @@ -22,66 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor - ## 描述 + +对浮点及定点小数按特定位数向下取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT floor(DOUBLE x)` +```sql +FLOOR([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 -如果不指定`d`: 返回小于或等于`x`的最大整数值, 这也是**最常见的用法**. -否则, 按照下面规则返回最大的小于或者等于`x`的舍入数字: +按照下面规则返回最大的小于或者等于 `` 的舍入数字: -如 `d` 是字面量(不是列): -`d` = 0: 等同于没有 `d` -`d` > 0 or `d` < 0: 舍入数是 `1/(10^d)` 的倍数,如果 `1/(10^d)` 不精确,则为相应数据类型的最接近的数字。 +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 -如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: -:::tip -该函数的另一个别名为 `dfloor`。 -::: +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DFLOOR ## 举例 +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ +``` + +```sql +select floor(123.456, 2); ``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text +------------------+---------------+------------------+-------------------+ | floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | +------------------+---------------+------------------+-------------------+ | 123.4 | 123 | 123 | 120 | +------------------+---------------+------------------+-------------------+ -mysql> SELECT number - -> , floor(number * 2.5, number - 1) AS f_decimal_column - -> , floor(number * 2.5, 0) AS f_decimal_literal - -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column - -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 2.0 | 2 | 2 | 2 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - FLOOR, DFLOOR +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index 120e96e6b8dcd..a98e2eece7ede 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin - ## 描述 + +计算参数的正弦值 + ## 语法 -`DOUBLE sin(DOUBLE x)` -返回`x`的正弦值,`x` 为弧度值. +```sql +SIN() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的正弦值,弧度制表示。 ## 举例 +```sql +select sin(1); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` + +```sql +select sin(0); +``` + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ +``` + +```sql +select sin(Pi()); ``` -### keywords - SIN +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md index 0029eefb346f9..0463171f60716 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin - ## 描述 + +将十进制数字转换为二进制文本。 + ## 语法 -`STRING bin(BIGINT x)` -将十进制数`x`转换为二进制数. +```sql +bin() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要转换的十进制值 | + +## 返回值 + +参数 `` 的二进制表示。当 `` 为负数时,结果为其 64 位补码表示。 ## 举例 +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md index d81a0cd5b1f22..48a8c03e1b11a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt - ## 描述 + +计算参数的立方根 + ## 语法 -`DOUBLE cbrt(DOUBLE x)` -返回`x`的立方根. +```sql +cbrt() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点参数 | + +## 返回值 + +参数 `` 的立方根,浮点数。 ## 举例 +```sql +select cbrt(0); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` + +```sql +select cbrt(-111); +``` + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ +``` + +```sql +select cbrt(1234); ``` -### keywords - CBRT +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md index e24de762f203d..3380c6b3e7b56 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md @@ -22,66 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil - ## 描述 + +对浮点及定点小数按特定位数向上取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT ceil(DOUBLE x)` +```sql +CEIL([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 -如果不指定`d`: 返回大于或等于`x`的最大整数值, 这也是**最常见的用法**. -否则, 按照下面规则返回最小的大于或者等于`x`的舍入数字: +按照下面规则返回最小的大于或者等于 `` 的舍入数字: -如 `d` 是字面量(不是列): -`d` = 0: 等同于没有 `d` -`d` > 0 or `d` < 0: 舍入数是 `1/(10^d)` 的倍数,如果 `1/(10^d)` 不精确,则为相应数据类型的最接近的数字。 +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 -如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: -:::tip -该函数的其他别名为 `dceil` 和 `ceiling`。 -::: +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DCEIL +- CEILING ## 举例 +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ +``` + +```sql +select ceil(123.456, 2); ``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -mysql> select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text +-----------------+--------------+-----------------+------------------+ | ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | +-----------------+--------------+-----------------+------------------+ | 123.5 | 124 | 124 | 130 | +-----------------+--------------+-----------------+------------------+ -mysql> SELECT number - -> , ceil(number * 2.5, number - 1) AS c_decimal_column - -> , ceil(number * 2.5, 0) AS c_decimal_literal - -> , ceil(cast(number * 2.5 AS DOUBLE), number - 1) AS c_double_column - -> , ceil(cast(number * 2.5 AS DOUBLE), 0) AS c_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | c_decimal_column | c_decimal_literal | c_double_column | c_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 3.0 | 3 | 3 | 3 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - CEIL, DCEIL, CEILING +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md index eb61848318361..13cd5f3a23d85 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv - ## 描述 + +对输入的数字进行进制转换 + ## 语法 ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -对输入的数字进行进制转换,输入的进制范围应该在`[2,36]`以内。 + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 需要进行进制转换的参数,可为字符串或整数 | +| `` | 数字,原始进制,范围应在 `[2,36]` 以内 | +| `` | 数字,目标进制,范围应在 `[2,36]` 以内 | + +## 返回值 + +转换后目标进制 `` 下的数字,以字符串形式返回。 ## 举例 +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md index d7f4369dd7331..593eaff6076c6 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos - ## 描述 + +计算参数的余弦值 + ## 语法 -`DOUBLE cos(DOUBLE x)` -返回`x`的余弦值,`x` 为弧度值. +```sql +COS() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的余弦值,弧度制表示。 ## 举例 +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md index 6bc426e6b4857..6fb2b46db883e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md @@ -22,66 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor - ## 描述 + +对浮点及定点小数按特定位数向下取整,返回取整过后的浮点或定点数。 + ## 语法 -`BIGINT floor(DOUBLE x)` +```sql +FLOOR([, ]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点(Double)或定点(Decimal)参数,表示要进行取整的参数 | +| `` | 可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,`0` 表示舍入到整数。不填写时等同于 ` = 0` | + +## 返回值 -如果不指定`d`: 返回小于或等于`x`的最大整数值, 这也是**最常见的用法**. -否则, 按照下面规则返回最大的小于或者等于`x`的舍入数字: +按照下面规则返回最大的小于或者等于 `` 的舍入数字: -如 `d` 是字面量(不是列): -`d` = 0: 等同于没有 `d` -`d` > 0 or `d` < 0: 舍入数是 `1/(10^d)` 的倍数,如果 `1/(10^d)` 不精确,则为相应数据类型的最接近的数字。 +舍入到 `1/(10^d)` 位,即,使结果可整除`1/(10^d)`。如果 `1/(10^d)` 不精确,则舍入位数为相应数据类型的最接近的数字。 -如果 `d` 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 +对于 Decimal 类型的入参 ``,假设其类型为 `Decimal(p, s)`,则返回值类型为: -:::tip -该函数的另一个别名为 `dfloor`。 -::: +- `Decimal(p, 0)`,若 ` <= 0` +- `Decimal(p, )`,若 `0 < <= s` +- `Decimal(p, s)`,若 ` > s` + +## 别名 + +- DFLOOR ## 举例 +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ +``` + +```sql +select floor(123.456, 2); ``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text +------------------+---------------+------------------+-------------------+ | floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | +------------------+---------------+------------------+-------------------+ | 123.4 | 123 | 123 | 120 | +------------------+---------------+------------------+-------------------+ -mysql> SELECT number - -> , floor(number * 2.5, number - 1) AS f_decimal_column - -> , floor(number * 2.5, 0) AS f_decimal_literal - -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column - -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 2.0 | 2 | 2 | 2 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - FLOOR, DFLOOR +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index 120e96e6b8dcd..a98e2eece7ede 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin - ## 描述 + +计算参数的正弦值 + ## 语法 -`DOUBLE sin(DOUBLE x)` -返回`x`的正弦值,`x` 为弧度值. +```sql +SIN() +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 浮点数,要计算参数的弧度值 | + +## 返回值 + +参数 `` 的正弦值,弧度制表示。 ## 举例 +```sql +select sin(1); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` + +```sql +select sin(0); +``` + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ +``` + +```sql +select sin(Pi()); ``` -### keywords - SIN +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +``` diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md index a24aea386d65e..18db3df46e894 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin +## Description -### description -#### Syntax +Converts decimal numbers to binary text. -`STRING bin(BIGINT x)` -Convert the decimal number `x` to binary. +## Syntax -### example +```sql +BIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Decimal value to be converted | + +## Return Value +The binary representation of the parameter ``. When `` is negative, the result is its 64-bit complement. + +## Examples + +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md index 96c4edb104021..e9440f32bc7aa 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt +## Description -### description -#### Syntax +Calculate the cube root of the parameter -`DOUBLE cbrt(DOUBLE x)` -Returns the cube root of x. +## Syntax -### example +```sql +CBRT() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating point parameter | + +## Return Value + +Cubic root of parameter ``, a floating point number. + +## Examples + +```sql +select cbrt(0); +``` + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` +```sql +select cbrt(-111); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ ``` -### keywords - CBRT +```sql +select cbrt(1234); +``` + +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md index a222dcde8b8c2..39f28ca7784ed 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/ceil.md @@ -22,40 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil - -### description -#### Syntax - -`BIGINT ceil(DOUBLE x)` -Returns the smallest integer value greater than or equal to `x`. - -:::tip -The other alias for this function are `dceil` and `ceiling`. -::: - -### example - -``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -``` - -### keywords - CEIL, DCEIL, CEILING +## Description + +Round up floating-point and fixed-point decimals to a specific number of places and return the rounded floating-point or fixed-point number. + +## Syntax + +```sql +CEIL([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the smallest rounded number greater than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. + +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: + +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` + +## Alias + +- DCEIL +- CEILING + +## Examples + +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ +``` + +```sql +select ceil(123.456, 2); +``` + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text ++-----------------+--------------+-----------------+------------------+ +| ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | ++-----------------+--------------+-----------------+------------------+ +| 123.5 | 124 | 124 | 130 | ++-----------------+--------------+-----------------+------------------+ +``` + +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ +``` diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md index d585beaa2b36b..e65c214563a3b 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv +## Description -### description -#### Syntax +Do radix conversion for input parameter. + +## Syntax ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -Convert the input number to the target base. The input base range should be within `[2,36]`. -### example +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Parameters to be converted, either as strings or integers | +| `` | Numeric, the source base, within `[2,36]`. | +| `` | Numeric, the target base, within `[2,36]`. | + +## Return Value + +The number under the converted target binary `` is returned as a string. +## Examples + +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md index 44ea2564fb6a9..3e97c98cae225 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos +## Description -### description -#### Syntax +Calculate the cosine of the parameter -`DOUBLE cos(DOUBLE x)` -Returns the cosine of `x`, where `x` is in radians +## Syntax -### example +```sql +COS() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value +The cosine of the parameter ``, expressed in radians. + +## Examples + +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md index 824f142934fae..b37b050594832 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/floor.md @@ -22,40 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor - -### description -#### Syntax - -`BIGINT floor(DOUBLE x)` -Returns the largest integer value less than or equal to `x`. - -:::tip -Another alias for this function is `dfloor`. -::: - -### example - -``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -``` - -### keywords - FLOOR, DFLOOR +## Description + +Round down floating-point and fixed-point decimals to a specific number of digits and return the rounded floating-point or fixed-point number. + +## Syntax + +```sql +FLOOR([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the largest rounded number less than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. + +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: + +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` + +## Alias + +- DFLOOR + +## Examples + +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ +``` + +```sql +select floor(123.456, 2); +``` + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text ++------------------+---------------+------------------+-------------------+ +| floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | ++------------------+---------------+------------------+-------------------+ +| 123.4 | 123 | 123 | 120 | ++------------------+---------------+------------------+-------------------+ +``` + +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ +``` diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md index d49a17b070b65..eb0e8807d5e84 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin +## Description -### description -#### Syntax +Calculate the sine of the parameter -`DOUBLE sin(DOUBLE x)` -Returns the sine of `x`, where `x` is in radians +## Syntax -### example +```sql +SIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value + +The sine of the parameter ``, expressed in radians. + +## Examples + +```sql +select sin(1); +``` + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` +```sql +select sin(0); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ ``` -### keywords - SIN +```sql +select sin(Pi()); +``` + +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md index a24aea386d65e..18db3df46e894 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin +## Description -### description -#### Syntax +Converts decimal numbers to binary text. -`STRING bin(BIGINT x)` -Convert the decimal number `x` to binary. +## Syntax -### example +```sql +BIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Decimal value to be converted | + +## Return Value +The binary representation of the parameter ``. When `` is negative, the result is its 64-bit complement. + +## Examples + +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md index 96c4edb104021..e9440f32bc7aa 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt +## Description -### description -#### Syntax +Calculate the cube root of the parameter -`DOUBLE cbrt(DOUBLE x)` -Returns the cube root of x. +## Syntax -### example +```sql +CBRT() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating point parameter | + +## Return Value + +Cubic root of parameter ``, a floating point number. + +## Examples + +```sql +select cbrt(0); +``` + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` +```sql +select cbrt(-111); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ ``` -### keywords - CBRT +```sql +select cbrt(1234); +``` + +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md index c91a10e91d3ad..39f28ca7784ed 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md @@ -22,66 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil +## Description -### description -#### Syntax +Round up floating-point and fixed-point decimals to a specific number of places and return the rounded floating-point or fixed-point number. -`T ceil(T x[, d])` +## Syntax -If not specified `d`: returns the smallest integer value less than or equal to `x`, which is **the most common usage**. -Otherwise, returns the smallest round number that is less than or equal to `x` and flowing the rules: +```sql +CEIL([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the smallest rounded number greater than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. -If `d` is specified as literal: -`d` = 0: just like without `d` -`d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact. +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` -:::tip -The other alias for this function are `dceil` and `ceiling`. -::: +## Alias -### example +- DCEIL +- CEILING +## Examples + +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ ``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -mysql> select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); + +```sql +select ceil(123.456, 2); +``` + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text +-----------------+--------------+-----------------+------------------+ | ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | +-----------------+--------------+-----------------+------------------+ | 123.5 | 124 | 124 | 130 | +-----------------+--------------+-----------------+------------------+ -mysql> SELECT number - -> , ceil(number * 2.5, number - 1) AS c_decimal_column - -> , ceil(number * 2.5, 0) AS c_decimal_literal - -> , ceil(cast(number * 2.5 AS DOUBLE), number - 1) AS c_double_column - -> , ceil(cast(number * 2.5 AS DOUBLE), 0) AS c_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | c_decimal_column | c_decimal_literal | c_double_column | c_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 3.0 | 3 | 3 | 3 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - CEIL, DCEIL, CEILING +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md index d585beaa2b36b..e65c214563a3b 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv +## Description -### description -#### Syntax +Do radix conversion for input parameter. + +## Syntax ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -Convert the input number to the target base. The input base range should be within `[2,36]`. -### example +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Parameters to be converted, either as strings or integers | +| `` | Numeric, the source base, within `[2,36]`. | +| `` | Numeric, the target base, within `[2,36]`. | + +## Return Value + +The number under the converted target binary `` is returned as a string. +## Examples + +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md index 44ea2564fb6a9..3e97c98cae225 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos +## Description -### description -#### Syntax +Calculate the cosine of the parameter -`DOUBLE cos(DOUBLE x)` -Returns the cosine of `x`, where `x` is in radians +## Syntax -### example +```sql +COS() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value +The cosine of the parameter ``, expressed in radians. + +## Examples + +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md index dad824eaaa75e..b37b050594832 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md @@ -22,66 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor +## Description -### description -#### Syntax +Round down floating-point and fixed-point decimals to a specific number of digits and return the rounded floating-point or fixed-point number. -`T floor(T x[, d])` +## Syntax -If not specified `d`: returns the largest integer value less than or equal to `x`, which is **the most common usage**. -Otherwise, returns the largest round number that is less than or equal to `x` and flowing the rules: +```sql +FLOOR([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the largest rounded number less than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. -If `d` is specified as literal: -`d` = 0: just like without `d` -`d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact. +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` -:::tip -Another alias for this function is `dfloor`. -::: +## Alias -### example +- DFLOOR +## Examples + +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ ``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); + +```sql +select floor(123.456, 2); +``` + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text +------------------+---------------+------------------+-------------------+ | floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | +------------------+---------------+------------------+-------------------+ | 123.4 | 123 | 123 | 120 | +------------------+---------------+------------------+-------------------+ -mysql> SELECT number - -> , floor(number * 2.5, number - 1) AS f_decimal_column - -> , floor(number * 2.5, 0) AS f_decimal_literal - -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column - -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 2.0 | 2 | 2 | 2 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - FLOOR, DFLOOR +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index d49a17b070b65..eb0e8807d5e84 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin +## Description -### description -#### Syntax +Calculate the sine of the parameter -`DOUBLE sin(DOUBLE x)` -Returns the sine of `x`, where `x` is in radians +## Syntax -### example +```sql +SIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value + +The sine of the parameter ``, expressed in radians. + +## Examples + +```sql +select sin(1); +``` + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` +```sql +select sin(0); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ ``` -### keywords - SIN +```sql +select sin(Pi()); +``` + +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md index a24aea386d65e..18db3df46e894 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/bin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## bin +## Description -### description -#### Syntax +Converts decimal numbers to binary text. -`STRING bin(BIGINT x)` -Convert the decimal number `x` to binary. +## Syntax -### example +```sql +BIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Decimal value to be converted | + +## Return Value +The binary representation of the parameter ``. When `` is negative, the result is its 64-bit complement. + +## Examples + +```sql +select bin(0); ``` -mysql> select bin(0); + +```text +--------+ | bin(0) | +--------+ | 0 | +--------+ -mysql> select bin(10); -+---------+ -| bin(10) | -+---------+ -| 1010 | -+---------+ -mysql> select bin(-3); +``` + +```sql +select bin(-1); +``` + +```text +------------------------------------------------------------------+ -| bin(-3) | +| bin(-1) | +------------------------------------------------------------------+ -| 1111111111111111111111111111111111111111111111111111111111111101 | +| 1111111111111111111111111111111111111111111111111111111111111111 | +------------------------------------------------------------------+ ``` -### keywords - BIN +```sql +select bin(123); +``` + +```text ++----------+ +| bin(123) | ++----------+ +| 1111011 | ++----------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md index 96c4edb104021..e9440f32bc7aa 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cbrt.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cbrt +## Description -### description -#### Syntax +Calculate the cube root of the parameter -`DOUBLE cbrt(DOUBLE x)` -Returns the cube root of x. +## Syntax -### example +```sql +CBRT() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating point parameter | + +## Return Value + +Cubic root of parameter ``, a floating point number. + +## Examples + +```sql +select cbrt(0); +``` + +```text ++-------------------------+ +| cbrt(cast(0 as DOUBLE)) | ++-------------------------+ +| 0.0 | ++-------------------------+ +``` +```sql +select cbrt(-111); ``` -mysql> select cbrt(8); -+-----------+ -| cbrt(8.0) | -+-----------+ -| 2 | -+-----------+ -mysql> select cbrt(2.0); -+--------------------+ -| cbrt(2.0) | -+--------------------+ -| 1.2599210498948734 | -+--------------------+ -mysql> select cbrt(-1000.0); -+---------------+ -| cbrt(-1000.0) | -+---------------+ -| -10 | -+---------------+ + +```text ++----------------------------+ +| cbrt(cast(-111 as DOUBLE)) | ++----------------------------+ +| -4.805895533705333 | ++----------------------------+ ``` -### keywords - CBRT +```sql +select cbrt(1234); +``` + +```text ++----------------------------+ +| cbrt(cast(1234 as DOUBLE)) | ++----------------------------+ +| 10.726014668827325 | ++----------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md index c91a10e91d3ad..39f28ca7784ed 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/ceil.md @@ -22,66 +22,102 @@ specific language governing permissions and limitations under the License. --> -## ceil +## Description -### description -#### Syntax +Round up floating-point and fixed-point decimals to a specific number of places and return the rounded floating-point or fixed-point number. -`T ceil(T x[, d])` +## Syntax -If not specified `d`: returns the smallest integer value less than or equal to `x`, which is **the most common usage**. -Otherwise, returns the smallest round number that is less than or equal to `x` and flowing the rules: +```sql +CEIL([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the smallest rounded number greater than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. -If `d` is specified as literal: -`d` = 0: just like without `d` -`d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact. +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` -:::tip -The other alias for this function are `dceil` and `ceiling`. -::: +## Alias -### example +- DCEIL +- CEILING +## Examples + +```sql +select ceil(123.456); +``` + +```text ++---------------+ +| ceil(123.456) | ++---------------+ +| 124 | ++---------------+ ``` -mysql> select ceil(1); -+-----------+ -| ceil(1.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select ceil(2.4); -+-----------+ -| ceil(2.4) | -+-----------+ -| 3 | -+-----------+ -mysql> select ceil(-10.3); -+-------------+ -| ceil(-10.3) | -+-------------+ -| -10 | -+-------------+ -mysql> select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); + +```sql +select ceil(123.456, 2); +``` + +```text ++------------------+ +| ceil(123.456, 2) | ++------------------+ +| 123.46 | ++------------------+ +``` + +```sql +select ceil(123.456, -2); +``` + +```text ++-------------------+ +| ceil(123.456, -2) | ++-------------------+ +| 200 | ++-------------------+ +``` + +```sql +select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1); +``` + +```text +-----------------+--------------+-----------------+------------------+ | ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) | +-----------------+--------------+-----------------+------------------+ | 123.5 | 124 | 124 | 130 | +-----------------+--------------+-----------------+------------------+ -mysql> SELECT number - -> , ceil(number * 2.5, number - 1) AS c_decimal_column - -> , ceil(number * 2.5, 0) AS c_decimal_literal - -> , ceil(cast(number * 2.5 AS DOUBLE), number - 1) AS c_double_column - -> , ceil(cast(number * 2.5 AS DOUBLE), 0) AS c_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | c_decimal_column | c_decimal_literal | c_double_column | c_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 3.0 | 3 | 3 | 3 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - CEIL, DCEIL, CEILING +```sql +select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++------------+ +| ceil(x, 2) | ++------------+ +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | +| 123.46 | ++------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md index d585beaa2b36b..e65c214563a3b 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/conv.md @@ -22,41 +22,62 @@ specific language governing permissions and limitations under the License. --> -## conv +## Description -### description -#### Syntax +Do radix conversion for input parameter. + +## Syntax ```sql -VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base) -VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base) +CONV(, , ) ``` -Convert the input number to the target base. The input base range should be within `[2,36]`. -### example +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Parameters to be converted, either as strings or integers | +| `` | Numeric, the source base, within `[2,36]`. | +| `` | Numeric, the target base, within `[2,36]`. | + +## Return Value + +The number under the converted target binary `` is returned as a string. +## Examples + +```sql +SELECT CONV(15,10,2); ``` -MySQL [test]> SELECT CONV(15,10,2); + +```text +-----------------+ | conv(15, 10, 2) | +-----------------+ | 1111 | +-----------------+ +``` -MySQL [test]> SELECT CONV('ff',16,10); +```sql +SELECT CONV('ff',16,10); +``` + +```text +--------------------+ | conv('ff', 16, 10) | +--------------------+ | 255 | +--------------------+ +``` -MySQL [test]> SELECT CONV(230,10,16); +```sql +SELECT CONV(230,10,16); +``` + +```text +-------------------+ | conv(230, 10, 16) | +-------------------+ | E6 | +-------------------+ ``` - -### keywords - CONV diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md index 44ea2564fb6a9..3e97c98cae225 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/cos.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## cos +## Description -### description -#### Syntax +Calculate the cosine of the parameter -`DOUBLE cos(DOUBLE x)` -Returns the cosine of `x`, where `x` is in radians +## Syntax -### example +```sql +COS() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value +The cosine of the parameter ``, expressed in radians. + +## Examples + +```sql +select cos(1); ``` -mysql> select cos(1); + +```text +---------------------+ | cos(1.0) | +---------------------+ | 0.54030230586813977 | +---------------------+ -mysql> select cos(0); -+----------+ -| cos(0.0) | -+----------+ -| 1 | -+----------+ -mysql> select cos(Pi()); +``` + +```sql +select cos(0); +``` + +```text ++------------------------+ +| cos(cast(0 as DOUBLE)) | ++------------------------+ +| 1.0 | ++------------------------+ +``` + +```sql +select cos(Pi()); +``` + +```text +-----------+ | cos(pi()) | +-----------+ | -1 | +-----------+ ``` - -### keywords - COS diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md index dad824eaaa75e..b37b050594832 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/floor.md @@ -22,66 +22,101 @@ specific language governing permissions and limitations under the License. --> -## floor +## Description -### description -#### Syntax +Round down floating-point and fixed-point decimals to a specific number of digits and return the rounded floating-point or fixed-point number. -`T floor(T x[, d])` +## Syntax -If not specified `d`: returns the largest integer value less than or equal to `x`, which is **the most common usage**. -Otherwise, returns the largest round number that is less than or equal to `x` and flowing the rules: +```sql +FLOOR([, ]) +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | Floating-point (Double) or fixed-point (Decimal) parameter indicating the parameter to be rounded | +| `` | Optional, integer, indicates rounding to the target number of digits, a positive number means rounding to the next decimal point, a negative number means rounding to the next decimal point, and `0` indicates rounding to an integer. When not filled, it is equivalent to ` = 0`. | + +## Return Value + +Returns the largest rounded number less than or equal to `` according to the following rules. + +Round to `1/(10^d)` digit, i.e., make the result divisible by `1/(10^d)`. If `1/(10^d)` is not exact, the rounding digit is the nearest number of the corresponding data type. -If `d` is specified as literal: -`d` = 0: just like without `d` -`d` > 0 or `d` < 0: the round number would be a multiple of `1/(10^d)`, or the nearest number of the appropriate data type if `1/(10^d)` isn't exact. +For an entry `` of type Decimal, assuming it is of type `Decimal(p, s)`, the return value is: -Else if `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +- `Decimal(p, 0)`,if ` <= 0` +- `Decimal(p, )`,if `0 < <= s` +- `Decimal(p, s)`,if ` > s` -:::tip -Another alias for this function is `dfloor`. -::: +## Alias -### example +- DFLOOR +## Examples + +```sql +select floor(123.456); +``` + +```text ++----------------+ +| floor(123.456) | ++----------------+ +| 123 | ++----------------+ ``` -mysql> select floor(1); -+------------+ -| floor(1.0) | -+------------+ -| 1 | -+------------+ -mysql> select floor(2.4); -+------------+ -| floor(2.4) | -+------------+ -| 2 | -+------------+ -mysql> select floor(-10.3); -+--------------+ -| floor(-10.3) | -+--------------+ -| -11 | -+--------------+ -mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); + +```sql +select floor(123.456, 2); +``` + +```text ++-------------------+ +| floor(123.456, 2) | ++-------------------+ +| 123.45 | ++-------------------+ +``` + +```sql +select floor(123.456, -2); +``` + +```text ++--------------------+ +| floor(123.456, -2) | ++--------------------+ +| 100 | ++--------------------+ +``` + +```sql +select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1); +``` + +```text +------------------+---------------+------------------+-------------------+ | floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) | +------------------+---------------+------------------+-------------------+ | 123.4 | 123 | 123 | 120 | +------------------+---------------+------------------+-------------------+ -mysql> SELECT number - -> , floor(number * 2.5, number - 1) AS f_decimal_column - -> , floor(number * 2.5, 0) AS f_decimal_literal - -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column - -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; -+--------+------------------+-------------------+-----------------+------------------+ -| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal | -+--------+------------------+-------------------+-----------------+------------------+ -| 1 | 2.0 | 2 | 2 | 2 | -+--------+------------------+-------------------+-----------------+------------------+ ``` -### keywords - FLOOR, DFLOOR +```sql +select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t; +``` + +```text ++-------------+ +| floor(x, 2) | ++-------------+ +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | +| 123.45 | ++-------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index d49a17b070b65..eb0e8807d5e84 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -22,36 +22,60 @@ specific language governing permissions and limitations under the License. --> -## sin +## Description -### description -#### Syntax +Calculate the sine of the parameter -`DOUBLE sin(DOUBLE x)` -Returns the sine of `x`, where `x` is in radians +## Syntax -### example +```sql +SIN() +``` + +## Parameters + +| Parameter | Description | +| -- | -- | +| `` | floating point number, the radian value of the parameter to calculate | + +## Return Value + +The sine of the parameter ``, expressed in radians. + +## Examples + +```sql +select sin(1); +``` + +```text ++------------------------+ +| sin(cast(1 as DOUBLE)) | ++------------------------+ +| 0.8414709848078965 | ++------------------------+ +``` +```sql +select sin(0); ``` -mysql> select sin(0); -+----------+ -| sin(0.0) | -+----------+ -| 0 | -+----------+ -mysql> select sin(1); -+--------------------+ -| sin(1.0) | -+--------------------+ -| 0.8414709848078965 | -+--------------------+ -mysql> select sin(0.5 * Pi()); -+-----------------+ -| sin(0.5 * pi()) | -+-----------------+ -| 1 | -+-----------------+ + +```text ++------------------------+ +| sin(cast(0 as DOUBLE)) | ++------------------------+ +| 0.0 | ++------------------------+ ``` -### keywords - SIN +```sql +select sin(Pi()); +``` + +```text ++------------------------------------+ +| sin(pi()) | ++------------------------------------+ +| 0.00000000000000012246467991473532 | ++------------------------------------+ +```