0% found this document useful (0 votes)
10 views

Document 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Document 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

AGGREGATE FUNCTIONS

Create a sample table and insert some values in it


Consider the following table
SQL> create table sample (id integer, name char (20), salary char (20));
Table created.
SQL> insert into sample values(1,'danny',80000);
1 row created.
SQL> insert into sample values(2,'farhan',750000);
1 row created.
SQL> insert into sample values(3,'john',40000);
1 row created.
SQL> insert into sample values(4,'bubbly',80000);
1 row created.
SQL> insert into sample values(5,'siri',25000);
1 row created.
SQL> select * from sample;
ID NAME SALARY
---------- -------------------- --------------------
1 danny 80000
2 farhan 750000
3 john 40000
4 bubbly 80000
5 siri 25000
MIN:
SYNTAX : select min (col-name) from table-name;
SQL> select min(salary) from sample;
MIN(SALARY)
-------------------
25000
MAX:
SYNTAX: select max (col-name) from table-name;
SQL> select max(salary) from sample;
MAX(SALARY)
--------------------
750000
SUM:
SYNTAX: select sum (col-name) from table-name;
SQL> select sum(salary) from sample;
SUM(SALARY)
-----------
975000
AVERAGE:
SYNTAX: select avg (col-name) from table-name;
SQL> select avg(salary) from sample;
AVG(SALARY)
-----------
195000

COUNT:
SYNTAX: select count (col-name) from table-name;
SQL> select count(salary) from sample;
COUNT(SALARY)
-------------
5
STANDARD DEVEATION:
SYNTAX: select stddev (col-name) from table-name;
SQL> select stddev(salary) from sample;
STDDEV(SALARY)
--------------
311207.326

STRING FUNCTIONS (dual)


ASCII:
SYNTAX: select asci(‘char’) from dual;
SQL> select ascii('A') from dual;
ASCII('A')
----------
65
CHAR:
SYNTAX: select char(‘char’) from dual;
SQL> select chr(65) from dual;
C
-
A
CONCATENATION:
SYNTAX: select concat(‘char1’,’char2’) from dual;
SQL> select concat ('a','b') from dual;
CO
--
ab
INITCAP:
SYNTAX: select initcap(‘char’) from dual;
SQL> select initcap('apple') from dual;
INITC
-----
Apple
INSTR:
SYNTAX: select instr(‘char’) from dual;
SQL> select instr('apple is a fruit','e') from dual;
INSTR('APPLEISAFRUIT','E')
--------------------------
5
LENGTH:
SYNTAX: select length(‘char’) from dual;
SQL> select length('apple') from dual;
LENGTH('APPLE')
---------------
5
LOWER:
SYNTAX: select lower(‘char’) from dual;
SQL> select lower('APPLE') from dual;
LOWER
-----
apple
UPPER:
SYNTAX: select upper(‘char’) from dual;
SQL> select upper('apple') from dual;
UPPER
-----
APPLE
LPAD:
SYNTAX: select lpad(‘char’) from dual;
SQL> select lpad('apple',10,'o') from dual;
LPAD (
'APPL
----------
oooooapple
RPAD:
SYNTAX: select rpad(‘char’) from dual;

SQL> select rpad('apple',10,'o') from dual;


RPAD ('APPL
----------
appleooooo
LTRIM:
SYNTAX: select ltrim(‘char’) from dual;
SQL> select ltrim('ooooooapple','o') from dual;

LTRIM
-----
apple
RTRIM:
SYNTAX: select rtrim(‘char’) from dual;
SQL> select rtrim('appleooooo','o') from dual;
RTRIM
-----
apple
REPLACE:
SYNTAX: select replace(‘char’, oldno, newno) from dual;
SQL> select replace('123apple12',23,45) from dual;
REPLACE ('1
----------
145apple12
TRANSLATE:
SYNTAX: select translate (‘char’, oldno, newno) from dual;
SQL> select translate('123apple12',23,45) from dual;

TRANSLATE (
----------
145apple14
VSIZE:
SYNTAX: select vsize(‘char’) from dual;
SQL> select vize('apple is a fruit') from dual;
VSIZE('APPLEISAFRUIT')
----------------------
16
SUBSTR:
SYNTAX: select substr(‘char', index) from dual;
SQL> select substr('apple is a fruit',5) from dual;
SUBSTR ('APPL
------------
e is a fruit

MATHEMATICAL/NUMERICAL FUNCTIONS
ABSOLUTE:
It gives the absolute value I.e., without any signs
SQL> select abs (-23.65) from dual;
ABS (-23.65)
-----------
23.65
LEAST:
It returns the least value among them
SQL> select least (2,5,3,7,1) from dual;
LEAST (2,5,3,7,1)
----------------
1
GREATEST:
It returns the greatest value among them

SQL> select greatest (2,5,3,7,1) from dual;


GREATEST (2,5,3,7,1)
-------------------
7
CEIL:
It returns the ceil value I.e., gives the upper value

SQL> select ceil (32.56) from dual;


CEIL (32.56)
-----------
33
FLOOR:
It returns the floor value I.e., gives the lower value
SQL> select floor (32.56) from dual;
FLOOR (32.56)
------------
32
MOD:
It returns the modulus values I.e., 15%4 =3 which is basically
remainder
SQL> select mod (15,4) from dual;
MOD (15,4)
----------
3
SQRT:
It returns the square root value
SQL> select sqrt (49) from dual;
SQRT (49)
----------
7
POWER:
It returns the power of the given values
SQL> select power (5,2) from dual;
POWER (5,2)
----------
25
SIGN:
It returns the sign of the value
SQL> select sign (-65) from dual;
SIGN (-65)
----------
-1
SQL> select sign (65) from dual;
SIGN (65)
----------
1
LOG:
It gives the logarithmic values of the given num
SQL> select log (10,2) from dual;
LOG (10,2)
----------
.301029996
EXP:
It gives the exponential values of the given num
SQL> select exp (2) from dual;
EXP (2)
----------
7.3890561
BINARY TO DECIMAL:
It converts the binary value to decimal value
SQL> select bin_to_num(1,0,1,0) from dual;
BIN_TO_NUM (1,0,1,0)
-------------------
10
ROUND:
If in 0.x x is greater than 5 it returns 0+1 or it returns 0
SQL> select round (35.86) from dual;
ROUND (35.86)
------------
36
SQL> select round (35.43) from dual;
ROUND (35.43)
------------
35
SQL> select round (145.289,2) from dual;
ROUND (145.289,2)
----------------
145.29
TRUNCATE:
It returns only the integer part
SQL> select trunc (35.86) from dual;
TRUNC (35.86)
------------
35
SQL> select trunc (35.43) from dual;
TRUNC (35.43)
------------
35
SQL> select trunc (35.86, -1) from dual;
TRUNC (35.86,-1)
---------------
30
TRIGNOMETRIC:
SQL> select sin (90) from dual;
SIN (90)
----------
.893996664
DATE FUNCTIONS

You might also like