Skip to content

Commit eb1c68b

Browse files
authored
Add example for OCT() (#16959)
1 parent f8f1dc2 commit eb1c68b

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

functions-and-operators/string-functions.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,53 @@ Negation of simple pattern matching.
12421242

12431243
### [`NOT REGEXP`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_not-regexp)
12441244

1245-
Negation of `REGEXP`.
1245+
Negation of [`REGEXP`](#regexp).
12461246

12471247
### [`OCT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_oct)
12481248

1249-
Return a string containing octal representation of a number.
1249+
Return a string containing [octal](https://en.wikipedia.org/wiki/Octal) (base 8) representation of a number.
1250+
1251+
Examples:
1252+
1253+
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.
1254+
1255+
```sql
1256+
WITH RECURSIVE nr(n) AS (
1257+
SELECT 0 AS n
1258+
UNION ALL
1259+
SELECT n+1 FROM nr WHERE n<20
1260+
)
1261+
SELECT n, OCT(n) FROM nr;
1262+
```
1263+
1264+
```
1265+
+------+--------+
1266+
| n | OCT(n) |
1267+
+------+--------+
1268+
| 0 | 0 |
1269+
| 1 | 1 |
1270+
| 2 | 2 |
1271+
| 3 | 3 |
1272+
| 4 | 4 |
1273+
| 5 | 5 |
1274+
| 6 | 6 |
1275+
| 7 | 7 |
1276+
| 8 | 10 |
1277+
| 9 | 11 |
1278+
| 10 | 12 |
1279+
| 11 | 13 |
1280+
| 12 | 14 |
1281+
| 13 | 15 |
1282+
| 14 | 16 |
1283+
| 15 | 17 |
1284+
| 16 | 20 |
1285+
| 17 | 21 |
1286+
| 18 | 22 |
1287+
| 19 | 23 |
1288+
| 20 | 24 |
1289+
+------+--------+
1290+
20 rows in set (0.00 sec)
1291+
```
12501292

12511293
### [`OCTET_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_octet-length)
12521294

0 commit comments

Comments
 (0)