Functions in SQL
Functions in SQL
sunil kadam
String functions
Right (str,n) : returns the righttmost ‘n’ characters
from the string
Eg select right(‘narsee monjee’, 4);
njee
Substring(str,m,n): returns a string of ‘n’ char long
from given string starting from ‘m’ position.
E.g select substring(‘narsee monjee college’,4,6)
see mo
String functions
LTRIM(str) : returns the leading (starting ) blank
spaces removed.
Eg. select Ltrim(‘bbbbnarsee’);
narsee
RTRIM(str) : returns the trailing (ending ) blank
spaces removed.
Eg. select Rtrim(‘narseebbbb);
narsee
String functions
TRIM(str) :returns the string with all blank stirng
prefixes and suffixes removed.
Eg. select trim(‘bbbbnarseebbbb);
narsee
String functions
Lpad (str,n,padstr) : returns the string ,left padded with
the pad string until string is ‘n’ char long.
Eg select lpad(‘hi’,6,’!’);
!!!!hi
Eg select lpad(100,7,’$’);
$$$$100
If string is longer than ‘n’ then it will be shortened to n
char
Select lpad (‘It is mysql ‘ ,8 , ’#’);
It is my
String functions
Rpad(str,n,padstr): returns the string ,right padded
with the pad string until string is ‘n’ char long.
Eg select rpad(‘hi’,6,’*’);
Hi****
Eg select rpad(100,7,’$’);
100$$$$
String functions
Length (str): returns the length of a string,
Eg select length(‘narsee monjee’);
13
Reverse (str) returns string in the reverse order
Eg select reverse(‘college’);
egelloc
String functions
Repeat (str,n): returns a string containing repeated ‘n’
times
Eg select repeat(‘@’,10);
@@@@@@@@@@
Numeric functions