You are on page 1of 7

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

UPPER(str):-
 UCASE() is a synonym for UPPER().
 Returns the string str with all characters changed to uppercase .

SELECT UPPER('Computer') 'COMPUTER'

SELECT upper('Informatic Practices') INFORMATIC PRACTICES

SELECT UCASE('Informatic Practices') INFORMATIC PRACTICES

Query Example:-

(i) Write SQL Query to display all names of employees in upper case from emp table.

LOWER(str)

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 1
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

 LCASE() is a synonym for LOWER().


 Returns the string str with all characters changed to lowercase

SELECT LOWER('Computer); 'computer'

SELECT lower(„INFORMATIC PRACTICES’) 'informatic practices'

SELECT LOWER(„INFORMATIC PRACTICES’) 'informatic practices'

Query Example:-

(i) Write SQL Query to display all names of employees in lower case from emp table.

 MID() is a synonym for SUBSTRING().


 SUBSTR() is a synonym for SUBSTRING().

This function can be used in 2 ways:-


(i) SUBSTRING(str,pos) OR SUBSTRING(str FROM pos):- return a substring from
string str starting at position pos.
(ii) SUBSTRING(str,pos,len) OR SUBSTRING(str FROM pos FOR len):- return a
substring len characters long from string str, starting at position pos.

 If negative value for pos. , the beginning of the substring is pos characters from the end
of the string, rather than the beginning.
 If len is less than 1, the result is the empty string.
 Extract substring always from left to right.
 Position starts from 1.

SELECT SUBSTRING('Quadratically',1); 'Quadratically'


SELECT SUBSTRING('Quadratically',5); 'ratically'
SELECT SUBSTRING('Quadratically',15); empty string

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 2
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

SELECT SUBSTRING('foobarbar' FROM 4); 'barbar'


SELECT SUBSTRING('Quadratically',5,6); 'ratica'
SELECT SUBSTRING('Quadratically',5,0); empty string
SELECT SUBSTRING('Quadratically',5,-5); empty string
SELECT SUBSTRING('Sakila', -3); 'ila'
SELECT SUBSTRING('Sakila', -5, 3); 'aki'
SELECT SUBSTRING('Sakila' FROM -4 FOR 2); 'ki'
Query Example 1:- display last 4 character of employees name from emp table.

Query Example 1:- display first 5 character of empoyees name from emp table.

LENGTH(str)
Returns the length of the string str, measured in bytes.
SELECT LENGTH('text'); 4
SELECT length('computer'); 8
SELECT length('informatic practices'); 20
Query Example 1:- display number of digit of salary for each employee from emp table.

LEFT(str,len)
Returns the leftmost len characters from the string str.

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 3
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

SELECT LEFT('foobarbar', 5); 'fooba'


SELECT left('informatic practices',6); inform
SELECT left('informatic practices',0); Empty string
SELECT left('informatic practices',-2); Empty string
SELECT left('informatic practices',56); 'informatic practices'
Query Example 1:- display first 5 character of employees name from emp table.

RIGHT(str,len)
 Returns the rightmost len characters from the string str.
 Character extract from left to right always

SELECT RIGHT('foobarbar', 4); 'rbar'


SELECT right('informatic practices',6); 'ctices'
SELECT right('informatic practices',0); Empty string
SELECT right('informatic practices',-2); Empty string
SELECT right('informatic practices',56); 'informatic practices'
Query Example 1:- display last 4 character of employees name from emp table.

INSTR(str,substr)

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 4
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

 Returns the position of the first occurrence of substring substr in string str.
 Returns 0 if substring substr is not found in str.
 It is not case sensitive.

SELECT INSTR('foobarbar', 'bar'); 4


SELECT INSTR('xbar', 'foobar'); 0
SELECT instr('informatic practices',‟or‟); 4
SELECT instr('informatic practices',‟t‟); 8
SELECT instr('informatic practices',‟comp‟); 0
Query Example 1:- display name of employees who have “mit” anywhere in their name from emp table.

LTRIM(str)
Returns the string str with leading space characters removed.
SELECT LTRIM(' barbar'); 'barbar'
SELECT ltrim(' informatic practices'); 'informatic practices'
Query Example 1:- display name of employees by removing any leading space in their name from emp table.

RTRIM(str)
Returns the string str with trailing space characters removed.

SELECT RTRIM('barbar '); 'barbar'


SELECT rtrim(' informatic practices '); ' informatic practices'

Query Example 1:- display name of employees by removing any trailing space in their name from emp table.

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 5
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)


TRIM(remstr FROM] str)

Returns the string str with all remstr prefixes or suffixes removed. If none of the
specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not
specified, spaces are removed.
 it is Case Sensitive

SELECT TRIM(' bar '); 'bar'

SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx'); 'barxxx'

SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx'); 'bar'

SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz'); 'barx'

SELECT trim(“i” from 'iiinformatic practicesiiii'); 'nformatic practices'


SELECT trim(“I” from 'iiinformatic practicesiiii'); 'iiinformatic practicesiiii'
SELECT trim(“xyz” from 'xyziformatic practicesiiiixxyz'); 'iformatic practicesiiiix'
Query Example 1:- display name of employees by removing “a” from any Leading or trailing in their name from emp table.

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 6
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

ASCII(str) Returns the numeric value of the leftmost character of the string str.

mysql> SELECT ASCII('2'); -> 50


mysql> SELECT ASCII(2); -> 50
mysql> SELECT ASCII('dx'); -> 100

CHAR(str) returns a string consisting of the characters given by the code values of
those integers.

mysql> SELECT CHAR(77,121,83,81,'76'); -> 'MySQL'


mysql> SELECT CHAR(77,77.3,'77.3'); -> 'MMM'

CONCAT(str1,str Returns the string that results from concatenating the arguments.
2,...) mysql> SELECT CONCAT('My', 'S', 'QL'); -> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL'); -> NULL
mysql> SELECT CONCAT(14.3); -> '14.3'

INSERT(str,pos, Returns the string str, with the substring beginning at


len,newstr) position pos and len characters long replaced by the string newstr.

mysql> SELECT INSERT('Quadratic', 3, 4, 'What');-> 'QuWhattic'


mysql> SELECT INSERT('Quadratic', 3, 100, 'What'); -> 'QuWhat'

REPEAT(str,coun Returns a string consisting of the string str repeated count times.
t)
mysql> SELECT REPEAT('MySQL', 3); -> 'MySQLMySQLMySQL'

REVERSE(str) Returns the string str with the order of the characters reversed.

mysql> SELECT REVERSE('abc'); -> 'cba'

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 7

You might also like