MySQL String Functions
ASCII and ORD Functions
mysql> SELECT ASCII('A');
+------------+
| ASCII('A') |
+------------+
|         65 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT ASCII('a');
+------------+
| ASCII('a') |
+------------+
|         97 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT ORD('A');
+----------+
| ORD('A') |
+----------+
|       65 |
+----------+
1 row in set (0.00 sec)

mysql> SELECT ORD('a');
+----------+
| ORD('a') |
+----------+
|       97 |
+----------+
1 row in set (0.00 sec)
LENGHT and CHAR_LENGTH Functions
mysql> SELECT LENGTH("Kodingwindow") AS Length;
+--------+
| Length |
+--------+
|     12 |
+--------+
1 row in set (0.00 sec)

mysql> SELECT CHAR_LENGTH("Kodingwindow") AS Length;
+--------+
| Length |
+--------+
|     12 |
+--------+
1 row in set (0.00 sec)
CONCAT Function
mysql> SELECT CONCAT("Koding","window") AS Concatenation;
+---------------+
| Concatenation |
+---------------+
| Kodingwindow  |
+---------------+
1 row in set (0.00 sec)

mysql> SELECT CONCAT("Koding","window"," Experiments") AS Concatenation;
+--------------------------+
| Concatenation            |
+--------------------------+
| Kodingwindow Experiments |
+--------------------------+
1 row in set (0.00 sec)
LCASE and UCASE Functions
mysql> SELECT LOWER("KoDiNgWiNdOw") AS Lowercase;
+--------------+
| Lowercase    |
+--------------+
| kodingwindow |
+--------------+
1 row in set (0.12 sec)

mysql> SELECT UPPER("Kodingwindow") AS Uppercase;
+--------------+
| Uppercase    |
+--------------+
| KODINGWINDOW |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT LCASE("KoDiNgWiNdOw") AS Lowercase;
+--------------+
| Lowercase    |
+--------------+
| kodingwindow |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT UCASE("Kodingwindow") AS Uppdercase;
+--------------+
| Uppdercase   |
+--------------+
| KODINGWINDOW |
+--------------+
1 row in set (0.00 sec)
LEFT and RIGHT Functions
mysql> SELECT LEFT("Kodingwindow",6) AS Extraction;
+------------+
| Extraction |
+------------+
| Koding     |
+------------+
1 row in set (0.00 sec)

mysql> SELECT RIGHT("Kodingwindow",6) AS Extraction;
+------------+
| Extraction |
+------------+
| window     |
+------------+
1 row in set (0.00 sec)
LOCATE and POSITION Functions
mysql> SELECT LOCATE("O","KODINGWINDOW") AS Locate;
+--------+
| Locate |
+--------+
|      2 |
+--------+
1 row in set (0.00 sec)

mysql> SELECT LOCATE("window","KODINGWINDOW") AS Locate;
+--------+
| Locate |
+--------+
|      7 |
+--------+
1 row in set (0.00 sec)

mysql> SELECT POSITION("O" IN "KODINGWINDOW") AS Position;
+----------+
| Position |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

mysql> SELECT POSITION("window" IN "KODINGWINDOW") AS Position;
+----------+
| Position |
+----------+
|        7 |
+----------+
1 row in set (0.00 sec)
SUBSTR and MID Functions
mysql> SELECT SUBSTR("Kodingwindow",7,12) AS Substring;
+-----------+
| Substring |
+-----------+
| window    |
+-----------+
1 row in set (0.00 sec)

mysql> SELECT SUBSTRING("Kodingwindow",7,12) AS Substring;
+-----------+
| Substring |
+-----------+
| window    |
+-----------+
1 row in set (0.00 sec)

mysql> SELECT MID("Kodingwindow",7,12) AS Substring;
+-----------+
| Substring |
+-----------+
| window    |
+-----------+
1 row in set (0.00 sec)
LTRIM, RTRIM, and TRIM Functions
mysql> SELECT LTRIM("  Kodingwindow   ") AS "Left Trim";
+-----------------+
| Left Trim       |
+-----------------+
| Kodingwindow    |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT RTRIM("  Kodingwindow   ") AS "Right Trim";
+----------------+
| Right Trim     |
+----------------+
|   Kodingwindow |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT TRIM("  Kodingwindow   ") AS "Trim";
+--------------+
| Trim         |
+--------------+
| Kodingwindow |
+--------------+
1 row in set (0.00 sec)
REPEAT, REPLACE, and REVERSE Functions
mysql> SELECT REPEAT(2,10) AS "Repeat";
+------------+
| Repeat     |
+------------+
| 2222222222 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT REPEAT("KW",5) AS "Repeat";
+------------+
| Repeat     |
+------------+
| KWKWKWKWKW |
+------------+
1 row in set (0.00 sec)

mysql> SELECT REPLACE("Kodingwindow","Koding","Learning") AS "Replace";
+----------------+
| Replace        |
+----------------+
| Learningwindow |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT REVERSE("Kodingwindow") AS "Reverse";
+--------------+
| Reverse      |
+--------------+
| wodniwgnidoK |
+--------------+
1 row in set (0.00 sec)
LPAD and RPAD Functions
mysql> SELECT LPAD("K",10,"W") AS "Left Padding";
+--------------+
| Left Padding |
+--------------+
| WWWWWWWWWK   |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT LPAD(152212,10,0) AS "Left Padding";
+--------------+
| Left Padding |
+--------------+
| 0000152212   |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT RPAD("K",10,"W") AS "Right Padding";
+---------------+
| Right Padding |
+---------------+
| KWWWWWWWWW    |
+---------------+
1 row in set (0.00 sec)

mysql> SELECT RPAD("K",10,"Z") AS "Right Padding";
+---------------+
| Right Padding |
+---------------+
| KZZZZZZZZZ    |
+---------------+
1 row in set (0.00 sec)
SPACE Function
mysql> SELECT SPACE(50);
+----------------------------------------------------+
| SPACE(50)                                          |
+----------------------------------------------------+
|                                                    |
+----------------------------------------------------+
1 row in set (0.00 sec)
FORMAT Function
mysql> SELECT FORMAT(15247892233,1);
+-----------------------+
| FORMAT(15247892233,1) |
+-----------------------+
| 15,247,892,233.0      |
+-----------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT(15247892233,2);
+-----------------------+
| FORMAT(15247892233,2) |
+-----------------------+
| 15,247,892,233.00     |
+-----------------------+
1 row in set (0.00 sec)
Advertisement