String Functions Ip
String Functions Ip
i) String functions:
1. ASCII(str):
Returns numeric value of left-most character.
Returns 0 if str is the empty string.
Returns NULL if str is NULL.
ASCII() works for characters with numeric values from 0 to 255.
3. LENGTH(str)
4. CONCAT(str1,str2,...)
Returns the string that results from concatenating the arguments. May have
one or more arguments.
mysql> SELECT CONCAT('My', 'S', 'QL');
+---------------------------------------------------------+
| CONCAT('My', 'S', 'QL') |
+---------------------------------------------------------+
| MySQL |
+---------------------------------------------------------+
1 row in set (0.00 sec)
5. INSERT(str,pos,len,newstr)
Returns the string str, with the substring beginning at position pos and len
characters long replaced by the string newstr.
Returns the original string if pos is not within the length of the string.
Replaces the rest of the string from position pos if len is not within the length
of the rest of the string.
Returns NULL if any argument is NULL.
mysql> SELECT INSERT('Quadratic', 3, 10, 'What');
+---------------------------------------------------------+
| INSERT('Quadratic', 3, 10, 'What') |
+---------------------------------------------------------+
| QuWhat |
+---------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT INSERT('Quadratic', 3, 4, 'What');
+---------------------------------------------------------+
| INSERT('Quadratic', 3, 4, 'What') |
+---------------------------------------------------------+
| QuWhattic |
+---------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT INSERT('Quadratic', 3, 2, 'What');
+---------------------------------------------------------+
| INSERT('Quadratic', 3, 2, 'What') |
+---------------------------------------------------------+
| QuWhatratic |
+---------------------------------------------------------+
6. INSTR(str,substr)
Returns the position of the first occurrence of substring substr in string str.
7. LEFT(str,len)
Returns the leftmost len characters from the string str, or NULL if any
argument is NULL.
mysql> SELECT LEFT('foobarbar', 5);
+---------------------------------------------------------+
| LEFT('foobarbar', 5) |
+---------------------------------------------------------+
| fooba |
+---------------------------------------------------------+
1 row in set (0.00 sec)
8. LOWER(str)/ LCASE(str)
Returns the string str with all characters changed to lowercase according
to the current character set mapping.
mysql> SELECT LOWER('QUADRATICALLY');
+---------------------------------------------------------+
| LOWER('QUADRATICALLY') |
+---------------------------------------------------------+
| quadratically |
+---------------------------------------------------------+
1 row in set (0.00 sec)
9. LPAD(str,len,padstr)
Returns the string str, left-padded with the string padstr to a length of len
characters.
If str is longer than len, the return value is shortened to len characters.
mysql> SELECT LPAD('python',4,'??');
+---------------------------------------------------------+
| LPAD('python',4,'??') |
+---------------------------------------------------------+
| pyth |
+---------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT LPAD('hi',4,'??');
+---------------------------------------------------------+
| LPAD('hi',4,'??') |
+---------------------------------------------------------+
| ??hi |
+---------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT LPAD('h',4,'??');
+---------------------------------------------------------+
| LPAD('h',4,'??') |
+---------------------------------------------------------+
| ???h |
+---------------------------------------------------------+
1 row in set (0.00 sec)
10. LTRIM(str)
Returns the string str with leading space characters removed.
mysql> SELECT LTRIM(' barbar');
+---------------------------------------------------------+
| LTRIM(' barbar') |
+---------------------------------------------------------+
| barbar |
+---------------------------------------------------------+
1 row in set (0.00 sec)
11. REPEAT(str,count)
Returns a string consisting of the string str repeated count times. If count
is less than 1, returns an empty string. Returns NULL if str or count are
NULL.
mysql> SELECT REPEAT('MySQL', 3);
+---------------------------------------------------------+
| REPEAT('MySQL', 3) |
+---------------------------------------------------------+
| MySQLMySQLMySQL |
+---------------------------------------------------------+
1 row in set (0.00 sec)
12. REPLACE(str,from_str,to_str)
Returns the string str with all occurrences of the string from_str replaced
by the string to_str. REPLACE() performs a case-sensitive match when
searching for from_str.
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
+---------------------------------------------------------+
| REPLACE('www.mysql.com', 'w', 'Ww') |
+---------------------------------------------------------+
| WwWwWw.mysql.com |
+---------------------------------------------------------+
1 row in set (0.00 sec)
13. REVERSE(str)
Returns the string str with the order of the characters reversed.
mysql> SELECT REVERSE('abcd');
+---------------------------------------------------------+
| REVERSE('abcd') |
+---------------------------------------------------------+
| dcba |
+---------------------------------------------------------+
1 row in set (0.00 sec)
14. RIGHT(str,len)
Returns the rightmost len characters from the string str, or NULL if any
argument is NULL.
mysql> SELECT RIGHT('foobarbar', 4);
+---------------------------------------------------------+
| RIGHT('foobarbar', 4) |
+---------------------------------------------------------+
| rbar |
+---------------------------------------------------------+
1 row in set (0.00 sec)
15. RPAD(str,len,padstr)
Returns the string str, right-padded with the string padstr to a length of
len characters. If str is longer than len, the return value is shortened to len
characters.
mysql> SELECT RPAD('hi',5,'?');
+---------------------------------------------------------+
| RPAD('hi',5,'?') |
+---------------------------------------------------------+
| hi??? |
+---------------------------------------------------------+
1 row in set (0.00 sec)
16. RTRIM(str)
Returns the string str with trailing space characters removed.
mysql> SELECT RTRIM('barbar ');
+---------------------------------------------------------+
| RTRIM('barbar ') |
+---------------------------------------------------------+
| barbar |
+---------------------------------------------------------+
1 row in set (0.00 sec)
Returns the string str with all characters changed to uppercase according to the
current character set mapping.
mysql> SELECT UPPER('python');
+---------------------------------------------------------+
| UPPER('python') |
+---------------------------------------------------------+
| PYTHON |
+---------------------------------------------------------+
1 row in set (0.00 sec)