From c88bbc861c69af61e6b594708017cbad2c0eeb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Wed, 3 Apr 2024 14:22:43 +0200 Subject: [PATCH 1/6] Add example for OCT() --- functions-and-operators/string-functions.md | 45 ++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 6f2ebb9e7e88f..6deb059749925 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1241,11 +1241,52 @@ Negation of simple pattern matching. ### [`NOT REGEXP`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_not-regexp) -Negation of `REGEXP`. +Negation of [`REGEXP`](#regexp). ### [`OCT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_oct) -Return a string containing octal representation of a number. +Return a string containing octal (base 7) representation of a number. + +Examples: + +In the example below you can see that the decimal values 1 to 7 are identical to the octal numbers. The numbers 8 until 15 in decimal match with 10 to 17 octal. + +```sql +WITH RECURSIVE nr(n) AS ( + SELECT 1 AS n + UNION ALL + SELECT n+1 FROM nr WHERE n<20 +) +SELECT n, OCT(n) FROM nr; +``` + +``` ++------+--------+ +| n | OCT(n) | ++------+--------+ +| 1 | 1 | +| 2 | 2 | +| 3 | 3 | +| 4 | 4 | +| 5 | 5 | +| 6 | 6 | +| 7 | 7 | +| 8 | 10 | +| 9 | 11 | +| 10 | 12 | +| 11 | 13 | +| 12 | 14 | +| 13 | 15 | +| 14 | 16 | +| 15 | 17 | +| 16 | 20 | +| 17 | 21 | +| 18 | 22 | +| 19 | 23 | +| 20 | 24 | ++------+--------+ +20 rows in set (0.00 sec) +``` ### [`OCTET_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_octet-length) From fb405e4a39f80f7ba5ad1c010229176852714cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sun, 7 Apr 2024 10:49:34 +0200 Subject: [PATCH 2/6] Update functions-and-operators/string-functions.md Co-authored-by: Aolin --- functions-and-operators/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 6deb059749925..317cdc381d48b 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1249,7 +1249,7 @@ Return a string containing octal (base 7) representation of a number. Examples: -In the example below you can see that the decimal values 1 to 7 are identical to the octal numbers. The numbers 8 until 15 in decimal match with 10 to 17 octal. +The following example generates a sequence of numbers from 1 to 20 using a [recursive common table expression (CTE)](/develop/dev-guide-use-common-table-expression.md#recursive-cte) and then uses the `OCT()` function to convert each number to its octal representation. Decimal values from 1 to 7 have identical representations in octal. Decimal numbers from 8 to 15 correspond to octal numbers from 10 to 17. ```sql WITH RECURSIVE nr(n) AS ( From 1832d1978fb79a0879430fc10015eff2ba85d4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 8 Apr 2024 15:26:22 +0200 Subject: [PATCH 3/6] Update functions-and-operators/string-functions.md Co-authored-by: Mattias Jonsson --- functions-and-operators/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 317cdc381d48b..fa3e8d9682eb8 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1245,7 +1245,7 @@ Negation of [`REGEXP`](#regexp). ### [`OCT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_oct) -Return a string containing octal (base 7) representation of a number. +Return a string containing octal (base 8) representation of a number. Examples: From 3c5fd395396d8e253ddcdc0baa216a62b7b3972d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 8 Apr 2024 15:26:37 +0200 Subject: [PATCH 4/6] Update functions-and-operators/string-functions.md Co-authored-by: Mattias Jonsson --- functions-and-operators/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index fa3e8d9682eb8..f342b134c065e 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1249,7 +1249,7 @@ Return a string containing octal (base 8) representation of a number. Examples: -The following example generates a sequence of numbers from 1 to 20 using a [recursive common table expression (CTE)](/develop/dev-guide-use-common-table-expression.md#recursive-cte) and then uses the `OCT()` function to convert each number to its octal representation. Decimal values from 1 to 7 have identical representations in octal. Decimal numbers from 8 to 15 correspond to octal numbers from 10 to 17. +The following example generates a sequence of numbers from 1 to 20 using a [recursive common table expression (CTE)](/develop/dev-guide-use-common-table-expression.md#recursive-cte) and then uses the `OCT()` function to convert each number to its octal representation. Decimal values from 0 to 7 have identical representations in octal. Decimal numbers from 8 to 15 correspond to octal numbers from 10 to 17, and so on. ```sql WITH RECURSIVE nr(n) AS ( From 8fc8be902d2c50bdb7af353ab780fc84811ca3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 8 Apr 2024 15:44:25 +0200 Subject: [PATCH 5/6] Suggestions from code review --- functions-and-operators/string-functions.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index f342b134c065e..613c53957b5f1 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1245,7 +1245,7 @@ Negation of [`REGEXP`](#regexp). ### [`OCT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_oct) -Return a string containing octal (base 8) representation of a number. +Return a string containing [octal](https://en.wikipedia.org/wiki/Octal) (base 8) representation of a number. Examples: @@ -1253,7 +1253,7 @@ The following example generates a sequence of numbers from 1 to 20 using a [recu ```sql WITH RECURSIVE nr(n) AS ( - SELECT 1 AS n + SELECT 0 AS n UNION ALL SELECT n+1 FROM nr WHERE n<20 ) @@ -1264,6 +1264,7 @@ SELECT n, OCT(n) FROM nr; +------+--------+ | n | OCT(n) | +------+--------+ +| 0 | 0 | | 1 | 1 | | 2 | 2 | | 3 | 3 | From d5ddc27c3ea30fd616d033f6ec40b6effbc72c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 9 Apr 2024 09:58:47 +0200 Subject: [PATCH 6/6] Update functions-and-operators/string-functions.md Co-authored-by: Aolin --- functions-and-operators/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 613c53957b5f1..407a8e6e943cd 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1249,7 +1249,7 @@ Return a string containing [octal](https://en.wikipedia.org/wiki/Octal) (base 8) Examples: -The following example generates a sequence of numbers from 1 to 20 using a [recursive common table expression (CTE)](/develop/dev-guide-use-common-table-expression.md#recursive-cte) and then uses the `OCT()` function to convert each number to its octal representation. Decimal values from 0 to 7 have identical representations in octal. Decimal numbers from 8 to 15 correspond to octal numbers from 10 to 17, and so on. +The following example generates a sequence of numbers from 0 to 20 using a [recursive common table expression (CTE)](/develop/dev-guide-use-common-table-expression.md#recursive-cte) and then uses the `OCT()` function to convert each number to its octal representation. Decimal values from 0 to 7 have identical representations in octal. Decimal numbers from 8 to 15 correspond to octal numbers from 10 to 17. ```sql WITH RECURSIVE nr(n) AS (