7 SQL String Functionss
7 SQL String Functionss
String functions are used to perform an operation on input string and return an output
string. Following are the string functions defined in SQL:
Syntax:
SELECT ascii('t');
Output: 116
2. CHAR_LENGTH(): Doesn’t work for SQL Server. Use LEN() for SQL Server. This function
is used to find the length of a word.
3. CHARACTER_LENGTH(): Doesn’t work for SQL Server. Use LEN() for SQL Server. This
function is used to find the length of a line.
5. CONCAT_WS(): This function is used to add two words or strings with a symbol as
concatenating symbol.
Output: 2
Output: ‘98.10%’
9. LCASE(): This function is used to convert the given string into lower case.
10. LEFT(): This function is used to SELECT a sub string from the left of given size or
characters.
11. RIGHT(): This function is used to SELECT a sub string from the right end of the given
size.
Syntax: LENGTH('GeeksForGeeks');
Output: 13
13. LOCATE(): This function is used to find the nth position of the given word in a string.
14. LOWER(): This function is used to convert the upper case string into lower case.
15. LPAD(): This function is used to make the given string of the given size by adding the given
symbol.
16. RPAD(): This function is used to make the given string as long as the given size by adding the
given symbol on the right.
17. LTRIM(): This function is used to cut the given sub string from the original string.
19. REPEAT(): This function is used to write the given string again and again till the number
of times mentioned.
18. REPLACE(): This function is used to cut the given string by removing the given sub string.
21. RTRIM(): This function is used to cut the given sub string from the original string.
22. SPACE(): This function is used to write the given number of spaces.
If string1 and string2 are the same, the STRCMP function will return 0.
If string1 is smaller than string2, the STRCMP function will return -1.
Output: -1
24. SUBSTR(): This function is used to find a sub string from the a string from the given position.
Syntax:SUBSTR('geeksforgeeks', 1, 5);
Output: ‘geeks’
25. SUBSTRING(): This function is used to find an alphabet from the mentioned size and the
given string.
26. TRIM(): This function is used to cut the given symbol from the string.
27. UCASE(): This function is used to make the string in upper case.