Professional Documents
Culture Documents
character function:
sql> select ename,lower(ename),upper(ename),initcap(ename),instr(ename,'a'),
concat(ename,job),
concat command:
sql> select ename,concat(ename,concat(',',job)) from emp where deptno=10;
ename concat(ename,concat(
---------- --------------------
clark clark,manager
king king,president
miller miller,clerk
ename||','||job
-----------------------
clark,manager
king,president
miller,clerk
fetching string:
sql> select ename,substr(ename,2,3),substr(ename,2) from emp where deptno=10;
'kg'
----
kg
length('kg')
------------
6
length from left, right and center:
sql> select length(ltrim(' kg ')),length(rtrim(' kg ')),length(trim(' kg ')) from dual;
ename sub
----------- ------
ward ard
martin art
james ame
ename replace(en
------------ ---------------------
clark clark
king king
miller miller
number function:
round command:
sql> select abs(-90),round(123.361,0),round(123.361),round(123.361,1),
round(123.361,2),round(123.361,-1),
2 round(123.36,-2) from dual;
truncate command:
sysdate
---------------
07-feb-07
sql> select to_char(sysdate,'dd dy day ddd mm mon month year yyyy rr yy hh24:mi:ss') from
dual;
hiredate to_char(hireda
--------- --------------
09-jun-81 tuesday 1981
17-nov-81 tuesday 1981
23-jan-82 saturday 1982
hiredate to_char(sysdate-hiredate)/365
--------- -----------------------------
09-jun-81 25.686355
17-nov-81 25.2452591
23-jan-82 25.0616974
hiredate to_char(hireda
--------- --------------
01-may-81 friday 1981
20-feb-81 friday 1981
to_date('
---------
15-aug-47
to_char(t
---------
friday
table created.
1 row created.
doj to_c
--------- ----
19-jan-90 1990
19-jan-90 1890
doj to
--------- --
19-jan-90 90
19-jan-90 90
doj to
--------- --
19-jan-90 90
19-jan-90 90
---------------------------------------------------------
to_char(t
---------
15-aug-47
hiredate months_between(sysdate,hiredate)
---------------- ------------------------------------------------------------------
09-jun-81 307.981282
17-nov-81 302.723218
23-jan-82 300.52967
hiredate months_between(sysdate,hiredate)/12
---------------- ----------------------------------------------------------------------
09-jun-81 25.6651132
17-nov-81 25.2269411
23-jan-82 25.0441454
sysdate add_month
--------------- ---------------------
08-feb-07 08-jun-08
group function:
salary:
commision:
count(hiredate)
---------------
14
for counting :
group
sum(sal)
----------
8750
10875
9400
=> which columns are used in the group clause,that columns must be used in the select part.
12 rows selected.
14 rows selected.
nvl2:
14 rows selected.
nullif:
14 rows selected.
update commision:
3 rows updated.
distinct:
comm deptno
---------- ----------
0 30
300 30
500 10
500 30
1400 30
5000 10
20
30
8 rows selected.
without distinct:
comm deptno
---------- ----------
5000 10
30
500 10
20
1400 30
300 30
0 30
30
500 30
20
20
20
20
500 10
14 rows selected.
decode:
sal decode(sal,5000,sal*5,3000,sal*4,sal)
---------- -------------------------------------
5000 25000
2850 2850
2450 2450
2975 2975
1250 1250
1600 1600
1500 1500
950 950
1250 1250
3000 12000
800 800
3000 12000
1100 1100
1300 1300
14 rows selected.
case:
sql> select sal,case when sal=5000 then sal*5 when sal=3000 then sal*4 else sal end from emp;
sal casewhensal=5000thensal*5whensal=3000thensal*4elsesalend
---------- --------------------------------------------------------
5000 25000
2850 2850
2450 2450
2975 2975
1250 1250
1600 1600
1500 1500
950 950
1250 1250
3000 12000
800 800
3000 12000
1100 1100
1300 1300
14 rows selected.