function in mysql xi ip
TRANSCRIPT
-
8/3/2019 Function in MySQL XI IP
1/11
Function in MySQL
-
8/3/2019 Function in MySQL XI IP
2/11
Functions are pre-written program
that perform their specific task
Function Type
Single RowFunction
NumericFunction
StringFunction
Date and TimeFunction
Multi rowfunction
Also Known asAggregate
function
-
8/3/2019 Function in MySQL XI IP
3/11
Single Row Function
It operate on single value and return single
value as output. It produce as many output as
there are inputs. When it applied on table it
return result for every row of the queried
table
-
8/3/2019 Function in MySQL XI IP
4/11
Multiple row function
It operates on a set of rows to return a single
value
** it will be discussed in detail in Class XII
-
8/3/2019 Function in MySQL XI IP
5/11
Numeric Function
1. POWER(x,y) Or POW(x,y)
It return the value of X raised to the power of
YExample : - Select pow(2,5);
output : - 32
Select pow(-2,4); output:- -16Select name,pow(salary,2) from emp
-
8/3/2019 Function in MySQL XI IP
6/11
2. ROUND(X,D) or ROUND(X)
Rounds the argument X to D decimal places
IF the number of decimal pale is not specified or is zero thenumber rounds to nearest integer
Examples :
a) Select round(-1.23) ; output: -1
b) Select round(-1.58); output: -2
c) Select round(1.43); output: 1
d) Select round(6.298,1); output: 6.3
e) Select round(6.235,0); output: 6
f) Select round(56.235,-1); output: -60
-
8/3/2019 Function in MySQL XI IP
7/11
3. TRUNCATE(X,D)
It truncate the number X to D decimal places. If D is 0, theresult has not decimal or fraction part. If D is negative itcauses D digits left of decimal point of the value X to become
zero
Examples:
Select truncate(7.543,1); output: 7.5
Select truncate(4.567,0); output 4
Select truncate(-7.45,1); output: -7.4Select truncate(346,-2); output: 300
Select name,dept,truncate(salary,0) from emp;
-
8/3/2019 Function in MySQL XI IP
8/11
String Function
1. LENGTH(STRING)
It return the length of string i.e. number of character in the given
string
Example:
Select length(computer); output: 8
select name,length(name) from emp;
2. CONCAT(string1,string2,)
it concatenate(join) give string and give output as single string
Example:
Select concat(Sun,Java,..Oracle); output: SunJava..Oracle
Select concat(name, works as a , designation ) from emp
-
8/3/2019 Function in MySQL XI IP
9/11
3. INSTR(str,substr)
it return the position of substring in the given string.
Example:
Select instr(computer,put); output: 4
select name,instr(name,ar) from emp;4. LOWER(string)
return the given string in small letter(lowercase)
Example:
select lower(COMPUTER); output: computer
5. UPPER(string)Example:
Select upper(computer); output: COMPUTER
Select upper(name) from emp;
-
8/3/2019 Function in MySQL XI IP
10/11
6. LEFT(string,n)
it return n number of character from the beginning of string.
Example:
Select left(computer,3); output: com
Select left(name,3);
7. RIGHT(string,n)
it return n number of character from the end of string
Example:
Select right(computer,3); output: ter
Select right(name,4) from emp;
-
8/3/2019 Function in MySQL XI IP
11/11
8. LTRIM(str)
it remove the leading space i.e. from the left side.
Example:
Select ltrim( computer);
9. RTRIM(str)
it remove the trailing spaces i.e. from the right side
Select rtrim(computer );
10. SUBSTRING(str,m,n) or MID(str,m,n)
it return portion of a string. It start from m position and return nnumber of character
Example:
Select substring(computer,4,3); output: put