Skip to content

Commit 55cfb3d

Browse files
authored
add detail desc for String Function SUBSTRING_INDEX () and TO_BASE64 (#16449)
1 parent bfc0d60 commit 55cfb3d

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

functions-and-operators/string-functions.md

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,11 +1286,97 @@ Return the substring as specified.
12861286

12871287
### [`SUBSTRING_INDEX()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substring-index)
12881288

1289-
Return a substring from a string before the specified number of occurrences of the delimiter.
1289+
The `SUBSTRING_INDEX()` function is used to extract a substring from a string based on a specified delimiter and count. This function is particularly useful when dealing with data separated by a specific delimiter, such as parsing CSV data or processing log files.
1290+
1291+
Syntax:
1292+
1293+
```sql
1294+
SUBSTRING_INDEX(str, delim, count)
1295+
```
1296+
1297+
- `str`: specifies the string to be processed.
1298+
- `delim`: specifies the delimiter in the string, which is case-sensitive.
1299+
- `count`: specifies the number of occurrences of the delimiter.
1300+
- If `count` is a positive number, the function returns the substring before the `count` occurrences (counting from the left of the string) of the delimiter.
1301+
- If `count` is a negative number, the function returns the substring after the `count` occurrences (counting from the right of the string) of the delimiter.
1302+
- If `count` is `0`, the function returns an empty string.
1303+
1304+
Example 1:
1305+
1306+
```sql
1307+
SELECT SUBSTRING_INDEX('www.tidbcloud.com', '.', 2);
1308+
```
1309+
1310+
Result 1:
1311+
1312+
```sql
1313+
+-----------------------------------------+
1314+
| SUBSTRING_INDEX('www.tidbcloud.com', '.', 2) |
1315+
+-----------------------------------------+
1316+
| www.tidbcloud |
1317+
+-----------------------------------------+
1318+
```
1319+
1320+
Example 2:
1321+
1322+
```sql
1323+
SELECT SUBSTRING_INDEX('www.tidbcloud.com', '.', -1);
1324+
```
1325+
1326+
Result 2:
1327+
1328+
```sql
1329+
+------------------------------------------+
1330+
| SUBSTRING_INDEX('www.tidbcloud.com', '.', -1) |
1331+
+------------------------------------------+
1332+
| com |
1333+
+------------------------------------------+
1334+
```
12901335

12911336
### [`TO_BASE64()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_to-base64)
12921337

1293-
Return the argument converted to a base-64 string.
1338+
The `TO_BASE64()` function is used to convert the given argument to a string in the base-64 encoded form and return the result according to the character set and collation of the current connection. A base-64 encoded string can be decoded using the [`FROM_BASE64()`](#from_base64) function.
1339+
1340+
Syntax:
1341+
1342+
```sql
1343+
TO_BASE64(str)
1344+
```
1345+
1346+
- If the argument is not a string, the function converts it to a string before base-64 encoding.
1347+
- If the argument is `NULL`, the function returns `NULL`.
1348+
1349+
Example 1:
1350+
1351+
```sql
1352+
SELECT TO_BASE64('abc');
1353+
```
1354+
1355+
Result 1:
1356+
1357+
```sql
1358+
+------------------+
1359+
| TO_BASE64('abc') |
1360+
+------------------+
1361+
| YWJj |
1362+
+------------------+
1363+
```
1364+
1365+
Example 2:
1366+
1367+
```sql
1368+
SELECT TO_BASE64(6);
1369+
```
1370+
1371+
Result 2:
1372+
1373+
```sql
1374+
+--------------+
1375+
| TO_BASE64(6) |
1376+
+--------------+
1377+
| Ng== |
1378+
+--------------+
1379+
```
12941380

12951381
### [`TRANSLATE()`](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/TRANSLATE.html#GUID-80F85ACB-092C-4CC7-91F6-B3A585E3A690)
12961382

0 commit comments

Comments
 (0)