Professional Documents
Culture Documents
STRING FUNCTIONS: String functions are used to manipulate the text string in many ways.
Lower() / Lcase() This function returns the result in Select Lower(“KV1kpa”); /
lowercase (small letters) Select LCase(“KV1kpa”);
ANSWER:
kv1kpa
Upper() / Ucase() This function returns the result in UPPER Select Upper(“KV1kpa”); /
case (capital letters) Select UCase(“KV1kpa”);
ANSWER:
KV1KPA
Concat() This function returns the result after Select concat(“India”, “Bharat”);
concatenating two strings ANSWER:
IndiaBharat
Length() This function calculates the length of the Select Length(“Jai Hind!”);
string. ANSWER: 9
Char() This function returns the character for each Select Char(66,65,71);
integer passed.
NOTE: ASCII (American Standard Code for ANSWER:
Informaton Interchange) Eg. A=65,B=66 ..so BAG
on a= 97,b=98 ..so on
Rtrim() This function returns the result after Select Rtrim(“ India ”);
removing extra spaces from the trailing ANSWER:
end(right side). India
LTrim() This function returns the result after Select Ltrim(“ India ”);
removing extra spaces from the ANSWER:
beginning/start(left side). India
Trim() This function returns the result after Select Trim(“ India ”);
removing extra spaces from both ANSWER:
starting(left) and trailing end(right). India
Right() This function returns the extracted Select Right(“Bharat”, 2);
characters from right (trailing) side. ANSWER:
at
Left() This function returns the extracted Select Left(“Bharat”, 3);
characters from left (beginning) side. ANSWER:
Bha
Mid() / This function returns the substring (part) of Select mid(“Kendriya Vidyalaya,5,10);
a string Select Substr(“Kendriya Vidyalaya,5,10);
Substr() / REMEMBER: MID(“string”, starting Index Select Substring(“Kendriya
Substring() number, number of characters to be Vidyalaya,5,10);
extracted) ANSWER:
(All the above 3 NOTE: Index no. in MySQL for a string riya Vidya
starts from 1. Any thing written inside ‘ ’ or NOTE: Here, 5 is the starting index, 10 is
funstions are same) “ ” is the string. The output produced is the the no. of characters to be
substring. extracted(taken)
Instr() This function returns the index of the first Select instr(“Bharat”, “a”);
occurrence of substring ANSWER:
3
Replace () The REPLACE() function replaces all Select Replace(“India is great.”,
occurrences of a substring within a string, “India”,“Bharat”);
with a new substring. ANSWER:
Note: This function performs a case- Bharat is great.
sensitive replacement.
NUMERIC FUNCTIONS: The numeric functions are those functions that accept numeric values as input parameters
(arguments) and returns numeric values after execution of the query
Mod() Returns remainder of one expression by Select Mod(7,3);
dividing by another expression. Select 7%3;
Select 7 Mod 3 ;
% ANSWER: 1
Sqrt() Returns the non-negative square root of Select Sqrt(16);
numeric expression. ANSWER: 4
Pow() / Power() Returns the value of one expression raised Select Pow(3,2); /
to the power of another expression. Select Power(3,2);
ANSWER: 9
Sign() Returns the sign of a given number. Select Sign(15), Sign(-4), Sign(0);
(+ for positive number, - for negative ANSWER:
number, 0 for 0) +1 -1 0
Round() Returns numeric expression rounded to an
integer. It can be used to round an
QUERY ANSWER
expression to a number of decimal points.
Select round(54.279,1); 54.3
Select round(54.279,2); 54.28
Select round(54.279); 54
Select round(54.279,0); 54
Select round(54.679); 55
Select round(54.679,0); 55
Select round(54.279,-1); 50
Select round(324.279,-1); 320
Select round(354.279,-2); 300
Select round(754.279,-1); 750
Select round(754.279,-2); 800
TABLE: Dept
Primary Key of Dept Alternate Key
Candidate Key
TABLE: Emp
Primary Key of Emp Foreign Key of Emp