Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

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

You might also like