SQL for Beginers
-
Upload
pasupuleti-veera -
Category
Documents
-
view
252 -
download
1
Transcript of SQL for Beginers
-
8/18/2019 SQL for Beginers
1/278
INTRODUCTION
SQL is divided into the following
Data Definition Language (DDL)
Data Manipulation Language (DML)
Data Retieval Language (DRL)
Tansa!tion Contol Language (TCL)
Data Contol Language (DCL)
DDL "" !eate# alte# dop# tun!ate# ena$e
DML "" inset# update# delete
DRL "" sele!t
TCL "" !o$$it# oll%a! savepoint
DCL "" gant# evo&e
CR'T' TL' S*NT+
Ceate ta%le ,table_name- (col1 datatype1, col2 datatype2 …coln datatypen).
'/0
SQL- !eate ta%le student (no nu$%e (1)# na$e va!ha (23)# $a&s nu$%e (4)).
INS'RT
This will %e used to inset the e!ods into ta%le5
6e have two $ethods to inset5
7 value $ethod
7 addess $ethod
a) USIN8 9LU' M'T:OD
S7nta/0
inset into ,table_name) values (value1, value2, value3 …. Valuen).
'/0SQL- inset into student values (2# ;sudha;# 233).
SQL- inset into student values (1# ;sað# 133).
To inset a new e!od again 7ou have to t7pe entie inset !o$$and# if thee ae lot of
e!ods this will %e diffi!ult5 This will %e avoided %7 using addess $ethod5
1
-
8/18/2019 SQL for Beginers
2/278
%) USIN8 DDR'SS M'T:OD
S7nta/0
inset into ,table_name) values (&col1, &col2, &col3 …. &coln).
This will po$pt 7ou fo the values %ut fo eve7 inset 7ou have to use fowad slash5
'/0
SQL- inset into student values (agan
'nte value fo $a&s0 433
old 20 inset into student values(
-
8/18/2019 SQL for Beginers
3/278
SQL- inset into student (no# na$e) values (
-
8/18/2019 SQL for Beginers
4/278
SQL- sele!t no# na$e# $a&s fo$ student.
NO NM' MRFS
""" """""" """"""""
2 Sudha 233
1 Sað 133
2 >agan 433
1 Naen @33
4 Ra$esh
@ Madhu
9isu
Rattu
SQL- sele!t no# na$e fo$ student.
NO NM'
""" """""""
2 Sudha
1 Sað
2 >agan
1 Naen
4 Ra$esh @ Madhu
9isu
Rattu
4
-
8/18/2019 SQL for Beginers
5/278
CONDITIONL S'L'CTIONS ND OA'RTORS
6e have two !lauses used in this
6hee
Ode %7
USIN8 6:'R'
S7nta/0
sele!t E fo$ ,table_name- whee ,condition-.
the following ae the diffeent t7pes of opeatos used in whee !lause5
ith$eti! opeatos
Co$paison opeatos
Logi!al opeatos
ith$eti! opeatos "" highest pe!eden!e
G# "# E# ?
Co$paison opeatos
H# H# -# ,# -H# ,H# ,-
%etween# not %etween
in# not in
null# not null
li&e
Logi!al opeatos
nd
O "" lowest pe!eden!e
not
a) USIN8 H# -# ,# -H# ,H# H# ,-
'/0
SQL- sele!t E fo$ student whee no H 1.
NO NM' MRFS
5
-
8/18/2019 SQL for Beginers
6/278
""" """"""" """""""""
1 Sað 133
1 Naen @33
SQL- sele!t E fo$ student whee no , 1.
NO NM' MRFS
""" """"""" """"""""""
2 Sudha 233
2 >agan 433
SQL- sele!t E fo$ student whee no - 1.
NO NM' MRFS
""" """"""" """"""""""
4 Ra$esh
@ Madhu
9isu
Rattu
SQL- sele!t E fo$ student whee no ,H 1.
NO NM' MRFS
""" """"""" """"""""""
2 Sudha 233
1 Sað 133
2 >agan 433
1 Naen @33
SQL- sele!t E fo$ student whee no -H 1.
NO NM' MRFS
""" """"""" """""""""
1 Sað 133
1 Naen @33
4 Ra$esh
6
-
8/18/2019 SQL for Beginers
7/278
@ Madhu
9isu
Rattu
SQL- sele!t E fo$ student whee no H 1.
NO NM' MRFS
""" """"""" """"""""""
2 Sudha 233
2 >agan 433
4 Ra$esh
@ Madhu
9isu
Rattu
SQL- sele!t E fo$ student whee no ,- 1.
NO NM' MRFS
""" """"""" """"""""""
2 Sudha 233
2 >agan 433
4 Ra$esh
@ Madhu
9isu Rattu
%) USIN8 ND
This will gives the output when all the !onditions %e!o$e tue5
S7nta/0
sele!t E fo$ ,table_name- whee ,condition1- and ,condition2- and 55
,conditionn-.
'/0
SQL- sele!t E fo$ student whee no H 1 and $a&s -H 133.
NO NM' MRFS
""" """"""" """"""""
7
-
8/18/2019 SQL for Beginers
8/278
-
8/18/2019 SQL for Beginers
9/278
1 Naen @33
e) USIN8 NOT 'T6''N
This will gives the output %ased on the !olu$n whi!h values ae not in its lowe
%ound#uppe%ound5
S7nta/0
sele!t E fo$ ,table_name- whee ,col - not %etween ,lower bound - and ,upper
bound -.
'/0
SQL- sele!t E fo$ student whee $a&s not %etween 133 and @33.
NO NM' MRFS
""" """"""" """""""""
2 Sudha 233
f) USIN8 IN
This will gives the output %ased on the !olu$n and its list of values spe!ified5
S7nta/0
sele!t E fo$ ,table_name- whee ,col - in ( value1, value2, value3 … valuen).
'/0
SQL- sele!t E fo$ student whee no in (2# 1# 4).
NO NM' MRFS
""" """"""" """""""""
2 Sudha 233
1 Sað 133
2 >agan 433 1 Naen @33
4 Ra$esh
9
-
8/18/2019 SQL for Beginers
10/278
g) USIN8 NOT IN
This will gives the output %ased on the !olu$n whi!h values ae not in the list of
values
spe!ified5
S7nta/0
sele!t E fo$ ,table_name- whee ,col - not in ( value1, value2, value3 …
valuen).
'/0
SQL- sele!t E fo$ student whee no not in (2# 1# 4).
NO NM' MRFS
""" """"""" """""""""
@ Madhu
9isu
Rattu
h) USIN8 NULL
This will gives the output %ased on the null values in the spe!ified !olu$n5
S7nta/0
sele!t E fo$ ,table_name- whee ,col - is null.
'/0 SQL- sele!t E fo$ student whee $a&s is null.
NO NM' MRFS
""" """"""" """""""""
4 Ra$esh
10
-
8/18/2019 SQL for Beginers
11/278
@ Madhu
9isu
Rattu
i) USIN8 NOT NULL
This will gives the output %ased on the not null values in the spe!ified !olu$n5
S7nta/0
sele!t E fo$ ,table_name- whee ,col - is not null.
'/0
SQL- sele!t E fo$ student whee $a&s is not null.
NO NM' MRFS
""" """"""" """""""""
2 Sudha 233
1 Sað 133
2 >agan 433
1 Naen @33
J) USIN8 LIF'
This will %e used to sea!h though the ows of data%ase !olu$n %ased on the patten
7ou spe!if75
S7nta/0
sele!t E fo$ ,table_name- whee ,col - li&e , pattern-.
'/0
i) This will give the ows whose $a&s ae 2335
SQL- sele!t E fo$ student whee $a&s li&e 233.
NO NM' MRFS
""" """"""" """""""""
11
-
8/18/2019 SQL for Beginers
12/278
2 Sudha 233
ii) This will give the ows whose na$e stat with KS;5
SQL- sele!t E fo$ student whee na$e li&e =S=.
NO NM' MRFS
""" """"""" """""""""
2 Sudha 233
1 Sað 133
iii) This will give the ows whose na$e ends with Kh;5
SQL- sele!t E fo$ student whee na$e li&e =h=.
NO NM' MRFS
""" """"""" """""""""
1 Sað 133
4 Ra$esh
i9) This will give the ows whose na$e;s se!ond lette stat with Ka;5
SQL- sele!t E fo$ student whee na$e li&e =a=.
NO NM' MRFS
""" """"""" """"""""
1 Sað 133
2 >agan 433
1 Naen @33
4 Ra$esh
@ Madhu
Rattu
9) This will give the ows whose na$e;s thid lette stat with Kd;5
SQL- sele!t E fo$ student whee na$e li&e =d=.
NO NM' MRFS
12
-
8/18/2019 SQL for Beginers
13/278
""" """"""" """""""""
2 Sudha 233
@ Madhu
9i) This will give the ows whose na$e;s se!ond lette stat with Kt; fo$ ending5
SQL- sele!t E fo$ student whee na$e li&e =t=.
NO NM' MRFS
""" """"""" """""""""
1 Sað 133
Rattu
9ii) This will give the ows whose na$e;s thid lette stat with Ke; fo$ ending5
SQL- sele!t E fo$ student whee na$e li&e =e=.
NO NM' MRFS
""" """"""" """""""""
1 Sað 133
4 Ra$esh
9iii) This will give the ows whose na$e !otains 1 a;s5
SQL- sele!t E fo$ student whee na$e li&e =a a =.
NO NM' MRFS
""" """"""" """"""""""
2 >agan 433
E *ou have to spe!if7 the pattens in like using undes!oe ( )5
13
-
8/18/2019 SQL for Beginers
14/278
USIN8 ORD'R *
This will %e used to odeing the !olu$ns data (as!ending o des!ending)5
S7nta/0
Sele!t E fo$ ,table_name- ode %7 ,col - des!.
7 default oa!le will use as!ending ode5
If 7ou want output in des!ending ode 7ou have to use desc &e7wod afte the !olu$n5
'/0
SQL- sele!t E fo$ student ode %7 no.
NO NM' MRFS
""" """"""" """""""""
2 Sudha 233
2 >agan 433
1 Sað 133
1 Naen @33
4 Ra$esh
@ Madhu
9isu
Rattu
SQL- sele!t E fo$ student ode %7 no des!.
NO NM' MRFS
""" """"""" """"""""" Rattu
9isu
@ Madhu
4 Ra$esh
1 Sað 133
14
-
8/18/2019 SQL for Beginers
15/278
1 Naen @33
2 Sudha 233
2 >agan 433
USIN8 DML
USIN8 UADT'
This !an %e used to $odif7 the ta%le data5
S7nta/0
Update ,table_name- set ,col1- H value2# ,col2- H value1 whee ,condition-.
'/0
SQL- update student set $a&s H 33.
If 7ou ae not spe!if7ing an7 !ondition this will update entie ta%le5
SQL- update student set $a&s H 33 whee no H 1.
SQL- update student set $a&s H 33# na$e H =9enu= whee no H 2.
USIN8 D'L'T'
This !an %e used to delete the ta%le data te$poail75
S7nta/0
Delete ,table_name- whee ,condition-.
'/0
SQL- delete student.
If 7ou ae not spe!if7ing an7 !ondition this will delete entie ta%le5
SQL- delete student whee no H 1.
15
-
8/18/2019 SQL for Beginers
16/278
USIN8 DDL
USIN8 LT'R
This !an %e used to add o e$ove !olu$ns and to $odif7 the pe!ision of the datat7pe5
a) DDIN8 COLUMN
S7nta/0
alte ta%le ,table_name- add ,col datatype-.
'/0
SQL- alte ta%le student add sdo% date.
%) R'MO9IN8 COLUMN
S7nta/0
alte ta%le ,table_name- dop ,col datatype-.
'/0
SQL- alte ta%le student dop !olu$n sdo%.
!) INCR'SIN8 OR D'CR'SIN8 AR'CISION OB COLUMN
S7nta/0
alte ta%le ,table_name- $odif7 ,col datatype-.
'/0
SQL- alte ta%le student $odif7 $a&s nu$%e().
E To de!ease pe!ision the !olu$n should %e e$pt75
d) MFIN8 COLUMN UNUS'D
S7nta/0
alte ta%le ,table_name- set unused !olu$n ,col -.
'/0
SQL- alte ta%le student set unused !olu$n $a&s.
16
-
8/18/2019 SQL for Beginers
17/278
'ven though the !olu$n is unused still it will o!!up7 $e$o75
e) DROAAIN8 UNUS'D COLUMNS
S7nta/0
alte ta%le ,table_name- dop unused !olu$ns.
'/0
SQL- alte ta%le student dop unused !olu$ns.
E *ou !an not dop individual unused !olu$ns of a ta%le5
f) R'NMIN8 COLUMN
S7nta/0 alte ta%le ,table_name- ena$e !olu$n ,old_col_name- to ,new_col_name-.
'/0
SQL- alte ta%le student ena$e !olu$n $a&s to s$a&s.
USIN8 TRUNCT'
This !an %e used to delete the entie ta%le data pe$anentl75
S7nta/0
tun!ate ta%le ,table_name-.
'/0
SQL- tun!ate ta%le student.
USIN8 DROA
This will %e used to dop the data%ase o%Je!t.
S7nta/0
Dop ta%le ,table_name-.
'/0
SQL- dop ta%le student.
USIN8 R'NM'
This will %e used to ena$e the data%ase o%Je!t.
S7nta/0
17
-
8/18/2019 SQL for Beginers
18/278
ena$e ,old table_name- to ,new_table_name-.
'/0
SQL- ena$e student to stud.
USIN8 TCL
USIN8 COMMIT
This will %e used to save the wo&5
Co$$it is of two t7pes5
I$pli!it
'/pli!it
a) IMALICIT
This will %e issued %7 oa!le intenall7 in two situations5
6hen an7 DDL opeation is pefo$ed5
6hen 7ou ae e/iting fo$ SQL E ALUS5
%) '+ALICIT
This will %e issued %7 the use5
S7nta/0
Co$$it o !o$$it wo&.
E 6hen eve 7ou !o$$itted then the tansa!tion was !o$pleted5
USIN8 ROLLCF
This will undo the opeation5
This will %e applied in two $ethods5
Upto pevious !o$$it
Upto pevious oll%a!&
S7nta/0
Roll o oll wo&.
O
18
-
8/18/2019 SQL for Beginers
19/278
Roll%a!& o oll%a!& wo&.
E 6hile po!ess is going on# if suddenl7 powe goes then oa!le will oll%a!& the
tansa!tion5
USIN8 S9'AOINT
*ou !an use savepoints to oll%a!& potions of 7ou !uent set of tansa!tions5
S7nta/0
Savepoint , savepoint_name-.
'/0
SQL- savepoint s2.
SQL- inset into student values(2# Ka;# 233).
SQL- savepoint s1. SQL- inset into student values(1# K%;# 133).
SQL- savepoint s4.
SQL- inset into student values(4# K!;# 433).
SQL- savepoint s@.
SQL- inset into student values(@# Kd;# @33).
efoe oll%a!&
SQL- sele!t E fo$ student.
NO NM' MRFS
""" """"""" """"""""""
2 a 233
1 % 133
4 ! 433
@ d @33
SQL- oll%a!& to savepoint s4.
O
SQL- oll%a!& to s4.
This will oll%a!& last two e!ods5
SQL- sele!t E fo$ student.
19
-
8/18/2019 SQL for Beginers
20/278
NO NM' MRFS
""" """"""" """"""""""
2 a 233
1 % 133
USIN8 DCL
DCL !o$$ands ae used to ganting and evo&ing the pe$issions5
USIN8 8RNT
This is used to gant the pivileges to othe uses5
S7nta/0
8ant , privilees- on ,ob!ect_name- to ,user_name- with gant option.
'/0 SQL- gant sele!t on student to sudha. "" 7ou !an give individual pivilege
SQL- gant sele!t# inset on student to sudha. "" 7ou !an give set of pivileges
SQL- gant all on student to sudha. "" 7ou !an give all pivileges
The sudha use has to use dot $ethod to a!!ess the o%Je!t5
SQL- sele!t E fo$ sað5student.
The sudha use !an not gant pe$ission on student ta%le to othe uses5 To get this
t7pe of option use the following5
SQL- gant all on student to sudha with gant option.
Now sudha use also gant pe$issions on student ta%le5
USIN8 R'9OF'
This is used to evo&e the pivileges fo$ the uses to whi!h 7ou ganted the
pivileges5
S7nta/0
Revo&e , privilees- on ,ob!ect_name- fo$ ,user_name-.
'/0
SQL- evo&e sele!t on student fo$ sudha. "" 7ou !an evo&e individual
pivilege
20
-
8/18/2019 SQL for Beginers
21/278
SQL- evo&e sele!t# inset on student fo$ sudha. "" 7ou !an evo&e set of
pivileges
SQL- evo&e all on student fo$ sudha. "" 7ou !an evo&e all pivileges
USIN8 LIS'S
CR'T' 6IT: S'L'CT
6e !an !eate a ta%le using e/isting ta%le along with data5
S7nta/0
Ceate ta%le ,new_table_name- col1, col2, col3 ... coln as sele!t E fo$
,old_table_name-.
'/0
SQL- !eate ta%le student2 as sele!t E fo$ student.
Ceating ta%le with 7ou own !olu$n na$es5
SQL- !eate ta%le student1(sno# sna$e# s$a&s) as sele!t E fo$ student.
Ceating ta%le with spe!ified !olu$ns5
SQL- !eate ta%le student4 as sele!t no#na$e fo$ student.
Ceating ta%le with out ta%le data5
SQL- !eate ta%le student1(sno# sna$e# s$a&s) as sele!t E fo$ student whee 2H1.
In the a%ove whee !lause give an7 !ondition whi!h does not satisf75
INS'RT 6IT: S'L'CT
Using this we !an inset e/isting ta%le data to a anothe ta%le in a single tip5 ut the
ta%le stu!tue should %e sa$e5
S7nta/0
Inset into ,table1- sele!t E fo$ ,table2-.
'/0
SQL- inset into student2 sele!t E fo$ student.
21
-
8/18/2019 SQL for Beginers
22/278
Inseting data into spe!ified !olu$ns
SQL- inset into student2(no# na$e) sele!t no# na$e fo$ student.
COLUMN LIS'S
S7nta/0
"elect #orinal_col$ #alias_name$ %rom #table na$e-.
'/0
SQL- sele!t no sno fo$ student.
o
SQL- sele!t no Psno fo$ student.
TL' LIS'S
If 7ou ae using ta%le aliases 7ou !an use dot $ethod to the !olu$ns5
S7nta/0
Sele!t ,alias_name-5,col1-# ,alias_name-5,col2- ,alias_name-5,coln- fo$
,table_name- ,alias_name-.
'/0
SQL- sele!t s5no# s5na$e fo$ student s.
22
-
8/18/2019 SQL for Beginers
23/278
USIN8 M'R8'
M'R8'
*ou !an use $ege !o$$and to pefo$ inset and update in a single !o$$and5
'/0
SQL- Mege into student2 s2
Using (sele!t EBo$ student1) s1
On(s25noHs15no)
6hen $at!hed then
Update set $a&s H s15$a&s
6hen not $at!hed then
Inset (s25no#s25na$e#s25$a&s)
9alues(s15no#s15na$e#s15$a&s).
In the a%ove the two ta%les ae with the sa$e stu!tue %ut we !an $ege diffeent
stu!tued ta%les also %ut the datat7pe of the !olu$ns should $at!h5
ssu$e that student2 has !olu$ns li&e no#na$e#$a&s and student1 has !olu$ns li&e
no# na$e# hno# !it75
SQL- Mege into student2 s2
Using (sele!t EBo$ student1) s1
On(s25noHs15no)
6hen $at!hed then
Update set $a&s H s15hno
6hen not $at!hed then
Inset (s25no#s25na$e#s25$a&s)
9alues(s15no#s15na$e#s15hno).
23
-
8/18/2019 SQL for Beginers
24/278
MULTIAL' INS'RTS
6e have ta%le !alled D'AT with the following !olu$ns and data
D'ATNO DNM' LOC
"""""""" """""""" """"
23 a!!ounting new 7o&
13 esea!h dallas
43 sales Chi!ago
@3 opeations %oston
a) CR'T' STUD'NT TL'
SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(1)#$a&s nu$%e(4)).
%) MULTI INS'RT 6IT: LL BI'LDS
SQL- Inset all
Into student values(2#;a;#233)
Into student values(1#;%;#133)
Into student values(4#;!;#433)
Sele!t Efo$ dept whee deptnoH23.
"" This insets 4 ows
!) MULTI INS'RT 6IT: SA'CIBI'D BI'LDS
SQL- inset all
Into student (no#na$e) values(@#;d;)
Into student(na$e#$a&s) values(;e;#@33)
Into student values(4#;!;#433)
24
-
8/18/2019 SQL for Beginers
25/278
Sele!t Efo$ dept whee deptnoH23.
"" This insets 4 ows
d) MULTI INS'RT 6IT: DUALICT' RO6S
SQL- inset all
Into student values(2#;a;#233)
Into student values(1#;%;#133)
Into student values(4#;!;#433)
Sele!t Efo$ dept whee deptno - 23.
"" This insets ows %e!ause in the sele!t state$ent etieves 4 e!ods (4 insets
fo ea!h
ow etieved)
e) MULTI INS'RT 6IT: CONDITIONS S'D
SQL- Inset all
6hen deptno - 23 then
Into student2 values(2#;a;#233)
6hen dna$e H KSL'S; then
Into student1 values(1#;%;#133)
6hen lo! H KN'6 *ORF; then
Into student4 values(4#;!;#433)
Sele!t Efo$ dept whee deptno-23.
"" This insets @ ows %e!ause the fist !ondition satisfied 4 ti$es# se!ond !ondition
satisfied on!e and the last none5
f) MULTI INS'RT 6IT: CONDITIONS S'D ND 'LS'
SQL- Inset all
6hen deptno - 233 then
Into student2 values(2#;a;#233)
6hen dna$e H KS; then
Into student1 values(1#;%;#133)
6hen lo! H KN'6 *ORF; then
Into student4 values(4#;!;#433)
'lse
25
-
8/18/2019 SQL for Beginers
26/278
Into student values(@#;d;#@33)
Sele!t Efo$ dept whee deptno-23.
"" This insets 4 e!ods %e!ause the else satisfied 4 ti$es
g) MULTI INS'RT 6IT: CONDITIONS S'D ND BIRST
SQL- Inset fist
6hen deptno H 13 then
Into student2 values(2#;a;#233)
6hen dna$e H KR'S'RC:; then
Into student1 values(1#;%;#133)
6hen lo! H KN'6 *ORF; then
Into student4 values(4#;!;#433)
Sele!t Efo$ dept whee deptnoH13.
"" This insets 2 e!od %e!ause the fist !lause avoid to !he!& the e$aining
!onditions
on!e the !ondition is satisfied5
h) MULTI INS'RT 6IT: CONDITIONS S'D# BIRST ND 'LS'
SQL- Inset fist
6hen deptno H 43 then
Into student2 values(2#;a;#233)
6hen dna$e H KR; then
Into student1 values(1#;%;#133)
6hen lo! H KN'6 *ORF; then
Into student4 values(4#;!;#433)
'lse
Into student values(@#;d;#@33)
Sele!t Efo$ dept whee deptnoH13.
"" This insets 2 e!od %e!ause the else !lause satisfied on!e
i) MULTI INS'RT 6IT: MULTIL' TL'S
SQL- Inset all
Into student2 values(2#;a;#233)
Into student1 values(1#;%;#133)
Into student4 values(4#;!;#433)
Sele!t Efo$ dept whee deptnoH23.
26
-
8/18/2019 SQL for Beginers
27/278
"" This insets 4 ows
EE *ou !an use $ulti ta%les with spe!ified fields# with dupli!ate ows# with
!onditions# with fist and else !lauses5
BUNCTIONS
Bun!tions !an %e !ategoied as follows5
Single ow fun!tions
8oup fun!tions
SIN8L' RO6 BUNCTIONS
Single ow fun!tions !an %e !ategoied into five5 These will %e applied fo ea!h ow
and podu!es individual output fo ea!h ow5
Nu$ei! fun!tions
Sting fun!tions
Date fun!tions
Mis!ellaneous fun!tions
Convesion fun!tions
NUM'RIC BUNCTIONS
%s
Sign
St
Mod
Nvl
Aowe
'/p
Ln
Log
Ceil
Bloo
Round
27
-
8/18/2019 SQL for Beginers
28/278
Tun&
itand
8eatest
Least
Coales!e
a) S
%solute value is the $easue of the $agnitude of value5
%solute value is alwa7s a positive nu$%e5
S7nta/0 a%s (value)
'/0
SQL- sele!t a%s()# a%s(")# a%s(3)# a%s(null) fo$ dual.
S() S(") S(3) S(NULL)
"""""""""" """""""""" """""""""" """""""""""""
" 3
%) SI8N
Sign gives the sign of a value5
S7nta/0 sign (value)
'/0
SQL- sele!t sign()# sign(")# sign(3)# sign(null) fo$ dual.
SI8N() SI8N(") SI8N(3) SI8N(NULL)"""""""""" """""""""" """""""""" """"""""""""""
2 "2 3
!) SQRT
This will give the suae oot of the given value5
S7nta/0 st (value) "" hee value $ust %e positive5
'/0
SQL- sele!t st(@)# st(3)# st(null)# st(2) fo$ dual.
SQRT(@) SQRT(3) SQRT(NULL) SQRT(2)
"""""""""" """""""""" """"""""""""""" """"""""""
1 3 2
d) MOD
This will give the e$ainde5
S7nta/0 $od (value, divisor )
28
-
8/18/2019 SQL for Beginers
29/278
'/0
SQL- sele!t $od(V#@)# $od(2#)# $od(null#null)# $od(3#3)# $od("V#@) fo$ dual.
MOD(V#@) MOD(2#) MOD(NULL#NULL) MOD(3#3) MOD("V#@)
"""""""""""" """""""""" """"""""""""""""""""" """"""""""" """""""""""""
4 2 3 "4
e) N9L
This will su%stitutes the spe!ified value in the pla!e of null values5
S7nta/0 nvl (null_col, replacement_value)
'/0
SQL- sele!t E fo$ student. "" hee fo 4d ow $a&s value is null
NO NM' MRFS
""" """"""" """""""""
2 a 233 1 % 133
4 !
SQL- sele!t no# na$e# nvl($a&s#433) fo$ student.
NO NM' N9L(MRFS#433)
""" """"""" """""""""""""""""""""
2 a 233
1 % 133
4 ! 433
SQL- sele!t nvl(2#1)# nvl(1#4)# nvl(@#4)# nvl(#@) fo$ dual.
N9L(2#1) N9L(1#4) N9L(@#4) N9L(#@)
"""""""""" """""""""" """""""""" """"""""""
2 1 @
SQL- sele!t nvl(3#3)# nvl(2#2)# nvl(null#null)# nvl(@#@) fo$ dual.
N9L(3#3) N9L(2#2) N9L(null#null) N9L(@#@)
"""""""""" """""""""" """"""""""""""""" """"""""""
3 2 @
f) AO6'R
Aowe is the a%ilit7 to aise a value to a given e/ponent5
S7nta/0 powe (value, eponent )
'/0
SQL- sele!t powe(1#)# powe(3#3)# powe(2#2)# powe(null#null)# powe(1#")
fo$ dual.
29
-
8/18/2019 SQL for Beginers
30/278
AO6'R(1#) AO6'R(3#3) AO6'R(2#2) AO6'R(NULL#NULL) AO6'R(1#")
"""""""""""""" """""""""""""" """"" """"""""" """"""""""""""""""""""" """""""""""""""
41 2 2 53421
g) '+A
This will aise e value to the give powe5
S7nta/0 e/p (value)
'/0
SQL- sele!t e/p(2)# e/p(1)# e/p(3)# e/p(null)# e/p("1) fo$ dual.
'+A(2) '+A(1) '+A(3) '+A(NULL) '+A("1)
"""""""" """"""""" """""""" """"""""""""" """"""""""
15V2W1W2W4 V54W32 2 524441W4h) LN
This is %ased on natual o %ase e logaith$5
S7nta/0 ln (value) "" hee value $ust %e geate than eo whi!h is positive onl75
'/0
SQL- sele!t ln(2)# ln(1)# ln(null) fo$ dual.
LN(2) LN(1) LN(NULL)
""""""" """"""" """"""""""""
3 542@V2W2
Ln and '/p ae e!ipo!al to ea!h othe5
'+A (4) H 1353W4
LN (1353W4) H 4
i) LO8
This is %ased on 23 %ased logaith$5
S7nta/0 log (23# value)"" hee value $ust %e geate than eo whi!h is positive onl75
'/0
SQL- sele!t log(23#233)# log(23#1)# log(23#2)# log(23#null) fo$ dual.LO8(23#233) LO8(23#1) LO8(23#2) LO8(23#NULL)
""""""""""""""" """"""""""" """""""""""" """""""""""""""""
1 543231 3
LN (value) H LO8 ('+A(2)# value)
SQL- sele!t ln(4)# log(e/p(2)#4) fo$ dual.
30
-
8/18/2019 SQL for Beginers
31/278
LN(4) LO8('+A(2)#4)
""""""" """""""""""""""""
253W211 253W211
J) C'IL
This will podu!e a whole nu$%e that is geate than o eual to the spe!ified value5
S7nta/0 !eil (value)
'/0
SQL- sele!t !eil()# !eil(52)# !eil(")# !eil( "52)# !eil(3)# !eil(null) fo$ dual.
C'IL() C'IL(52) C'IL(") C'IL("52) C'IL(3) C'IL(NULL)
""""""""" """"""""""" """""""""" """""""""""" """""""" """"""""""""""
" " 3
&) BLOOR This will podu!e a whole nu$%e that is less than o eual to the spe!ified value5
S7nta/0 floo (value)
'/0
SQL- sele!t floo()# floo(52)# floo(")# floo( "52)# floo(3)# floo(null) fo$ dual.
BLOOR() BLOOR(52) BLOOR(") BLOOR("52) BLOOR(3) BLOOR(NULL)
""""""""""" """"""""""""" """""""""""" """""""""""""" """"""""""" """"""""""""""""
" " 3
l) ROUND
This will ounds nu$%es to a given nu$%e of digits of pe!ision5
S7nta/0 ound (value, precision)
'/0
SQL- sele!t ound(214514@)# ound(214514@#1)# ound(214514@#1) fo$ dual.
ROUND(214514@) ROUND(214514@#3) ROUND(214514@#1) ROUND(214514@#1)
""""""""""""""""""""" """""""""""""""""""""""" """"""""""""""""""""""" """""""""""""""""""""""
214 214 214514 21451@
SQL- sele!t ound(214514@#"2)# ound(214514@#"1)# ound(214514@#"4)#ound(214514@#"@) fo$ dual.
ROUND(214514@#"2) ROUND(214514@#"1) ROUND(214514@#"4) ROUND(214514@#"@)
"""""""""""""""""""""""" """"""""""""""""""""""""" """""""""""""""""""""""" """"""""""""""""""""""""
213 233 3 3
SQL- sele!t ound(214#3)# ound(214#2)# ound(214#1) fo$ dual.
31
-
8/18/2019 SQL for Beginers
32/278
ROUND(214#3) ROUND(214#2) ROUND(214#1)
""""""""""""""""" """"""""""""""""" """"""""""""""""
214 214 214
SQL- sele!t ound("214#3)# ound("214#2)# ound("214#1) fo$ dual.
ROUND("214#3) ROUND("214#2) ROUND("214#1)
"""""""""""""""""" """"""""""""""""" """""""""""""""""""
"214 "214 "214
SQL- sele!t ound(214#"2)# ound(214#"1)# ound(214#"4)# ound("214#"2)#
ound("214#"1)# ound("214#"4) fo$ dual.
RND(214#"2) RND(214#"1) RND(214#"4) RND("214#"2) RND("214#"1) RND("214#"4)
""""""""""""" """"""""""""" """"""""""""" """""""""""""" """""""""""""" """"""""""""""
213 233 3 "213 "233 3
SQL- sele!t ound(null#null)# ound(3#3)# ound(2#2)# ound("2#"2)# ound("1#"1) fo$
dual.
ROUND(NULL#NULL) ROUND(3#3) ROUND(2#2) ROUND("2#"2) ROUND("1#"1)
""""""""""""""""""""""" """""""""""""" """""""""""""" """""""""""""""" """"""""""""""""
3 2 3 3
$) TRUNC
This will tun!ates o !hops off digits of pe!ision fo$ a nu$%e5
S7nta/0 tun! (value, precision)
'/0
SQL- sele!t tun!(214514@)# tun!(214514@#1)# tun!(214514@#1) fo$ dual.
TRUNC(214514@) TRUNC(214514@#1) TRUNC(214514@#1)
""""""""""""""""""""" """"""""""""""""""""""" """""""""""""""""""""""
214 214514 214514
SQL- sele!t tun!(214514@#"2)# tun!(214514@#"1)# tun!(214514@#"4)#
tun!(214514@#"@) fo$ dual.
TRUNC(214514@#"2) TRUNC(214514@#"1) TRUNC(214514@#"4) TRUNC(214514@#"@)
"""""""""""""""""""""""" """""""""""""""""""""""" """"""""""""""""""""""" """"""""""""""""""""""""
213 233 3 3
32
-
8/18/2019 SQL for Beginers
33/278
SQL- sele!t tun!(214#3)# tun!(214#2)# tun!(214#1) fo$ dual.
TRUNC(214#3) TRUNC(214#2) TRUNC(214#1)
"""""""""""""""" """""""""""""""" """""""""""""""""
214 214 214
SQL- sele!t tun!("214#3)# tun!("214#2)# tun!("214#1) fo$ dual.
TRUNC("214#3) TRUNC("214#2) TRUNC("214#1)
""""""""""""""""" """"""""""""""""" """""""""""""""""
"214 "214 "214
SQL- sele!t tun!(214#"2)# tun!(214#"1)# tun!(214#"4)# tun!("214#"2)# tun!("214#1)#
tun!("214#"4) fo$ dual.
TRUN(214#"2) TRUN(214#"1) TRUN(214#"4) TRUN("214#"2) TRUN("214#1) TRUN("14#"4)
""""""""""""" """"""""""""" """""""""""" """""""""""" """"""""" """""""""""213 233 3 "213 "214 3
SQL- sele!t tun!(null#null)# tun!(3#3)# tun!(2#2)# tun!("2#"2)# tun!("1#"1) fo$ dual.
TRUNC(NULL#NULL) TRUNC(3#3) TRUNC(2#2) TRUNC("2#"2) TRUNC("1#"1)
""""""""""""""""""""""" """"""""""""" """"""""""""" """"""""""""""" """"""""""""""""
3 2 3 3
n) ITND
This will pefo$ %itwise and opeation5
S7nta/0 %itand (value1, value2)
'/0
SQL- sele!t %itand(1#4)# %itand(3#3)# %itand(2#2)# %itand(null#null)# %itand("1#"4) fo$
dual.
ITND(1#4) ITND(3#3) ITND(2#2) ITND(NULL#NULL) ITND("1#"4)
"""""""""""""" """"""""""""""" """""""""""""" """""""""""""""""""""""" """""""""""""""""
1 3 2 "@
o) 8R'T'ST
This will give the geatest nu$%e5
S7nta/0 geatest (value1, value2, value3 … valuen)
'/0
SQL- sele!t geatest(2# 1# 4)# geatest("2# "1# "4) fo$ dual.
8R'T'ST(2#1#4) 8R'T'ST("2#"1#"4)
33
-
8/18/2019 SQL for Beginers
34/278
"""""""""""""""""""" """""""""""""""""""""""
4 "2
If all the values ae eos then it will displa7 eo5
If all the paa$etes ae nulls then it will displa7 nothing5
If an7 of the paa$etes is null it will displa7 nothing5
p) L'ST
This will give the least nu$%e5
S7nta/0 least (value1, value2, value3 … valuen)
'/0
SQL- sele!t least(2# 1# 4)# least("2# "1# "4) fo$ dual.
L'ST(2#1#4) L'ST("2#"1#"4)
"""""""""""""""""""" """""""""""""""""""""""
2 "4 If all the values ae eos then it will displa7 eo5
If all the paa$etes ae nulls then it will displa7 nothing5
If an7 of the paa$etes is null it will displa7 nothing5
) COL'SC'
This will etun fist non"null value5
S7nta/0 !oales!e (value1, value2, value3 … valuen)
'/0
SQL- sele!t !oales!e(2#1#4)# !oales!e(null#1#null#) fo$ dual.
COL'SC'(2#1#4) COL'SC'(NULL#1#NULL#)
""""""""""""""""""" """""""""""""""""""""""""""""""
2 1
34
-
8/18/2019 SQL for Beginers
35/278
STRIN8 BUNCTIONS
Init!ap
Uppe
Lowe
Length
Rpad
Lpad
Lti$
Rti$
Ti$
Tanslate
Repla!e
Sounde/
Con!at ( K XX K Con!atenation opeato)
s!ii
Ch
Su%st
Inst
De!ode
8eatest
Least
Coales!e
a) INITCA
This will !apitalie the initial lette of the sting5
S7nta/0 init!ap ( strin)
'/0 SQL- sele!t init!ap(=!o$pute=) fo$ dual.
INITCA
"""""""""""
35
-
8/18/2019 SQL for Beginers
36/278
Co$pute
%) UAA'R
This will !onvet the sting into uppe!ase5
S7nta/0 uppe ( strin)
'/0 SQL- sele!t uppe(=!o$pute=) fo$ dual.
UAA'R
"""""""""""
COMAUT'R
!) LO6'R
This will !onvet the sting into lowe!ase5
S7nta/0 lowe ( strin)
'/0
SQL- sele!t lowe(=COMAUT'R =) fo$ dual.
LO6'R
""""""""""
!o$pute
d) L'N8T:
This will give length of the sting5
S7nta/0 length ( strin)
'/0
SQL- sele!t length(=!o$pute=) fo$ dual.
L'N8T:
"""""""""""
W
e) RAD
This will allows 7ou to pad the ight side of a !olu$n with an7 set of !haa!tes5
S7nta/0 pad ( strin, lent' , paddin_c'ar))
'/0
SQL- sele!t pad(=!o$pute=#2#=E=)# pad(=!o$pute=#2#=EY=) fo$ dual.
RAD(=COMAUT'R= RAD(=COMAUT'R=
"""""""""""""""""""""" """"""""""""""""""""""
!o$puteEEEEEEE !o$puteEYEYEYE
"" Default padding !haa!te was %lan& spa!e5
f) LAD
This will allows 7ou to pad the left side of a !olu$n with an7 set of !haa!tes5
S7nta/0 lpad ( strin, lent' , paddin_c'ar))
36
-
8/18/2019 SQL for Beginers
37/278
'/0
SQL- sele!t lpad(=!o$pute=#2#=E=)# lpad(=!o$pute=#2#=EY=) fo$ dual.
LAD(=COMAUT'R= LAD(=COMAUT'R=
""""""""""""""""""""" """""""""""""""""""""
EEEEEEE!o$pute EYEYEYE!o$pute
"" Default padding !haa!te was %lan& spa!e5
g) LTRIM
This will ti$ off unwanted !haa!tes fo$ the left end of sting5
S7nta/0 lti$ ( strin ,unwanted_c'ars))
'/0
SQL- sele!t lti$(=!o$pute=#=!o=)# lti$(=!o$pute=#=!o$=) fo$ dual.
LTRIM( LTRIM
"""""""" """""""""
$pute pute
SQL- sele!t lti$(=!o$pute=#=pute=)# lti$(=!o$pute=#=o$pute=) fo$ dual.
LTRIM(=C LTRIM(=C
"""""""""" """"""""""
!o$pute !o$pute
"" If 7ou haven;t spe!if7 an7 unwanted !haa!tes it will displa7 entie sting5
h) RTRIM
This will ti$ off unwanted !haa!tes fo$ the ight end of sting5
S7nta/0 ti$ ( strin , unwanted_c'ars))
'/0
SQL- sele!t ti$(=!o$pute=#=e=)# ti$(=!o$pute=#=te=) fo$ dual.
RTRIM( RTRIM
"""""""" """""""""
!o$put !o$pu
SQL- sele!t ti$(=!o$pute=#=!o$put;)# ti$(=!o$pute=#=!o$pute=) fo$ dual.RTRIM(=C RTRIM(=C
"""""""""" """"""""""
!o$pute !o$pute
"" If 7ou haven;t spe!if7 an7 unwanted !haa!tes it will displa7 entie sting5
i) TRIM
37
-
8/18/2019 SQL for Beginers
38/278
This will ti$ off unwanted !haa!tes fo$ the %oth sides of sting5
S7nta/0 ti$ (unwanted_c'ars fo$ strin)
'/0
SQL- sele!t ti$( =i= fo$ =indiani=) fo$ dual.
TRIM(
"""""
ndian
SQL- sele!t ti$( leading=i= fo$ =indiani=) fo$ dual."" this will wo& as LTRIM
TRIM(L
""""""
ndiani
SQL- sele!t ti$( tailing=i= fo$ =indiani=) fo$ dual."" this will wo& as RTRIM
TRIM(T
""""""
Indian
J) TRNSLT'
This will epla!e the set of !haa!tes# !haa!te %7 !haa!te5
S7nta/0 tanslate ( strin, old_c'ars, new_c'ars)
'/0
SQL- sele!t tanslate(=india=#=in=#=/7=) fo$ dual.
TRNS
""""""""
/7d/a
&) R'ALC'
This will epla!e the set of !haa!tes# sting %7 sting5
S7nta/0 epla!e ( strin, old_c'ars , new_c'ars))
'/0
SQL- sele!t epla!e(=india=#=in=#=/7=)# epla!e(Kindia;#;in;) fo$ dual.
R'ALC' R'ALC'
""""""""""" """""""""""
+7dia dia
l) SOUND'+
38
-
8/18/2019 SQL for Beginers
39/278
This will %e used to find wods that sound li&e othe wods# e/!lusivel7 used in
whee !lause5
S7nta/0 sounde/ ( strin)
'/0
SQL- sele!t E fo$ e$p whee sounde/(ena$e) H sounde/(=SMIT=).
'MANO 'NM' >O M8R :IR'DT' SL D'ATNO
"""""""" """""""" """"" """"" """""""""""" """"""""" """"""""""
V4 SMIT: CL'RF V31 2V"D'C"W3 33 13
$) CONCT
This will %e used to !o$%ine two stings onl75
S7nta/0 !on!at ( strin1, strin2)
'/0
SQL- sele!t !on!at(=!o$pute=#= opeato=) fo$ dual.
CONCT(=COMAUT'R=
"""""""""""""""""""""""""
!o$pute opeato
If 7ou want to !o$%ine $oe than two stings 7ou have to use !on!atenation
opeato (XX)5
SQL- sele!t =how= XX = ae= XX = 7ou= fo$ dual.
=:O6=XX=R'
"""""""""""""""
how ae 7ou
n) SCII
This will etun the de!i$al epesentation in the data%ase !haa!te set of the fist
!haa!te of the sting5
S7nta/0 as!ii ( strin)
'/0
SQL- sele!t as!ii(=a=)# as!ii(=apple=) fo$ dual.
SCII(==) SCII(=AAL'=)"""""""""""" """"""""""""""""""
V V
o) C:R
This will etun the !haa!te having the %ina7 euivalent to the sting in eithe the
39
-
8/18/2019 SQL for Beginers
40/278
-
8/18/2019 SQL for Beginers
41/278
If 7ou ae not spe!if7ing start_c'r_count and occurrence then it will stat
sea!h fo$
the %eginning and finds fist o!!uen!e onl75
If %oth paa$etes start_c'r_count and occurrence ae null# it will displa7
nothing5
) D'COD'
De!ode will a!t as value %7 value su%stitution5
Bo eve7 value of field# it will !he!&s fo a $at!h in a seies of if?then tests5
S7nta/0 de!ode (value, i%1, t'en1, i%2, t'en2, ……. else).
'/0 SQL- sele!t sal# de!ode(sal#33#=Low=#333#=:igh=#=Mediu$=) fo$ e$p.
SL D'COD'
""""" """""""""
33 Low
133 Mediu$
1333 Mediu$
433 Mediu$
4333 Mediu$
333 :igh
@333 Mediu$
333 :igh
2W33 Mediu$
2133 Mediu$
1333 Mediu$
1V33 Mediu$
1133 Mediu$
4133 Mediu$
SQL- sele!t de!ode(2#2#4)# de!ode(2#1#4#@#@#) fo$ dual.
D'COD'(2#2#4) D'COD'(2#1#4#@#@#)""""""""""""""""" """""""""""""""""""""""" 4
41
-
8/18/2019 SQL for Beginers
42/278
If the nu$%e of paa$etes ae odd and diffeent then de!ode will displa7
nothing5
If the nu$%e of paa$etes ae even and diffeent then de!ode will displa7
last
value5
If all the paa$etes ae null then de!ode will displa7 nothing5
If all the paa$etes ae eos then de!ode will displa7 eo5
s) 8R'T'ST
This will give the geatest sting5
S7nta/0 geatest ( strn1, strin2, strin3 … strinn)
'/0
SQL- sele!t geatest(=a=# =%=# =!=)# geatest(=satish=#=sinu=#=sað=) fo$ dual.
8R'T 8R'T
""""""" """""""
! sinu
If all the paa$etes ae nulls then it will displa7 nothing5
If an7 of the paa$etes is null it will displa7 nothing5
t) L'ST
This will give the least sting5
S7nta/0 geatest ( strn1, strin2, strin3 … strinn)
'/0
SQL- sele!t least(=a=# =%=# =!=)# least(=satish=#=sinu=#=sað=) fo$ dual.
L'ST L'ST
""""""" """""""
sað
If all the paa$etes ae nulls then it will displa7 nothing5
If an7 of the paa$etes is null it will displa7 nothing5
u) COL'SC'
This will gives the fist non"null sting5
S7nta/0 !oales!e ( strn1, strin2, strin3 … strinn)
42
-
8/18/2019 SQL for Beginers
43/278
'/0
SQL- sele!t !oales!e(=a=#=%=#=!=)# !oales!e(null#=a=#null#=%=) fo$ dual.
COL'SC' COL'SC'
""""""""""" """""""""""
a a
EEEDT' BUNCTIONSEEE
S7sdate
Cuentdate
Cuentti$esta$p
S7sti$esta$p
Lo!alti$esta$p
D%ti$eone
Sessionti$eone
To!ha
Todate
dd$onths
Months%etween
Ne/tda7
Lastda7
'/ta!t
8eatest
Least
Round
Tun!
Newti$e
Coales!e
Oa!le default date fo$at is DD"MON"**5
43
-
8/18/2019 SQL for Beginers
44/278
6e !an !hange the default fo$at to ou desied fo$at %7 using the following
!o$$and5
SQL- alte session set nlsdatefo$at H KDD"MONT:"****;.
ut this will e/pie on!e the session was !losed5
a) S*SDT'
This will give the !uent date and ti$e5
'/0
SQL- sele!t s7sdate fo$ dual.
S*SDT'
"""""""""""
1@"D'C"3
%) CURR'NTDT'
This will etuns the !uent date in the session;s ti$eone5
'/0
SQL- sele!t !uentdate fo$ dual.
CURR'NTDT'
""""""""""""""""""
1@"D'C"3
!) CURR'NTTIM'STMA
This will etuns the !uent ti$esta$p with the a!tive ti$e one info$ation5
'/0
SQL- sele!t !uentti$esta$p fo$ dual.
CURR'NTTIM'STMA
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1@"D'C"3 345@15@254W44 M G3043
d) S*STIM'STMA
This will etuns the s7ste$ date# in!luding fa!tional se!onds and ti$e one of the
data%ase5
'/0
44
-
8/18/2019 SQL for Beginers
45/278
SQL- sele!t s7sti$esta$p fo$ dual.
S*STIM'STMA
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1@"D'C"3 345@5425W433 M G3043
e) LOCLTIM'STMA
This will etuns lo!al ti$esta$p in the a!tive ti$e one info$ation# with no ti$e
one info$ation shown5
'/0
SQL- sele!t lo!alti$esta$p fo$ dual.
LOCLTIM'STMA"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1@"D'C"3 345@@52W531WV@ M
f) DTIM'ZON'
This will etuns the !uent data%ase ti$e one in UTC fo$at5 (Coodinated
Univesal Ti$e)
'/0
SQL- sele!t d%ti$eone fo$ dual.
DTIM'ZON'""""""""""""""" "3V033
g) S'SSIONTIM'ZON'
This will etuns the value of the !uent session;s ti$e one5
'/0
SQL- sele!t sessionti$eone fo$ dual.
S'SSIONTIM'ZON'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
G3043
45
-
8/18/2019 SQL for Beginers
46/278
h) TOC:R
This will %e used to e/ta!t vaious date fo$ats5
The availa%le date fo$ats as follows5
S7nta/0 to!ha (date# %ormat )
DT' BORMTS
D "" No of da7s in wee&DD "" No of da7s in $onthDDD "" No of da7s in 7eaMM "" No of $onthMON "" Thee lette a%%eviation of $onthMONT: "" Bull7 spelled out $onthRM "" Ro$an nu$eal $onthD* "" Thee lette a%%eviated da7
D* "" Bull7 spelled out da7* "" Last one digit of the 7ea** "" Last two digits of the 7ea*** "" Last thee digits of the 7ea**** "" Bull fou digit 7eaS**** "" Signed 7eaI "" One digit 7ea fo$ ISO standadI* "" Two digit 7ea fo$ ISO standadI** "" Thee digit 7ea fo$ ISO standadI*** "" Bou digit 7ea fo$ ISO standad*# *** "" *ea with !o$$a*'R "" Bull7 spelled out 7eaCC "" Centu7Q "" No of uates6 "" No of wee&s in $onth66 "" No of wee&s in 7eaI6 "" No of wee&s in 7ea fo$ ISO standad:: "" :ousMI "" MinutesSS "" Se!ondsBB "" Ba!tional se!ondsM o AM "" Displa7s M o AM depending upon ti$e of da7
46
-
8/18/2019 SQL for Beginers
47/278
5M o A5M "" Displa7s 5M o A5M depending upon ti$e of da7D o C "" Displa7s D o C depending upon the date5D o 5C "" Displa7s D o C depending upon the dateBM "" Aefi/ to $onth o da7# suppesses padding of $onth o da7T: "" Suffi/ to a nu$%eSA "" suffi/ to a nu$%e to %e spelled out
SAT: "" Suffi/ !o$%ination of T: and SA to %e %oth spelled outT:SA "" sa$e as SAT:
'/0
SQL- sele!t to!ha(s7sdate#=dd $onth 7777 hh0$i0ss a$ d7=) fo$ dual.
TOC:R(S*SDT'#=DD MONT: ****::0MI
""""""""""""""""""""""""""""""""""""""""""""""""""""
1@ de!e$%e 133 31034014 p$ sun
SQL- sele!t to!ha(s7sdate#=dd $onth 7ea=) fo$ dual.
TOC:R(S*SDT'#=DDMONT:*'R=)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
1@ de!e$%e two thousand si/
SQL- sele!t to!ha(s7sdate#=dd f$$onth 7ea=) fo$ dual.
TOC:R(S*SDT'#=DD BMMONT: *'R=)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
1@ de!e$%e two thousand si/
SQL- sele!t to!ha(s7sdate#=ddth DDT:=) fo$ dual.
TOC:R(S
""""""""""""
1@th 1@T:
SQL- sele!t to!ha(s7sdate#=ddspth DDSAT:=) fo$ dual.
TOC:R(S*SDT'#=DDSAT:DDSAT:
""""""""""""""""""""""""""""""""""""""""""
twent7"fouth T6'NT*"BOURT: SQL- sele!t to!ha(s7sdate#=ddsp Ddsp DDSA =) fo$ dual.
TOC:R(S*SDT'#=DDSADDSADDSA=)
""""""""""""""""""""""""""""""""""""""""""""""""
twent7"fou Twent7"Bou T6'NT*"BOUR
47
-
8/18/2019 SQL for Beginers
48/278
-
8/18/2019 SQL for Beginers
49/278
MONT:S'T6''N(TODT'(=22"U8"23=#=DD"MON"****=)#TODT'(=22">N"
23=#=DD"MON"****=))
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
V
SQL- sele!t $onths%etween(todate(=22"Jan"23=#=dd"$on"7777=)# todate(=22"
aug"23=#=dd"$on"7777=)) fo$ dual.
MONT:S'T6''N(TODT'(=22">N"23=#=DD"MON"****=)#TODT'(=22"
U8"23=#=DD"MON"****=))
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"V
l) N'+TD*
This will podu!e ne/t da7 of the given da7 fo$ the spe!ified date5
S7nta/0 ne/tda7 (date, day )
'/0
SQL- sele!t ne/tda7(todate(=1@"de!"133=#=dd"$on"7777=)#=sun=) fo$ dual.
N'+TD*(
"""""""""""""
42"D'C"3
"" If the da7 paa$ete is null then it will displa7 nothing5
$) LSTD*
This will podu!e last da7 of the given date5
S7nta/0 lastda7 (date)
'/0
SQL- sele!t lastda7(todate(=1@"de!"133=#=dd"$on"7777=)#=sun=) fo$ dual.
LSTD*(
"""""""""""""42"D'C"3
n) '+TRCT
This is used to e/ta!t a potion of the date value5
S7nta/0 e/ta!t ((7ea X $onth X da7 X hou X $inute X se!ond)# date)
'/0
49
-
8/18/2019 SQL for Beginers
50/278
SQL- sele!t e/ta!t(7ea fo$ s7sdate) fo$ dual.
'+TRCT(*'RBROMS*SDT')
""""""""""""""""""""""""""""""""""""
133
"" *ou !an e/ta!t onl7 one value at a ti$e5
o) 8R'T'ST
This will give the geatest date5
S7nta/0 geatest (date1, date2, date3 … daten)
'/0 SQL- sele!t geatest(todate(=22"Jan"3=#=dd"$on"77=)#todate(=22"$a"
3=#=dd"$on" 77=)#todate(=22"ap"3=#=dd"$on"77=)) fo$ dual.
8R'T'ST(
"""""""""""""
22"AR"3
p) L'ST
This will give the least date5
S7nta/0 least (date1, date2, date3 … daten)
'/0
SQL- sele!t least(todate(=22"Jan"3=#=dd"$on"77=)#todate(=22"$a"3=#=dd"$on"
77=)#todate(=22"ap"3=#=dd"$on"77=)) fo$ dual.
L'ST(
"""""""""""""
22">N"3
) ROUND
Round will ounds the date to whi!h it was eual to o geate than the given date5
S7nta/0 ound (date, ( da7 X $onth X 7ea *)
If the se!ond paa$ete was year then ound will !he!&s the $onth of the given date
in the following anges5
>N "" >UN
>UL "" D'C
If the $onth falls %etween >N and >UN then it etuns the fist da7 of the !uent 7ea5
If the $onth falls %etween >UL and D'C then it etuns the fist da7 of the ne/t 7ea5
If the se!ond paa$ete was mont' then ound will !he!&s the da7 of the given date in
the following anges5
2 "" 2
50
-
8/18/2019 SQL for Beginers
51/278
2 "" 42
If the da7 falls %etween 2 and 2 then it etuns the fist da7 of the !uent $onth5
If the da7 falls %etween 2 and 42 then it etuns the fist da7 of the ne/t $onth5
If the se!ond paa$ete was day then ound will !he!&s the wee& da7 of the given date
in the following anges5SUN "" 6'D
T:U "" SUN
If the wee& da7 falls %etween SUN and 6'D then it etuns the pevious sunda75
If the wee&da7 falls %etween T:U and SUN then it etuns the ne/t sunda75
If the se!ond paa$ete was null then it etuns nothing5
If the 7ou ae not spe!if7ing the se!ond paa$ete then ound will esets the
ti$e to the %egining of the !uent da7 in !ase of use spe!ified date5
If the 7ou ae not spe!if7ing the se!ond paa$ete then ound will esets the
ti$e to the %egining of the ne/t da7 in !ase of s7sdate5
'/0
SQL- sele!t ound(todate(=1@"de!"3@=#=dd"$on"77=)#=7ea=)# ound(todate(=22"
$a"
3=#=dd"$on"77=)#=7ea=) fo$ dual.
ROUND(TO ROUND(TO
"""""""""""" """""""""""""""
32">N"3 32">N"3
SQL- sele!t ound(todate(=22"Jan"3@=#=dd"$on"77=)#=$onth=)# ound(todate(=2W"
Jan"
3@=#=dd"$on"77=)#=$onth=) fo$ dual.
ROUND(TO ROUND(TO
""""""""""""" """""""""""""""
32">N"3@ 32"B'"3@
SQL- sele!t ound(todate(=1"de!"3=#=dd"$on"77=)#=da7=)# ound(todate(=1"
de!"
3=#=dd"$on"77=)#=da7=) fo$ dual.
ROUND(TO ROUND(TO
51
-
8/18/2019 SQL for Beginers
52/278
"""""""""""""" """"""""""""""
1@"D'C"3 42"D'C"3
SQL- sele!t to!ha(ound(todate(=1@"de!"3=#=dd"$on"77=))# =dd $on 7777
hh0$i0ss a$=)
fo$ dual.
TOC:R(ROUND(TODT'(=
"""""""""""""""""""""""""""""""""
1@ de! 133 21033033 a$
) TRUNC
Tun! will !hops off the date to whi!h it was eual to o less than the given date5
S7nta/0 tun! (date, ( da7 X $onth X 7ea *)
If the se!ond paa$ete was year then it alwa7s etuns the fist da7 of the
!uent 7ea5
If the se!ond paa$ete was mont' then it alwa7s etuns the fist da7 of the
!uent $onth5
If the se!ond paa$ete was day then it alwa7s etuns the pevious sunda75
If the se!ond paa$ete was null then it etuns nothing5
If the 7ou ae not spe!if7ing the se!ond paa$ete then tun& will esets the
ti$e to the %egining of the !uent da75
'/0
SQL- sele!t tun!(todate(=1@"de!"3@=#=dd"$on"77=)#=7ea=)# tun!(todate(=22"$a"
3=#=dd"$on"77=)#=7ea=) fo$ dual.
TRUNC(TO TRUNC(TO
""""""""""""" """"""""""""""
32">N"3@ 32">N"3
SQL- sele!t tun!(todate(=22"Jan"3@=#=dd"$on"77=)#=$onth=)# tun!(todate(=2W"Jan"
3@=#=dd"$on"77=)#=$onth=) fo$ dual.
TRUNC(TO TRUNC(TO
""""""""""""" """""""""""""
52
-
8/18/2019 SQL for Beginers
53/278
-
8/18/2019 SQL for Beginers
54/278
SQL- sele!t to!ha(newti$e(s7sdate#=g$t=#=est=)#=dd $on 7777 hh0$i0ss a$=)
fo$ dual.
TOC:R(N'6TIM'(S*SDT
"""""""""""""""""""""""
1@ de! 133 30201 p$
t) COL'SC'
This will give the fist non"null date5
S7nta/0 !oales!e (date1, date2, date3 … daten)
'/0
SQL- sele!t !oales!e(=21"Jan"3=#=24"Jan"=)# !oales!e(null#=21"Jan"3=#=14"$a"
W=#null) fo$ dual.
COL'SC'( COL'SC'(
""""""""""""" """"""""""""
21"Jan"3 21"Jan"3
MISC'LLN'OUS BUNCTIONS
Uid
Use
9sie
Ran&
Densean&
a) UID
This will etuns the intege value !oesponding to the use !uentl7 logged in5
'/0
SQL- sele!t uid fo$ dual.
UID
""""""""""
42
%) US'R
This will etuns the login;s use na$e5
'/0
SQL- sele!t use fo$ dual.
US'R
54
-
8/18/2019 SQL for Beginers
55/278
""""""""""""""""
SF'T:
!) 9SIZ'
This will etuns the nu$%e of %7tes in the e/pession5
'/0
SQL- sele!t vsie(214)# vsie(=!o$pute=)# vsie(=21"Jan"3=) fo$ dual.
9SIZ'(214) 9SIZ'(=COMAUT'R=) 9SIZ'(=21">N"3=)
""""""""""""" """"""""""""""""""""""" """"""""""""""""""""""
4 W
d) RNF
This will give the non"seuential an&ing5
'/0
SQL- sele!t ownu$#sal fo$ (sele!t sal fo$ e$p ode %7 sal des!).
RO6NUM SL
"""""""""" """"""""""
2 333
1 4333
4 4333
@ 1V
1W3
1@3
V 233
W 233
2433 23 213
22 213
21 2233
24 2333
2@ 3
55
-
8/18/2019 SQL for Beginers
56/278
2 W33
SQL- sele!t an&(1V) within goup(ode %7 sal des!) fo$ e$p.
RNF(1V)6IT:IN8ROUA(ORD'R*SLD'SC)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@
d) D'NS'RNF
This will give the seuential an&ing5
'/0
SQL- sele!t densean&(1V) within goup(ode %7 sal des!) fo$ e$p.
D'NS'RNF(1V)6IT:IN8ROUA(ORD'R*SLD'SC)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
4
CON9'RSION BUNCTIONS
intonu$
Chatoowid
Rowidto!ha
Tonu$%e
To!ha
Todate
a) INTONUM
This will !onvet the %ina7 value to its nu$ei!al euivalent5
S7nta/0 %intonu$( binary_bits)
'/0
SQL- sele!t %intonu$(2#2#3) fo$ dual.
INTONUM(2#2#3)
""""""""""""""""""""""""
If all the %its ae eo then it podu!es eo5
If all the %its ae null then it podu!es an eo5
%) C:RTORO6ID
56
-
8/18/2019 SQL for Beginers
57/278
This will !onvet a !haa!te sting to a!t li&e an intenal oa!le ow identifie o
owid5
!) RO6IDTOC:R
This will !onvet an intenal oa!le ow identifie o owid to !haa!te sting5
d) TONUM'R
This will !onvet a !ha o va!ha to nu$%e5
e) TOC:R
This will !onvet a nu$%e o date to !haa!te sting5
f) TODT'
This will !onvet a nu$%e# !ha o va!ha to a date5
8ROUA BUNCTIONS
Su$
vg
Ma/
Min
Count
8oup fun!tions will %e applied on all the ows %ut podu!es single output5
a) SUM
This will give the su$ of the values of the spe!ified !olu$n5
S7nta/0 su$ (column)
'/0
SQL- sele!t su$(sal) fo$ e$p.
SUM(SL)
""""""""""
4W33
%) 98
This will give the aveage of the values of the spe!ified !olu$n5
57
-
8/18/2019 SQL for Beginers
58/278
-
8/18/2019 SQL for Beginers
59/278
-
8/18/2019 SQL for Beginers
60/278
'ntit7 integit7 !onstaints
Ai$a7 &e7
Uniue
ARIMR* F'*
This is used to avoid dupli!ates and nulls5 This will wo& as !o$%ination of uniue and
not null5
Ai$a7 &e7 alwa7s atta!hed to the paent ta%le5
6e !an add this !onstaint in all thee levels5
'/0
COLUMN L'9'L
SQL- !eate ta%le student(no nu$%e(1) pi$a7 &e7# na$e va!ha(23)# $a&snu$%e(4)).
SQL- !eate ta%le student(no nu$%e(1) !onstaint p& pi$a7 &e7# na$e
va!ha(23)# $a&s nu$%e(4)).
TL' L'9'L
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
pi$a7 &e7(no)).
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
!onstaint
p& pi$a7 &e7(no)).
LT'R L'9'L
SQL- alte ta%le student add pi$a7 &e7(no).
SQL- alte ta%le student add !onstaint p& pi$a7 &e7(no).
UNIQU'0
This is used to avoid dupli!ates %ut it allow nulls5
6e !an add this !onstaint in all thee levels5
'/0
COLUMN L'9'L
60
-
8/18/2019 SQL for Beginers
61/278
-
8/18/2019 SQL for Beginers
62/278
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)
!he!& ($a&s - 433)).
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)
!onstaint !h !he!&($a&s - 433)).
TL' L'9'L
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
!he!& ($a&s - 433)).
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
!onstaint !h !he!&($a&s - 433)).
LT'R L'9'L
SQL- alte ta%le student add !he!&($a&s-433).
SQL- alte ta%le student add !onstaint !h !he!&($a&s-433).
Refeential integit7 !onstaints
Boeign &e7
BOR'I8N F'*
This is used to efeen!e the paent ta%le pi$a7 &e7 !olu$n whi!h allows dupli!ates5
Boeign &e7 alwa7s atta!hed to the !hild ta%le5
6e !an add this !onstaint in ta%le and alte levels onl75
'/0
TL' L'9'L
SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#
pi$a7 &e7(e$pno)# foeign &e7(deptno) efeen!es dept(deptno)).
SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#
!onstaint p& pi$a7 &e7(e$pno)# !onstaint f& foeign &e7(deptno) efeen!es
dept(deptno)).
LT'R L'9'L
62
-
8/18/2019 SQL for Beginers
63/278
SQL- alte ta%le e$p add foeign &e7(deptno) efeen!es dept(deptno).
SQL- alte ta%le e$p add !onstaint f& foeign &e7(deptno) efeen!es dept(deptno).
Note0
On!e the pi$a7 &e7 and foeign &e7 elationship has %een !eated then 7ou !an not
e$ove an7 paent e!od if the dependent !hilds e/ists5
USIN8 ON D'LT' CSCD'
7 using this !lause 7ou !an e$ove the paent e!od even it !hilds e/ists5
e!ause when eve 7ou e$ove paent e!od oa!le auto$ati!all7 e$oves all its
dependent e!ods fo$ !hild ta%le# if this !lause is pesent while !eating foeign &e7
!onstaint5
'/0
TL' L'9'L
SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#pi$a7 &e7(e$pno)# foeign &e7(deptno) efeen!es dept(deptno) on delete
!as!ade).
SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#
!onstaint p& pi$a7 &e7(e$pno)# !onstaint f& foeign &e7(deptno) efeen!es
dept(deptno) on delete !as!ade).
63
-
8/18/2019 SQL for Beginers
64/278
LT'R L'9'L
SQL- alte ta%le e$p add foeign &e7(deptno) efeen!es dept(deptno) on delete
!as!ade.
SQL- alte ta%le e$p add !onstaint f& foeign &e7(deptno) efeen!es dept(deptno)
on delete !as!ade.
COMAOSIT' F'*S
!o$posite &e7 !an %e defined on a !o$%ination of !olu$ns5
6e !an define !o$posite &e7s on entit7 integit7 and efeential integit7 !onstaints5
Co$posite &e7 !an %e defined in ta%le and alte levels onl75
'/0
UNIQU' (TL' L'9'L)
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
uniue(no#na$e)).
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
!onstaint un uniue(no#na$e)).
UNIQU' (LT'R L'9'L)
SQL- alte ta%le student add uniue(no#na$e).
SQL- alte ta%le student add !onstaint un uniue(no#na$e).
ARIMR* F'* (TL' L'9'L)
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
pi$a7 &e7(no#na$e)).
SQL- !eate ta%le student(no nu$%e(1) # na$e va!ha(23)# $a&s nu$%e(4)#
!onstaint p& pi$a7 &e7(no#na$e)).
ARIMR* F'* (LT'R L'9'L)
SQL- alte ta%le student add pi$a7 &e7(no#an$e).SQL- alte ta%le student add !onstaint p& pi$a7 &e7(no#na$e).
BOR'I8N F'* (TL' L'9'L)
SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#
dna$e va!ha(23)# pi$a7 &e7(e$pno)# foeign &e7(deptno#dna$e) efeen!es
64
-
8/18/2019 SQL for Beginers
65/278
dept(deptno#dna$e)).
SQL- !eate ta%le e$p(e$pno nu$%e(1)# ena$e va!ha(23)# deptno nu$%e(1)#
dna$e va!ha(23)# !onstaint p& pi$a7 &e7(e$pno)# !onstaint f& foeign
&e7(deptno#dna$e) efeen!es dept(deptno#dna$e)).
BOR'I8N F'* (LT'R L'9'L)
SQL- alte ta%le e$p add foeign &e7(deptno#dna$e) efeen!es
dept(deptno#dna$e).
SQL- alte ta%le e$p add !onstaint f& foeign &e7(deptno#dna$e) efeen!es
dept(deptno#dna$e).
D'B'RRL' CONSTRINTS0
'a!h !onstaint has two additional atti%utes to suppot defeed !he!&ing of
!onstaints5
Defeed initiall7 i$$ediate
Defeed initiall7 defeed
Defeed initiall7 i$$ediate !he!&s fo !onstaint violation at the ti$e of inset5
Defeed initiall7 defeed !he!&s fo !onstaint violation at the ti$e of !o$$it5
'/0
SQL- !eate ta%le student(no nu$%e(1)# na$e va!ha(23)# $a&s nu$%e(4)#
!onstaint un uniue(no) defeed initiall7 i$$ediate).
65
-
8/18/2019 SQL for Beginers
66/278
SQL- !eate ta%le student(no nu$%e(1)# na$e va!ha(23)# $a&s nu$%e(4)#
!onstaint un uniue(no) defeed initiall7 defeed).
SQL- alte ta%le student add !onstaint un uniue(no) defea%le initiall7 defeed.
SQL- set !onstaints all i$$ediate.
This will ena%le all the !onstaints violations at the ti$e of inseting5
SQL- set !onstaints all defeed.
This will ena%le all the !onstaints violations at the ti$e of !o$$it5
OA'RTIONS 6IT: CONSTRINTS
Aossi%le opeations with !onstaints as follows5
'na%le
Disa%le
'nfo!e
Dop
'NL'
This will ena%le the !onstaint5 efoe ena%le# the !onstaint will !he!& the e/isting
data5'/0
SQL- alte ta%le student ena%le !onstaint un.
DISL'
This will disa%le the !onstaint5
'/0
66
-
8/18/2019 SQL for Beginers
67/278
SQL- alte ta%le student ena%le !onstaint un.
'NBORC'
This will enfo!e the !onstaint athe than ena%le fo futue insets o updates5
This will not !he!& fo e/isting data while enfo!ing data5
'/0
SQL- alte ta%le student enfo!e !onstaint un.
DROA
This will e$ove the !onstaint5
'/0
SQL- alte ta%le student dop !onstaint un.
On!e the ta%le is dopped# !onstaints auto$ati!all7 will dop5
CS' ND D'BULT
CS'0
Case is si$ila to de!ode %ut easie to undestand while going though !oding
'/0
SQL- Sele!t sal#Case sal
6hen 33 then Klow;
6hen 333 then Khigh;
'lse K$ediu$;
'nd !ase
67
-
8/18/2019 SQL for Beginers
68/278
-
8/18/2019 SQL for Beginers
69/278
"""""" """""""""
2 a
22 %
SQL- inset into student values(null# K!;). SQL- sele!t E fo$ student.
NO NM'
"""""" """""""""
2 a
22 %
C
"" Default !an not oveide nulls5
STRCT DT T*A'S
So$e ti$es 7ou $a7 want t7pe whi!h holds all t7pes of data in!luding nu$%es# !has
and spe!ial !haa!tes so$ething li&e this5 *ou !an not a!hieve this using pe"defined
t7pes5
*ou !an define !usto$ t7pes whi!h holds 7ou desied data5
'/0
Suppose in a ta%le we have addess !olu$n whi!h holds hno and !it7 info$ation5
6e will define a !usto$ t7pe whi!h holds %oth nu$ei! as well as !ha data5
CR'TIN8 DT
SQL- !eate t7pe add as o%Je!t(hno nu$%e(4)#!it7 va!ha(23)).
CR'TIN8 TL' S'D ON DT
SQL- !eate ta%le student(no nu$%e(1)#na$e va!ha(1)#addess add).
69
-
8/18/2019 SQL for Beginers
70/278
INS'RTIN8 DT INTO DT TL'S
SQL- inset into student values(2#=a=#add(222#=h7d=)).
SQL- inset into student values(1#=%=#add(111#=%ang=)).
SQL- inset into student values(4#=!=#add(444#=delhi=)).
S'L'CTIN8 DT BROM DT TL'S
SQL- sele!t E fo$ student.
NO NM' DDR'SS(:NO# CIT*)
""" """"""" """""""""""""""""""""""""
2 a DDR(222# =h7d=)
1 % DDR(111# =%ang=)
4 ! DDR(444# =delhi=)
SQL- sele!t no#na$e#s5addess5hno#s5addess5!it7 fo$ student s.
NO NM' DDR'SS5:NO DDR'SS5CIT*
"""" """"""" """"""""""""""""" """"""""""""""""
2 a 222 h7d
1 % 111 %ang
4 ! 444 delhi
UADT' 6IT: DT TL'S
SQL- update student s set s5addess5!it7 H =%o$%a7= whee s5addess5hno H 444.
SQL- sele!t no#na$e#s5addess5hno#s5addess5!it7 fo$ student s.
NO NM' DDR'SS5:NO DDR'SS5CIT*
"""" """"""" """"""""""""""""" """"""""""""""""
2 a 222 h7d
1 % 111 %ang
4 ! 444 %o$%a7
D'L'T' 6IT: DT TL'S
SQL- delete student s whee s5addess5hno H 222.
SQL- sele!t no#na$e#s5addess5hno#s5addess5!it7 fo$ student s.
70
-
8/18/2019 SQL for Beginers
71/278
NO NM' DDR'SS5:NO DDR'SS5CIT*
"""" """"""" """"""""""""""""" """"""""""""""""
1 % 111 %ang
4 ! 444 %o$%a7
DROAAIN8 DT
SQL- dop t7pe add.
O>'CT 9I'6S ND M'T:ODS
O>'CT 9I'6S
If 7ou want to i$ple$ent o%Je!ts with the e/isting ta%le# o%Je!t views !o$e into
pi!tue5
*ou define the o%Je!t and !eate a view whi!h elates this o%Je!t to the e/isting ta%le
nothing %ut ob!ect view 5
O%Je!t views ae used to elate the use defined o%Je!ts to the e/isting ta%le5
'/02) ssu$e that the ta%le student has alead7 %een !eated with the following !olu$ns
SQL- !eate ta%le student(no nu$%e(1)#na$e va!ha(23)#hno nu$%e(4)#!it7
va!ha(23)).
1) Ceate the following t7pes
SQL- !eate t7pe add as o%Je!t(hno nu$%e(1)#!it7 va!ha(23)).?
71
-
8/18/2019 SQL for Beginers
72/278
SQL- !eate t7pe stud as o%Je!t(na$e va!ha(23)#addess add).?
4) Relate the o%Je!ts to the student ta%le %7 !eating the o%Je!t view
SQL- !eate view studentov(no#studinfo) as sele!t no#stud(na$e#add(hno#!it7))
fo$ student.
@) Now 7ou !an inset data into student ta%le in two wa7s
a) 7 egula inset
SQL- Inset into student values(2#;sudha;#222#;h7d;).
%) 7 using o%Je!t view
SQL- Inset into studentov values(2#stud(Ksudha;#add(222#;h7d;))).
M'T:ODS0
*ou !an define $ethods whi!h ae nothing %ut fun!tions in t7pes and appl7 in the
ta%les whi!h holds the t7pes.
'/0
2) Defining $ethods in t7pes
SQL- Ceate t7pe stud as o%Je!t(na$e va!ha(23)#$a&s nu$%e(4)#
Me$%e fun!tion $a&sf($a&s in nu$%e) etun nu$%e# Aag$a esti!tefeen!es($a&sf#wnds#nds#wnps#fnps)).?
1) Defining t7pe %od7
SQL- Ceate t7pe %od7 stud as
Me$%e fun!tion $a&sf($a&s in nu$%e) etun nu$%e is
egin
72
-
8/18/2019 SQL for Beginers
73/278
Retun ($a&sG233).
'nd $a&sf.
'nd.?
4) Ceate a ta%le using stud t7pe
SQL- Ceate ta%le student(no nu$%e(1)#info stud).
@) Inset so$e data into student ta%le
SQL- Inset into student values(2#stud(Ksudha;#233)).
) Using $ethod in sele!t
SQL- Sele!t s5info5$a&sf(s5info5$a&s) fo$ student s.
"" :ee we ae using the pag$a esti!tefeen!es to avoid the wites to the
data%ase5
9"RR*S ND N'ST'D TL'S
9"RR*S
va7ing aa7 allows 7ou to stoe epeating atti%utes of a e!od in a single ow %ut
with li$it5
'/0
2) 6e !an !eate vaa7s using oa!le t7pes as well as use defined t7pes5
a) 9aa7 using pe"defined t7pes SQL- Ceate t7pe va as vaa7() of va!ha(23).?
%) 9aa7s using use defined t7pes
SQL- Ceate t7pe add as o%Je!t(hno nu$%e(4)#!it7 va!ha(23)).?
SQL- Ceate t7pe va as vaa7() of add.?
1) Using vaa7 in ta%le
73
-
8/18/2019 SQL for Beginers
74/278
SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(23)#addess va).
4) Inseting values into vaa7 ta%le
SQL- Inset into student values(2#;sudha;#va(add(222#;h7d;))).
SQL- Inset into student values(1#;Jagan;#va(add(222#;h7d;)#add(111#;%ang;))).
@) Sele!ting data fo$ vaa7 ta%le
SQL- Sele!t E fo$ student.
"" This will displa7 vaa7 !olu$n data along with vaa7 and adt.
SQL- Sele!t no#na$e# s5E fo$ student s2# ta%le(s25addess) s.
"" This will displa7 in geneal fo$at
) Instead of s5E 7ou !an spe!if7 the !olu$ns in vaa7
SQL- Sele!t no#na$e# s5hno#s5!it7 fo$ student s2#ta%le(s25addess) s.
"" Update and delete not possi%le in vaa7s5
"" :ee we used ta%le fun!tion whi!h will ta&e the vaa7 !olu$n as input fo
podu!ing output e/!luding vaa7 and t7pes5
N'ST'D TL'S
nested ta%le is# as its na$e i$plies# a ta%le within a ta%le5 In this !ase it is a ta%le
that is epesented as a !olu$n within anothe ta%le5
Nested ta%le has the sa$e effe!t of vaa7s %ut has no li$it5
'/0
2) 6e !an !eate nested ta%les using oa!le t7pes and use defined t7pes whi!h has
no li$it
a) Nested ta%les using pe"defined t7pes
SQL- Ceate t7pe nt as ta%le of va!ha(23).?
%) Nested ta%les using use defined t7pes
SQL- Ceate t7pe add as o%Je!t(hno nu$%e(4)#!it7 va!ha(23)).?
SQL- Ceate t7pe nt as ta%le of add.?
1) Using nested ta%le in ta%le SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(23)#addess nt) nested
ta%le addess stoe as studentte$p.
4) Inseting values into ta%le whi!h has nested ta%le
SQL- Inset into student values (2#;sudha;#nt(add(222#;h7d;))).
SQL-Insetinto student values (1#;Jagan;#nt(add(222#;h7d;)#add(111#;%ang;))).
74
-
8/18/2019 SQL for Beginers
75/278
@) Sele!ting data fo$ ta%le whi!h has nested ta%le
SQL- Sele!t E fo$ student.
"" This will displa7 nested ta%le !olu$n data along with nested ta%le and adt.
SQL- Sele!t no#na$e# s5E fo$ student s2# ta%le(s25addess) s.
"" This will displa7 in geneal fo$at
) Instead of s5E 7ou !an spe!if7 the !olu$ns in nested ta%le
SQL- Sele!t no#na$e# s5hno#s5!it7 fo$ student s2#ta%le(s25addess) s.
) Inseting nested ta%le data to the e/isting ow
SQL- Inset into ta%le(sele!t addess fo$ student whee noH2)
values(add(#;!hennai;)).
V) Update in nested ta%les
SQL- Update ta%le(sele!t addess fo$ student whee noH1) s set s5!it7H;%o$%a7;
whee s5hno H 111.
W) Delete in nested ta%le
SQL- Delete ta%le(sele!t addess fo$ student whee noH4) s whee s5hnoH444.
DT MOD'L
LLCOLLT*A'S US'RCOLLT*A'S
US'RT*A'S LLT*A'S
DCOLLT*A'S DT*A'S
LS:CF QU'R*
Used to etieve the data whi!h has %een alead7 !o$$itted with out going fo
e!ove75
Blash%a!&s ae of two t7pes
Ti$e %ase flash%a!&
SCN %ased flash%a!& (SCN stands fo S7ste$ Change Nu$%e)
'/0
2) Using ti$e %ased flash%a!&
a) SQL- Sele!t Efo$ student. "" This will displa7 all the ows
%) SQL- Delete student.
!) SQL- Co$$it. "" this will !o$$it the wo&5
75
-
8/18/2019 SQL for Beginers
76/278
d) SQL- Sele!t Efo$ student. "" :ee it will displa7 nothing
e) Then e/e!ute the following po!edues
SQL- '/e! d%$sflash%a!&5ena%leatti$e(s7sdate"1?2@@3)
f) SQL- Sele!t Efo$ student.
"" :ee it will displa7 the lost data
"" The lost data will !o$e %ut the !uent s7ste$ ti$e was used
g) SQL- '/e! d%$sflash%a!&5disa%le
"" :ee we have to disa%le the flash%a!& to ena%le it again
1) Using SCN %ased flash%a!&
a) De!lae a vaia%le to stoe SCN
SQL- 9aia%le s nu$%e
%) 8et the SCN
SQL- '/e! 0s 0H e/e! d%$sflash%a!&5gets7ste$!hangenu$%e
!) To see the SCN
SQL- Aint s
d) Then e/e!ute the following po!edues
SQL- '/e! d%$sflash%a!&5ena%leats7ste$!hangenu$%e(0s)
SQL- '/e! d%$sflash%a!&5disa%le
'+T'RNL TL'S
*ou !an use e/tenal ta%le featue to a!!ess e/tenal files as if the7 ae ta%les inside
the data%ase5
6hen 7ou !eate an e/tenal ta%le# 7ou define its stu!tue and lo!ation with in oa!le5
6hen 7ou ue7 the ta%le# oa!le eads the e/tenal ta%le and etuns the esults Just
as if the data had %een stoed with in the data%ase5
CC'SSIN8 '+T'RNL TL' DT
To a!!ess e/tenal files fo$ within oa!le# 7ou $ust fist use the !eate die!to7
!o$$and to define a die!to7 o%Je!t pointing to the e/tenal file lo!ation
Uses who will a!!ess the e/tenal files $ust have the ead and wite pivilege on the
die!to75
'/0
76
-
8/18/2019 SQL for Beginers
77/278
CR'TIN8 DIR'CTOR* ND OS L'9'L BIL'
SQL- Slplus s7ste$?$anage
SQL- Ceate die!to7 saðdi as K?9isd%?visd%?5153?e/tenal;.
SQL- 8ant all on die!to7 saðdi to sað.
SQL- Conn sað?sað SQL- Spool dept5lst
SQL- Sele!t deptno XX K#; XX dna$e XX K#; XX lo! fo$ dept.
SQL- Spool off
CR'TIN8 '+T'RNL TL'
SQL- Ceate ta%le depte/t(deptno nu$%e(1)#Dna$e va!ha(2@)# Lo! va!ha(24))
Oganiation e/tenal ( t7pe oa!leloade
Default die!to7 saðdi
!!ess paa$etes
( e!ods deli$ited %7 newline
Bields te$inated %7 P#
( deptno nu$%e(1)#
Dna$e va!ha(2@)#
Lo! va!ha(24)))
Lo!ation (K?9isd%?visd%?5153?dept5lst;)).
S'L'CTIN8 DT BROM '+T'RNL TL'
SQL- sele!t E fo$ depte/t.
This will ead fo$ dept5lst whi!h is a opeating s7ste$ level file5
LIMITTIONS ON '+T'RNL TL'S
a) *ou !an not pefo$ inset# update# and delete opeations
a) Inde/ing not possi%le
%) Constaints not possi%le
'N'BITS OB '+T'RNL TL'S
77
-
8/18/2019 SQL for Beginers
78/278
a) Queies of e/tenal ta%les !o$plete ve7 ui!&l7 even though a full ta%le s!an id
euied with ea!h a!!ess
%) *ou !an Join e/tenal ta%les to ea!h othe o to standad ta%les
R'B D'R'B 9LU'
R'B
The ef fun!tion allows efeen!ing of e/isting ow o%Je!ts5
'a!h of the ow o%Je!ts has an o%Je!t id value assigned to it5
The o%Je!t id assigned !an %e seen %7 using ef fun!tion5
D'R'B
The deef fun!tion pefo$s opposite a!tion5
It ta&es a efeen!e value of o%Je!t id and etuns the value of the ow o%Je!ts5
78
-
8/18/2019 SQL for Beginers
79/278
9LU'
'ven though the pi$a7 ta%le is o%Je!t ta%le# still it displa7s the ows in geneal
fo$at5
To displa7 the entie stu!tue of the o%Je!t# this will %e used5
'/0
2) !eate vendotadt t7pe
SQL- Ceate t7pe vendoadt as o%Je!t (vendo!ode nu$%e(1)# vendona$e
va!ha(1)# vendoaddess va!ha(23)).?
1) !eate o%Je!t ta%les vendos and vendos2
SQL- Ceate ta%le vendos of vendoadt.
SQL- Ceate ta%le vendos2 of vendoadt.
4) inset the data into o%Je!t ta%les
SQL- inset into vendos values(2# Ka;# Kh7d;).
SQL- inset into vendos values(1# K%;# K%ang;).
SQL- inset into vendos2 values(4# K!;# Kdelhi;).
SQL- inset into vendos2 values(@# Kd;# K!hennai;).
@) !eate anothe ta%le odes whi!h holds the vendoadt t7pe also5
SQL- Ceate ta%le odes (odeno nu$%e(1)# vendoinfo ef vendoadt).
O
SQL- Ceate ta%le odes (odeno nu$%e(1)# vendoinfo ef vendoadt with
owid).
) inset the data into odes ta%le
The vendoinfo !olu$n in the following s7nta/es will stoe o%Je!t id of an7 ta%le
whi!h is efeen!ed %7 vendoadt o%Je!t ( %oth vendos and vendos2)5
SQL- inset into odes values(22#(sele!t ef(v) fo$ vendos v whee
vendo!ode H 2)).
SQL- inset into odes values(21#(sele!t ef(v) fo$ vendos v whee
vendo!ode H 1)).
SQL- inset into odes values(24#(sele!t ef(v2) fo$ vendos2 v2 whee
vendo!ode H2)).
SQL- inset into odes values(2@#(sele!t ef(v2) fo$ vendos2 v2 whee
vendo!ode H 2)).
) To see the o%Je!t ids of vendo ta%le
SQL- Sele!t ef(9) fo$ vendos v.
79
-
8/18/2019 SQL for Beginers
80/278
V) If 7ou see the vendoinfo of odes it will show onl7 the o%Je!t ids not the
values# to see the values
SQL- Sele!t deef(o5vendoinfo) fo$ odes o.
W) 'ven though the vendos ta%le is o%Je!t ta%le it will not show the adt along with
data# to see the data along with the adt
SQL-Sele!t E fo$ vendos.
This will give the data without adt5
SQL-Sele!t value(v) fo$ vendos v.
This will give the !olu$ns data along wih the t7pe5
R'B CONSTRINTS
Ref !an also a!ts as !onstaint5'ven though vendos2 also holding vendoadt# the odes ta%le will stoe the o%Je!t
ids of vendos onl7 %e!ause it is !onstained to that ta%le onl75
The vendoinfo !olu$n in the following s7nta/es will stoe o%Je!t ids of vendos onl75
SQL- Ceate ta%le odes (odeno nu$%e(1)# vendoinfo ef vendoadt s!ope is
vendos).
O
SQL- Ceate ta%le odes (odeno nu$%e(1)# vendoinfo ef vendoadt !onstaint
f& efeen!es vendos).
O>'CT 9I'6S 6IT: R'B'R'NC'S
To i$ple$ent the o%Je!ts and the ef !onstaints to the e/isting ta%les# what we !an
do[ Si$pl7 dop the %oth ta%les and e!eate with o%Je!ts and ef !onstains5
ut 7ou !an a!hieve this with out dopping the ta%les and without losing the data %7
!eating o%Je!t views with efeen!es5
'/0
a) Ceate the following ta%les
SQL-Ceate ta%le student2(no nu$%e(1) pi$a7 &e7#na$e va!ha(1)#$a&s
nu$%e(4)).
SQL-Ceate ta%le student1(no nu$%e(1) pi$a7 &e7#hno nu$%e(4)#!it7
va!ha(23)#id nu$%e(1)#foeign Fe7(id) efeen!es student2(no)).
80
-
8/18/2019 SQL for Beginers
81/278
%) Inset the e!ods into %oth ta%les
SQL- inset into student2(2#;a;#233).
SQL- inset into student2(1#;%;#133).
SQL- inset into student1(22#222#;h7d;#2).
SQL- inset into student1(21#111#;%ang;#1).
SQL- inset into student1(24#444#;%o$%a7;#2).
!) Ceate the t7pe
SQL- !eate o epla!e t7pe stud as o%Je!t(no nu$%e(1)#na$e va!ha(1)#
$a&s nu$%e(4)).?
d) 8eneating OIDs
SQL- Ceate o epla!e view student2ov of stud with o%Je!t identifie(o id) (no)
as Sele!t E fo$ Student2.
e) 8eneating efeen!es
SQL-Ceate o epla!e view student1ov as sele!t
no#hno#!it7#$a&eef(student2ov#id) id fo$ Student1.
d) Que7 the following
SQL- sele!t Efo$ student2ov.
SQL- sele!t ef(s) fo$ student2ov s.
SQL- sele!t values(s) fo$ student2ov.
SQ- sele!t Efo$ student1ov.
SQL- sele!t deef(s5id) fo$ student1ov s.
ARTITIONS
single logi!al ta%le !an %e split into a nu$%e of ph7si!all7 sepaate pie!es %ased on
anges of &e7 values5 'a!h of the pats of the ta%le is !alled a patition5
non"patitioned ta%le !an not %e patitioned late5
T*A'S
Range patitions
List patitions
:ash patitions
Su% patitions
D9NT8'S
81
-
8/18/2019 SQL for Beginers
82/278
Redu!ing downti$e fo s!heduled $aintenan!e# whi!h allows $aintenan!e
opeations to %e !aied out on sele!ted patitions while othe patitions ae
availa%le to uses5
Redu!ing downti$e due to data failue# failue of a pati!ula patition will no
wa7 affe!t othe patitions5
Aatition independen!e allows fo !on!uent use of the vaious patitions fo
vaious puposes5
D9NT8'S OB ARTITIONS * STORIN8 T:'M IN DIBB'R'NT TL'SAC'S
Redu!es the possi%ilit7 of data !ouption in $ultiple patitions5
a!& up and e!ove7 of ea!h patition !an %e done independentl75
DISD9NT8'S
Aatitioned ta%les !annot !ontain an7 !olu$ns with long o long aw datat7pes#
LO t7pes o o%Je!t t7pes5
RN8' ARTITIONS
a) Ceating ange patitioned ta%le
SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(1)) patition %7 ange(no)
(patition p2 values less than(23)# patition p1 values less than(13)# patition p4
values less than(43)#patition p@ values less than($a/value)).
EE if 7ou ae using $a/value fo the last patition# 7ou !an not add a patition5
%) Inseting e!ods into ange patitioned ta%le
SQL- Inset into student values(2#;a;). "" this will go to p2
SQL- Inset into student values(22#;%;). "" this will go to p1
SQL- Inset into student values(12#;!;). "" this will go to p4
SQL- Inset into student values(42#;d;). "" this will go to p@
!) Retieving e!ods fo$ ange patitioned ta%le
SQL- Sele!t Efo$ student.
SQL- Sele!t Efo$ student patition(p2).
82
-
8/18/2019 SQL for Beginers
83/278
d) Aossi%le opeations with ange patitions
dd Split
Dop Move
Tun!ate '/!hange
Rena$e
e) dding a patition
SQL- lte ta%le student add patition p values less than(@3).
f) Dopping a patition
SQL- lte ta%le student dop patition p@.
g) Rena$ing a patition
SQL- lte ta%le student ena$e patition p4 to p.
h) Tun!ate a patition
SQL- lte ta%le student tun!ate patition p.
i) Splitting a patition
SQL- lte ta%le student split patition p1 at(2) into (patition p12#patition p11).
J) '/!hanging a patition
SQL- lte ta%le student e/!hange patition p2 with ta%le student1.
&) Moving a patition
SQL- lte ta%le student $ove patition p12 ta%lespa!e saðts.
LIST ARTITIONS
a) Ceating list patitioned ta%le
SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(1)) patition %7 list(no)
(patition p2 values(2#1#4#@#)# patition p1 values(#V#W##23)#patition p4
values(22#21#24#2@#2)#patition p@ values(2#2V#2W#2#13)).
%) Inseting e!ods into list patitioned ta%le
SQL- Inset into student values(2#;a;). "" this will go to p2
SQL- Inset into student values(#;%;). "" this will go to p1
SQL- Inset into student values(22#;!;). "" this will go to p4
SQL- Inset into student values(2#;d;). "" this will go to p@
!) Retieving e!ods fo$ list patitioned ta%le
SQL- Sele!t Efo$ student.
SQL- Sele!t Efo$ student patition(p2).
d) Aossi%le opeations with list patitions
83
-
8/18/2019 SQL for Beginers
84/278
dd
Dop
Tun!ate
Rena$e
Move
'/!hange
e) dding a patition
SQL- lte ta%le student add patition p values(12#11#14#1@#1).
f) Dopping a patition
SQL- lte ta%le student dop patition p@.
g) Rena$ing a patition
SQL- lte ta%le student ena$e patition p4 to p.
h) Tun!ate a patition
SQL- lte ta%le student tun!ate patition p.
i) '/!hanging a patition
SQL- lte ta%le student e/!hange patition p2 with ta%le student1.
J) Moving a patition
SQL- lte ta%le student $ove patition p1 ta%lespa!e saðts.
:S: ARTITIONS
a) Ceating hash patitioned ta%le
SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(1)) patition %7 hash(no)
patitions .
:ee oa!le auto$ati!all7 gives patition na$es li&e
S*SA2
S*SA1
S*SA4
S*SA@
S*SA
%) Inseting e!ods into hash patitioned ta%le
It will inset the e!ods %ased on hash fun!tion !al!ulated %7 ta&ing the patition &e7
SQL- Inset into student values(2#;a;).
SQL- Inset into student values(#;%;).
84
-
8/18/2019 SQL for Beginers
85/278
SQL- Inset into student values(22#;!;).
SQL- Inset into student values(2#;d;).
!) Retieving e!ods fo$ hash patitioned ta%le
SQL- Sele!t Efo$ student.
SQL- Sele!t Efo$ student patition(s7sp2).
d) Aossi%le opeations with hash patitions
dd
Tun!ate
Rena$e
Move
'/!hange
e) dding a patition
SQL- lte ta%le student add patition p .
f) Rena$ing a patition
SQL- lte ta%le student ena$e patition p to pV.
g) Tun!ate a patition
SQL- lte ta%le student tun!ate patition pV.
h) '/!hanging a patition
SQL- lte ta%le student e/!hange patition s7sp2 with ta%le student1.
i) Moving a patition
SQL- lte ta%le student $ove patition s7sp1 ta%lespa!e saðts.
SU"ARTITIONS 6IT: RN8' ND :S:
Su%patitions !lause is used %7 hash onl75 6e !an not !eate su%patitions with list and
hash patitions5
a) Ceating su%patitioned ta%le
SQL- Ceate ta%le student(no nu$%e(1)#na$e va!ha(1)#$a&s nu$%e(4))
Aatition %7 ange(no) su%patition %7 hash(na$e) su%patitions 4
(Aatition p2 values less than(23)#patition p1 values less than(13)).
This will !eate two patitions p2 and p1 with thee su%patitions fo ea!h patition
A2 \ S*SSUA2 A1 \ S*SSUA@
S*SSUA1 S*SSUA
S*SSUA4 S*SSUA
EE if 7ou ae using $a/value fo the last patition# 7ou !an not add a patition5
%) Inseting e!ods into su%patitioned ta%le
85
-
8/18/2019 SQL for Beginers
86/278
SQL- Inset into student values(2#;a;). "" this will go to p2
SQL- Inset into student values(22#;%;). "" this will go to p1
!) Retieving e!ods fo$ su%patitioned ta%le
SQL- Sele!t Efo$ student.
SQL- Sele!t Efo$ student patition(p2).
SQL- Sele!t Efo$ student su%patition(s7ssu%p2).
d) Aossi%le opeations with su%patitions
dd Rena$e
Dop Split
Tun