Oracle SQL training in Kochi| Trivandrum | Thrissur
-
Upload
indiaoptions -
Category
Documents
-
view
225 -
download
0
Transcript of Oracle SQL training in Kochi| Trivandrum | Thrissur
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
1/65
ISO 9001 : 2008 Certifed Company
THRISSUR KOCHI
TRIVANDRUM
www.facebook.com/indiaoption
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
2/65
Only Authorised Oracle Training Partner in
Kerala
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
3/65
SQL *Plus
This is a tool of Oracle which supports
SQL ( A language developed by I!" #$$%&
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
4/65
SQL 'oands
))L ()ATA)+I,ITIO,LA,-.A-"
)!L ()ATA!A,IP.LATO,LA,-.A-"
T'L (T/A,SA'TIO,'O,T/OLLA,-.A-"
)'L ()ATA'O,T/OLLA-.A-"
CRAT !"#RT CO$$!T %RA"T
A&TR #&CT RO&&'ACK R(OK
TR)"CAT )P*AT #A(PO!"T
*ROP *&T
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
5/65
asic )ata Types
,.!/
,ueric values with or with out decial points&g&
SALA/0 ,.!/(1"2
'O!!ISSIO, ,.!/(345"2
'6A/
Accepts alphanueric type of data& Its si7e is predefinedand doesn8t vary according to input&
g
,A! '6A/(5$"2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
6/65
)ata Types (contd"
9A/'6A/
Accepts alphanueric type of data& Its si7e is predefined andvaries according to input&
g ,A! 9A/'6A/(5$"2
)AT )ate type of data& )ate forat should be )):!O,:0000&
g& )O; )AT2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
7/65
'/AT
This is used to create a table&
Synta
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
8/65
)S'
To display the structure of the table&
Synta
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
9/65
ALT/
To change the structure of the table&
g to increase the si7e of a colun&
ALT/ TAL !P !O)I+0 ,A! 9A/'6A/ (5C"2
,ote=)o not reduce the si7e of the data type&
g= +or adding a new colun
ALT/ TAL !P A)) 'O!!ISSIO, ,.!/ (345"2
g to reove an e
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
10/65
I,S/T
To insert records (rows" into a table.SyntaTAL ,A!? 9AL.S ('OL# 9AL.4'OL5 9AL.4 @&&"
g=
I,S/T I,TO !P 9AL.S(#48A,.848!A,A-/848$5:AP/:5$$$84B$$$$"2
,ote= nsure that non nueric data are enclosed in single Duotes&
g for inserting ultiple values
I,S/T I,TO !P 9AL.S(E,O48E,A!848E)-,848E)O;84ESAL"2
,ote&
0ou will be asFed to enter records one by one& After entering all the records
you ay give a G and press nter Fey so that you can Feep on inserting records&
I,S/TI,- ,.LL 9AL.
g to insert null value to the colun SAL
I,S/T I,TO !P (,O4,A!4)-,4)O;" 9AL.S (#48;O0848'L/H848$#:
!A/:5$#8"2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
11/65
SL'T
To retrieve records fro a table.
Synta
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
12/65
SL'T ( contd"
SL'T * +/O! !P K6/ SAL TK, #$$$$ A,) 5$$$$2
SL'T * +/O! !P K6/ SAL ,OT TK, #$$$$ A,) 5$$$$2
SL'T * +/O! !P K6/ )-, I, (N!A,A-/848'L/H8"2
SL'T * +/O! !P K6/ )-, ,OT I, (N!A,A-/848'L/H8"2
SL'T * +/O! !P K6/ ,A! LIH (N%8"2
SL'T ,O4 ,A!4 SAL*#5 AS A,,.AL SALA/0 +/O! !P2
SL'T S0S)AT +/O! ).AL 2 ().AL is a syste table"
SL'T * +/O! TA 2 (To display all tables4 views4 synonys created by the
current user"
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
13/65
.P)AT
To change the records of a table&
SyntaTAL ,A!? ST 'OL.!, ,A!M,K 9AL.
JK6/ 'LA.S
g=
.P)AT !P ST ,A! M NA/., H.!A/8 K6/ ,A! M NA/.,82
.P)AT !P ST SAL M SAL #$$$2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
14/65
)LT
To reove records fro table&
SyntaTAL ,A!? JK6/ 'LA.S
g=
)LT +/O! !P K6/ ,O M #52
,ote=
If you do not give any condition4 all the records will get deleted&
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
15/65
T/.,'AT
This will delete all the records fro table&
Synta
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
16/65
)/OP
This will reove the table itself&
SyntaTAL ,A!?
g=
)/OP TAL !P2
'O!!IT
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
17/65
'O!!IT
This will save changes(I,S/T4 .P)AT4 )LT" peranently to the
database server& Khen you aFe an e
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
18/65
-/A,T
To grant privileges (I,S/T4SL'T4 .P)AT4)LT" to other
users&
SyntaP/I9IL- LIST? O, >TAL ,A!? TO >.S/ ,A!?
g&
-/A,T I,S/T4 SL'T O, !P TO S'OTT2
-/A,T ALL O, !P TO S'OTT2 (ALL eans )!L coands"
-/A,TI,- P/I9IL-S KIT6 -/A,T OPTIO,
6ere the other user can grant privileges to soe other users&
g&
-/A,T ALL O, !P TO S'OTT KIT6 -/A,T OPTIO,2/9OH
This will taFe bacF the privileges fro the other user2
g&
/9OH .P)AT4 )LT O, !P +/O! S'OTT2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
19/65
O/)/ 0
To sort the records in ascending or descending order&
g=
SL'T * +/O! !P O/)/ 0 ,A!2
SL'T * +/O! !P O/)/ 0 ,A! )S'2 (+ordisplaying in descending order"
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
20/65
SQL * Plus +unctions
#& )ate functions
5& 'haracter functions
& ,ueric functions
& 'onversion functions
C& !iscellaneous functions
1& -roup functions
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
21/65
)ate functions
SL'T A))R!O,T6S (S0S)AT4 " +/O! ).AL2
SL'T !O,T6SRTK, (N##:SP:5$##84 8##:+:5$##8" +/O! ).AL2
SL'T !O,T6SRTK, (S0S)AT4 )O;"G#5 +/O! !PLO02
SL'T /O.,) (S0S)AT4 80A/8" +/O! ).AL2
SL'T /O.,)(S0S)AT4 8!O,T68" +/O! ).AL2
SL'T /O.,) (S0S)AT4 8)A08" +/O! ).AL2 (/ounds the date to thenearest Sunday"&
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
22/65
'haracter functions
SL'T .PP/ (,A!" +/O! !PLO02
SL'T LOK/ (,A!" +/O! !PLO02
SL'T I,IT'AP (,A!" +/O! !PLO02
SL'T /PLA' (N-OO) !O/,I,-84 8-OO)84 8A)8" +/O! ).AL2
SL'T S.ST/ (N-OO) !O/,I,-84#4" +/O! ).AL2
SL'T 'O,'AT (N6LLO848 KO/L)8" +/O! ).AL2
SL'T L,-T6 (N6AI8" +/O! ).AL2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
23/65
,ueric functionsSL'T AS (:#$$" +/O! ).AL2
SL'T /O.,) (#1&1" +/O! ).AL2
SL'T /O.,) (#1&5345" +/O! ).AL2
SL'T 'IL (&1" +/O! ).AL2
SL'T +LOO/ (#5&1" +/O! ).AL2
SL'T SQ/T (#1" +/O! ).AL2
SL'T POK/ (54" +/O! ).AL2
SL'T !O) (##45" +/O! ).AL2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
24/65
'onversion functionsTOR'6A/( "
'onverts date type data to character type data&g&
SL'T TOR'6A/ (S0S)AT4 8!!:)):00008 +/O! ).AL2
SL'T TOR'6A/ (S0S)AT4 8)):!!:00008 +/O! ).AL2
SL'T TOR'6A/ (S0S)AT4 8)A08 +/O! ).AL2
TOR)AT( "'onverts character type data to Oracle8s date forat&
g&
SL'T TOR)AT (8$1:$:5$#584 8!!:)):00008" +/O! ).AL2
TOR,.!/( "
'onverts character type data to nuber&
g&
SL'T TOR,.!/(N#$$8" +/O! ).AL2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
25/65
!iscellaneousfunctions
SL'T .S/ +/O! ).AL2
SL'T .I) +/O! ).AL2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
26/65
-/O.P +.,'TIO,S
SL'T !A (SAL" +/O! !P2
SL'T !I, (SAL" +/O! !P2
SL'T S.! (SAL" +/O! !P2
SL'T A9- (SAL" +/O! !P2
SL'T 'O.,T(,A!" +/O! !P2
SL'T 'O.,T (*" +/O! !P2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
27/65
-/O.P 0
To group the records of a table&
g= for counting no of eployees in each departent (colunnae is deptno"
g=
SL'T )PT,O4 'O.,T( *" +/O! !P -/O.P 0 )PT,O2
SL'T )PT,O4 A9-(SAL" +/O! !P -/O.P 0 )PT,O2
A -
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
28/65
6A9I,-
To give a condition for a -/O.P 0stateent&
g=
+or displaying only those deptno with ore than C people&
SL'T )PT,O4 'O.,T (*" +/O! !P -/O.P 0 )PT,O
6A9I,- 'O.,T (*" ? C2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
29/65
;OI,
)isplaying records fro ore than one table& Thereshould be a coon colun with the sae data type and
si7e&
T0PS O+ ;OI,
#& I,,/ ;OI,5& O.T/ ;OI,
& SL+ ;OI,
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
30/65
O.T/ ;OI, can be classified into
types& L+T O.T/ ;OI,
/I-6T O.T/ ;OI,
+.LL O.T/ ;OI,
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
31/65
I,,/ ;OI,
This will display only atching (coon" records fro two
tables&
g=
SL'T )PT&)PT,O4 ),A!4 ,A!4 SAL4 !P&)PT,O
+/O! )PT I,,/ ;OI, !P O, )PT&)PT,O M!P&)PT,O2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
32/65
L+T O.T/ ;OI,
This will display all the records fro the left table onlyatching records fro the right table&
g=
SL'T )PT&)PT,O4 ),A!4 ,A!4 SAL4 !P&)PT,O+/O! )PT L+T O.T/ ;OI, !P O, )PT&)PT,O M
!P&)PT,O2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
33/65
/I-6T O.T/ ;OI,
Opposite to L+T O.T/ ;OI,
g=
SL'T )PT&)PT,O4 ),A!4 ,A!4 SAL4 !P&)PT,O
+/O! )PT /I-6T O.T/ ;OI, !P O, )PT&)PT,O M
!P&)PT,O2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
34/65
+.LL O.T/ ;OI,
This will display all the records fro both the tables
g=
SL'T )PT&)PT,O4 ),A!4 ,A!4 SAL4 !P&)PT,O +/O!
)PT +.LL O.T/ ;OI, !P O, )PT&)PT,O M !P&)PT,O2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
35/65
SL+ ;OI,
;oining a table to itself is called SL+ ;OI,&
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
36/65
Dui ;oin
Siilar to Inner oin& ;oining two tables using eDual to operator
is called eDui oin&
g.SL'T )PT&)PT,O4 ),A!4 ,A!4 SAL4 !P&)PT,O
+/O! )PT4 !P K6/ )PT&)PT,O M !P&)PT,O2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
37/65
,on Dui oin
;oining two tables using an operator other than eDual to
operator is called non eDui oin&
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
38/65
ST OP/ATO/S
This will cobine the results of two Dueries& oth Dueriesshould have the sae structure& There types of Set
operators&
#& .,IO,5& .,IO, ALL
& I,T/S'T
& !I,.S
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
39/65
.,IO,
This will display records fro both the Dueries e
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
40/65
.,IO, ALL
This will display all the records fro both the Dueries
including duplicate records&
g=
SL'T * +/O! ST.)# .,IO, ALL SL'T * +/O! ST.)52
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
41/65
I,T/S'T
This will display only coon records fro both the Dueries.g&
SL'T * +/O! ST.)# I,T/S'T SL'T * +/O! ST.)52
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
42/65
!I,.S
This will display distinctive records fro the first Duery only&
g.SL'T * +/O! ST.)# !I,.S SL'T * +/O! ST.)52
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
43/65
'O,ST/AI,TS
Specifies soe restrictions on the table& nsures data integrity&
'onstraints are classified into types&
#& )oain constraints
5& ntity constraints
& /eferential integrity constraints
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
44/65
)O!AI, 'O,ST/AI,TS
,ot null constraint
'hecF constraint
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
45/65
,OT ,.LL 'O,ST/AI,T
)oes not accept null value&
g=
'/AT TAL !P (,O ,.!/(" 'O,ST/AI,T
!PR,OR,, ,OT ,.LL4 ,A! 9A/'6A/ (5$"4 SAL ,.!/(1""2
0ou ay give the following coand to checF weather ,OT ,.LL
constraint is worFing&
I,S/T I,TO !P (,A!4 SAL" 9AL.S (N;OS845$$$$"2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
46/65
'6'H 'O,ST/AI,T
Specifies a condition&
g=
'/AT TAL !P (,O ,.!/("4 ,A! 9A/'6A/ (5$"4 SAL
,.!/ (1" 'O,ST/AI,T !PRSALR'H '6'H (SAL TK,
$$$ A,) B$$$$""2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
47/65
,TIT0 'O,ST/AI,TS
.,IQ. 'O,ST/AI,T P/I!A/0 H0 'O,ST/AI,T
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
48/65
.,IQ. 'O,ST/AI,T
)oes not accept duplicate values4 but will accept null value&
g=
'/AT TAL !P (,O ,.!/(" 'O,ST/AI,T
!PR.H .,IQ.4 ,A! 9A/'6A/ (5$"4 SAL ,.!/ (1""2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
49/65
P/I!A/0 H0 'O,ST/AI,T
This constraint will not accept duplicate or null values&
Table created with this constraint is called parent table or
aster table which can be referenced by other tables& There
can be only one priary Fey constraint for a table&
g=
'/AT TAL )PT ()PT,O ,.!/(5" 'O,ST/AI,T
)PTRPH P/I!A/0 H04 ),A! 9A/'6A/ (5$""2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
50/65
/+/,TIAL I,T-/IT0
'O,ST/AI,TS
+O/I-, H0 'O,ST/AI,T
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
51/65
+O/I-, H0 'O,ST/AI,T
Table created with this constraint can be called child table&
g=
'/AT TAL !P (,O ,.!/("4 ,A! 9A/'6A/ ($"4 SAL
,.!/ (1"4 )PT,O ,.!/(5" /+/,'S )PT ()PT,O""2
,ote=
nsure that the priary Fey colun of the parent table and foreign Fey
colun of the child table have the sae data type and si7e&
Khile inserting records into the child table8s foreign Fey colun4 ensure
that the record e
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
52/65
O, )LT 'AS'A)
If you givethis coand along with a foreign Feydeclaration4 it becoes possible to delete a parent table record
even if it has corresponding records in the child table& Khat
happens is that along with the parent table record4
corresponding records fro the child table also get deleted&
g+
'/AT TAL !P (,O ,.!/("4 ,A! 9A/'6A/ (5$"4
SAL ,.!/ (1"4 )PT,O ,.!/(5" /+/,'S )PT
()PT,O" O, )LT 'AS'A)"2
S. Q./0
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
53/65
S. Q./0
Query inside a Duery (select stateent" is called Sub Duery& This will
iprove perforance because it reduces the networF traffic&g to find eployee details whose designation is sae as that of 6A/I&
SL'T * +/O! !PLO0 K6/ )-, M (SL'T )-,
+/O! !PLO0 K6/ ,A! M N6A/I8"2
SL'T * +/O! !PLO0 K6/ SAL ? (SL'T A9- (SAL"+/O! !PLO0"2
g to find out second highest salary&
SL'T !A (SAL" +/O! !PLO0 K6/ SAL
,OT I, (SL'T !A (SAL" +/O! !PLO0"2
!.LTIPL S. Q./0
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
54/65
!.LTIPL S. Q./0
g=
SL'T * +/O! !PLO0 K6/ )-, I, (SL'T )-,+/O! !PLO0 K6/ ,A! M N6A/I8" A,) SAL M (SL'T
SAL +/O! !PLO0 K6/ ,A! M NS!A8"2
,ote 0ou can club any no of Dueries liFe this using NA,)8
operator or NO/8 operator&
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
55/65
!.LTIL9L S.Q./0
Sub Duery inside a sub Duery is called !ultilevel sub Duery&
g to display details of the eployee who gets the second
highest salary&
SL'T ,O4 ,A!4 SAL +/O! !PLO0 K6/SAL I, (SL'T !A (SAL" +/O! !PLO0 K6/ SAL
,OT I, (SL'T !A (SAL" +/O! !PLO0""2
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
56/65
'O//LAT) S.Q./0
It is a type of sub Duery which is e
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
57/65
OT6/ )ATAAS O;'TS
#& S0,O,0!
5& 9IK
& SQ.,'
& I,)
S0,O,0!
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
58/65
S0,O,0!
Synony is liFe a duplicate table which is created on a table&
Khatever changes ()!L coands" you aFe in a synony will be reflected
in the associated table also&
Synta
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
59/65
9IK
9iew can be defined as a virtual table which is created by
using a Duery& Khatever changes you aFe in a view will bereflected on the associated table also&
Synta
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
60/65
9IK (contd"
'hanging colun naes in a viewg=
'/AT 9IK !P9 (!P,O4 )SI-,ATIO,4 SALA/0" AS SL'T ,O4
)-,4 SAL +/O! !PLO0 K6/ )PT,O M 5$2
)/OPPI,- A 9IK
g
)/OP 9IK !P92
SQ.,'
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
61/65
SQ.,'
SeDuence is used to generate uniDue integer values&
g.'/AT SQ.,' SS I,'/!,T 0 # !A9AL. #$
!I,9AL. #2
,ote&
Assue that you have a table called stud which has asingle colun rollno (data type nuber(""& ,ow we ay
insert records into this table using the seDuence which we
have created&
SQ.,' ('ontd"
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
62/65
SQ.,' ('ontd"
g&
I,S/T I,TO ST.) 9AL.S (SS&,T9AL"2Then type G to repeat the process&
I,S/T I,TO ST.) 9AL.S (SS&'.//9AL"2
g&
'/AT SQ.,' SS STA/T KIT6 1 I,'/!,T 0 #
!A9AL. #$ !I,9AL. # '0'L 'A'6 32
)/OPPI,- A SQ.,'
g
)/OP SQ.,' SS2
I,)
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
63/65
I,)
Inde< is a database obect which is created on a table or view& /ecords are
stored in a sorted order& It is not possible to open an IndeI,) ,A!? O, >TAL ,A!? ('OL.!, ,A!"
-=
'/AT I,) !P O, !PL (,O"2
'/AT I,) !P O, !PL (,O" /9/S2
'O!POSIT I,)
Specifying for than one colun in an inde< is called 'O!POSIT I,)&g=
'/AT I,) !P O, !PL( ,O4,A!"2
I,) (contd"
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
64/65
I,) (contd"
.,IQ. I,)
This type of Inde< can8t be created on a table which has duplicate
records in the Fey colun (colun to be inde
-
7/23/2019 Oracle SQL training in Kochi| Trivandrum | Thrissur
65/65
ThanF 0ou