At the end of this unit, you will be able to • Lea!n to "!eate, alte! and d!o# database ob$e"ts • • Lea!n to inse!t , u#date and delete data Lea!n to %!ant and !e&o'e #!i&ile%es

• • • •

Data Definition (tate)ents Data Mai#ulation (tate)ents Data Cont!ol (tate)ents T!ansa"tion Con!ol (tate)ents



Datatypes in Oracle
,a"h "olu)n &alue of a table in O!a"le has a dataty#e* The dataty#e asso"iates a fi-ed set of #!o#e!ties with the &alue and defines the do)ain of &alues that ea"h "olu)n "an "ontain* These #!o#e!ties "ause O!a"le to t!eat &alues of one dataty#e diffe!ently f!o) &alues of anothe!* The followin% dataty#es a!e a&ailable in O!a"le* Datatype CHAR(size) VARCHAR2(size) NUM !R(p"s) DAT! #ON$ #ON$ RA% RA%(size) RO%&D Description (to!es fi-ed len%th "ha!a"te! data* Ma-i)u) si.e is +///* Default si.e is 1 byte* (to!es &a!iable len%th "ha!a"te! st!in%s ha&in% )a-i)u) si.e of 0/// bytes* 1ou )ust s#e"ify si.e fo! a 2ARC3AR+* (to!es nu)be! ha&in% #!e"ision # and s"ale s, # "an !an%e f!o) 1 to 45 and s dete!)ines the nu)be! of di%its to the !i%ht of the de"i)al #oint* (to!es data and ti)e &alues between /1-/1-061+ 7C and /1-1+-061+ AD (to!es la!%e,&a!iable len%th st!in%s,u# to + %i%abytes* (to!es lon% bina!y st!in%s, u# to + %i%abytes* (to!es s)all bina!y st!in%s,less than +/// bytes* (to!es he-ade"i)al RO8ID &alues that "o!!es#ond to O!a"le table RO8ID(*9blo"'*!ow*file:

Data De'inition (tate)ents
Data definition state)ents CR,AT,,ALT,R and DROP a!e used to "!eate new ob$e"ts, alte! the st!u"tu!es of e-istin% ob$e"ts, o! "o)#letely !e)o&e ob$e"ts f!o) the database* Constraints Const!aints a!e #a!t of a table definition that li)it the &alues you "an ente! into its "olu)ns* Till now the only !est!i"tion on &alues that you "ould ente! has been on the dataty#es and of the &alues ente!ed whi"h ha&e to be "o)#atible with those of the "olu)ns into whi"h the &alues a!e bein% #la"ed* 8hen you "!eate a table you "an #la"e "onst!aints on the &alues that "an be ente!ed into its fields; by doin% this (<L will !e$e"t any &alues that &iolate the "!ite!ia you define* Two basi" ty#es of "onst!aints a!e "olu)n "onsta!ints = whi"h a##ly only to indi&idual "olu)ns and table "onst!aints = a##ly to %!ou#s of one o! )o!e "olu)ns*

The UNI<U.AU#T val/es . we say that the fi!st field 9@OR.1: !efe!n"es the se"ond field9PAR. they a!e defined in the sa)e way as "olu)n "onst!aints.NT ?.RNTIAL inte%!ity* @OR. and NOT NULL "onst!aints* Che"' "onst!aint allows you to define a "ondition.DATA MANIPULATION AND CONTROL . Or R!.I Constraint Type NOT NU## Constraint Description This "onst!aint is of "olu)n &a!iety only* The NOT NULL 'eywo!d #la"ed i))ediately afte! the dataty#e of a "olu)n ensu!es that any atte)#ts to #ut null &alues into that field by inse!t o! u#date state)ent will be !e$e"ted* As a "olu)n "onst!aint.!R!NC!( Constraint 0 .IAN ?. the syste) is said to be in a state of R.1 "onst!aint is "o)bination of UNI<U. -!.1:* 8hen a field is a fo!ei%n 'ey. 'eywo!d i))ediately afte! the dataty#e of a "olu)n ensu!es that the &alues ente!ed into the "olu)n a!e diffe!ent f!o) one anothe! i*e* distin"t* As a table "onst!aint = A %!ou# of fields "an be defined as uni>ue with UNI<U.IAN ?.1 "onst!aint "an be of the table o! "olu)n &a!iety. with the table &a!iety allowin% )ulti#le fields to be used as a sin%le fo!ei%n 'ey* CH!CConstraint D!. it is s#e"ially lin'ed to the table it !efe!en"es* That )eans e&e!y &alue in this field is di!e"tly !elated to a &alue in anothe! field and ea"h &alue of the fo!ei%n 'ey should una)bi%uously !efe! to only one &alue of the #a!ent 'ey* If this is the "ase. he!e the "o)bination of &alues )ust be uni>ue* UN&*U! Constraint +R&MAR.@. they do not li)it the &alues you "an ente! but )e!ely s#e"ify what ha##ens if you do not ente! any* Refe!ential ite%!ity in&ol&es !elatin% fields o! %!ou# of fields often in diffe!ent tables to one anothe!* 8hen all the &alues of one filed in a table ha&e to be #!esent in a filed of anothe! table. Constraint This "an be of table o! "olu)n &a!iety* Only one #!i)a!y 'ey 9of any nu)be! of "olu)ns: "an be defined fo! a %i&en table* PRIMAR1 ?. table "onst!aint.OR!&$N -!. that a &alue ente!ed into the table has to satisfy befo!e it "an be a""e#ted* Default &alues a!e not "onst!aints.

RT o! UPDAT.( and D. "o))and. the &alue )ust al!eady be #!esent in thei! #a!ent 'eys* 1ou )ay #ut NULLBs in these fields unless that field has NOT NULL "onst!aint* 1ou )ay delete any !ows with fo!ei%n 'eys without affe"tin% the #a!ent 'eys* As fa! as "han%es to the #a!ent 'ey &alues a!e "on"e!ned.T.1 • • • Any &alues you #ut into these fields with an IN(.L.I .IAN ?. you )ay not want to t!eat all of the DML "o))ands in the sa)e way* IN(.ffe"t of @o!ei%n ?ey Const!aint @o! fields defined as @OR.( "an be "as"aded o! !est!i"ted as desi!ed* C .DATA MANIPULATION AND CONTROL . the!e a!e essentially th!ee #ossibilities • 1ou "an !est!i"t o! fo!bid the "han%e = whi"h )eans that the "han%e on the #a!ent 'ey is !est!i"ted* • 1ou "an )a'e "han%e in the #a!ent 'ey and ha&e that sa)e "han%e )ade in the fo!ei%n 'ey auto)ati"ally = whi"h )eans the "han%e "as"ades* • 1ou "an )a'e "han%e in the #a!ent 'ey and set the fo!ei%n 'ey to NULL auto)ati"ally 9assu)in% NUL( a!e allowed in the fo!ei%n 'ey: = whi"h )eans the "han%e nulls the fo!ei%n 'ey* 8ith these "ate%o!ies a&ailable.RT is i!!ele&ant as it #uts new #a!ent 'ey &alue in the table so none of its &alues "an be "u!!ently be !efe!en"ed* UPDAT.

the table will ha&e to be "!eated.DATA MANIPULATION AND CONTROL . Table "!eated* F .es a!e "o#ied f!o) the !esult of A( >ue!y .L.sal @ROM e)#. with the !e>ui!ed st!u"tu!e.CT ena)e. TA7L.AT. new + A( (.I Tables • Tables a!e #!i)a!y sto!a%e units in O!a"le* To sto!e data in a table.AT. alon% with the &a!ious "onst!aints* Create Table (tate)ent +/rpose (ysnta0 CR!AT! TA #! (to!a%e (t!u"tu!e to hold data* CR. TA7L. afte! the table is "!ated the !esults of the >ue!y a!e inse!ted as its !ows* !0a)ple (*# Co))an2 Res/lt C!eate a new table usin% A( "lause* (<LECR. Guse!*HtableDna)e I9"olu)nDna)e dataty#e G"olu)nD"onst!aintH J GtableD"onst!aintH : J A( >ue!yK %1ere TableDna)e Colu)nDna)e Dataty#e Colu)nD"onst!aint TableD"onst!aint A( >ue!y is na)e of the table is na)e of the "olu)n is the dataty#e of the "olu)n is data "onst!aint fo! the "olu)n is data "onst!aint fo! the table "olu)nBs ty#e and si.$ob.

-----------------(MIT3 CL.R? 14// 10 !ows sele"ted* !0a)ple (*# Co))an2 C!eate an e)#ty table* (<LECR.R. TA7L.(MAN 1C// AMIT CL.NAM.L.(MAN 1F// 8A(IM (AL.R +N6C MARIA (AL.CT L @ROM e)#ty.R +5C/ (UMIT MANAA.(MAN 1+C/ RAMA MANAA. 1 O +.R? NC/ ANIL ANAL1(T 4/// MILAN CL.L.R +0C/ (UNIL ANAL1(T 4/// C3RI( PR.L. No !ows sele"ted* Res/lt !0a)ple (*# Co))an2 Res/lt 6 . Table "!eated* To "onfi!) the "ontents of the table e)#ty* (<LE(.R? 11// MAC? CL.(ID.I !0a)ple (*# Co))an2 Res/lt To "onfi!) the "ontents of table N. .AT.(MAN 1+C/ 7ILL MANAA. e)#ty + A( (. MO7 (AL -----------.DATA MANIPULATION AND CONTROL .CT L @ROM new.R? 5// A(3A (AL.8 (<LE(.NT C/// TINA (AL.CT L @ROM de#t 4 83.----------.

R90:. TA7L.BNB:::.+:."olDna)e dataty#eHQ:K IDROP CON(TRAINT "onst!aintDna)eK IADD CON(TRAINT "onst!aintDna)e CON(TRAINT T1P.R9+:. 4 "ustid R.R9+: NOT NULL:.@AULT (1(DAT. Table "!eated* Res/lt !0a)ple (*# Co))an2 C!eate a new table usin% !efe!en"es. 5 "o)) NUM7.R90: PRIMAR1 ?.( tableDna)e9"olDna)e:HK 5 (ynta0 I.R95. C shi#date DAT. "he"' "onst!aints and Default &alues* (<LECR.+:. C )%! NUM7.@. N de#tno NUM7..R91/.. 0 $ob 2ARC3AR+9N:..NC.NA7L.(TA7 + 9id NUM7.AT. enableD"lause J DI(A7L.R. 6 sal NUM7. te)# + 9e)#no NUM7. D.R TA7L. Guse!*HtableDna)e IADD J MODI@19"olDna)e dataty#eG.( "usto)e!. "olDna)e GR.NC. 0 o!ddate DAT.AT. F hi!edate DAT. TA7L.I !0a)ple (*# Co))an2 C!eate a new table (<LE CR. 6 C3. F status C3AR91:. 4 ena)e 2ARC3AR+91/: NOT NULL.1 NOT NULL. D.R. Table "!eated* Res/lt Alter Table (tate)ent +/rpose A#T!R TA #! Add "olu)n to a table Modify a "olu)n definition Add o! Re)o&e data "onst!aints* ALT. disableD"lauseK .DATA MANIPULATION AND CONTROL .@.@AULT (1(DAT. (AL.C?9status IN9PAB.

R TA7L.R TA7L.R TA7L. te)# + ADD 9add!ess 2ARC3AR+94/::. te)# + MODI@1 9ena)e 2ARC3AR91C::. te)# + ADD CON(TRAINT te)#D)%!Df' 4 @OR.NC. Table alte!ed* (*# Co))an2 Res/lt !0a)ple Add "onst!aints to te)# table . Table alte!ed* In"!ease the width of "olu)n ena)e of table te)# to 1C "ha!a"te!s* (<LEALT.DATA MANIPULATION AND CONTROL .R.IAN ?. indi"atin% that a )ana%e! )ust al!eady e-ist as a &alid e)#loyee in the te)# table (<LEALT.( te)#9e)#no:.19)%!: R.@.I %1ere TableDna)e ColDna)e Dataty#e Const!aintDna)e .nableD"lause RdiasbleD"lause !0a)ple (*# Co))an2 Res/lt !0a)ple is na)e of the table* is na)ee of the "olu)n* is the dataty#e of the "olu)n is the na)e of the "onst!aint is the na)e of the "onst!aint o! all t!i%%e!s on the table* Add "olu)n to table te)#* (<LEALT. Table alte!ed* (*# Co))an2 Res/lt N .

@AULT PAB. salestab + ADD CONTRAINT salestabD#' 4 PRIMAR1 ?.DAT.(( NullS -------NOT NULL NOT NULL Ty#e --------NUM7.R TA7L.R TA7L.DATA MANIPULATION AND CONTROL . (*# Co))an2 1/ . Table alte!ed* (*# Co))an2 Res/lt !0a)ple Add D.R90: DAT. salestab + MODI@1 status C3AR91: D.1 "onst!aint to salestab table* (<LEALT.R TA7L.R90: 2ARC3AR+91C: 2ARC3AR+9N: NUM7. MO7 MAR 3IR. NUM7. NOT 4 NULL.I !0a)ple (*# Co))an2 Res/lt To "onfi!) the st!u"tu!e of table te)#* (<LED.19id:.R9+: 2ARC3AR94/: NOT NULL !0a)ple Add PRIMAR1 ?. te)# Na)e ----------.(CRI7.@AULT &alue to status "olu)n of salestab table* (<LEALT. salestab + MODI@1 o!ddate DAT.R95.NAM. (AL COMM D.+: NUM7.+: NUM7. D.MPNO .PTNO ADDR.@AULT (1(DAT. Table alte!ed* (*# Co))an2 Res/lt !0a)ple Add NOT NULL "onst!aint to o!ddate "olu)n of table salestab* (<LEALT.R91/.

te)# + DROP CON(TRAINT te)#D)%!Df'.R9F: DAT.1.I Res/lt !0a)ple Table alte!ed* To "onfi!) the st!u"tu!e of table salestab* (<LED.1 of "usto)e! table* (<LEALT. (TATU( NullS -------NOT NULL NOT NULL Ty#e --------NUM7. "usto)e! + .1 of the e)# table* (<LEALT. C3AR91: (*# Co))an2 Res/lt !0a)ple (*# Co))an2 Res/lt Re)o&e the @OR. PRIMAR1 ?. salestab Na)e ----------ID CU(TID ORDDAT.(CRI7. "usto)e! + DI(A7L. Table alte!ed* !0a)ple (*# Co))an2 Res/lt To disable the PRIMAR1 ?.1 "onst!aint added to te)# table (<LEALT.1. DAT.DATA MANIPULATION AND CONTROL .R TA7L.R TA7L. PRIMAR1 ?.R9+: NUM7.IAN ?.NA7L. (3IPDAT.R TA7L. Table alte!ed* 11 . Table alte!ed* !0a)ple (*# Co))an2 Res/lt To enable the PRIMAR1 ?.

DATA MANIPULATION AND CONTROL .D (AL.status 4 @ROM use!D"onst!aints 0 83.(TA7 .D (AL.(TA7 .(TA7DP? (1(DC//01/ 0 !ows sele"ted* Drop Table (tate)ent +/rpose (ynta0 %1ere TableDna)e !0a)ple (*# Co))an2 Res/lt is na)e of the table* DRO+ TA #! Re)o&e table f!o) database* DROP TA7L.I !0a)ple To &e!ify the status of all "onst!aints of salestab table* (<LE(."onst!aintDtype. (TATU( --------------------.D (AL.NA7L. ----------------------------(1(DC//0/6 (ALD@? (AL.NA7L.NA7L.-----------(AL.D (*# Co))an2 Res/lt CON(TRAINTDNAM. tableDna)e LI?.(TA7 . P(AL.CT + "onst!aintDna)e. Guse!*HtableDna)e Re)o&e data f!o) database* (<LEDROP TA7L. Table d!o##ed* 1+ .R. C C R P C TA7L.DNAM. te)#.(TA7B.L.NA7L.(TA7 .tablena)e.

(CRI7. (AL COMM D.RT and D.PTNO NOT NULL 14 .R96.DATA MANIPULATION AND CONTROL .T. MO7 MAR 3IR.R90: 2ARC3AR+91/: 2ARC3AR+9N: NUM7.+: NUM7. e)# NullS -------------------NOT NULL Ty#e ----------------------------NUM7. state)ents alte! e-isin% !ows in a database table.I Data Manip/lation (tate)ents Data Mani#ulation state)ents a!e used to alte! the database tables in so)e way* The UPDAT.&alueH**: J >ue!yK !0a)ple To des"!ibe the st!u"tu!e of e)# table* (<LED. #la"e new !e"o!ds into a database table o! !e)o&e one o! )o!e !e"o!ds f!o) the database table* INSERT (tate)ent +/rpose (ynta0 %1ere table "olu)n &alue 2ALU. NUM7.NAM.( 9&aluesG.( >ue!y is na)e of the table is na)e of the table is the "o!!es#ondin% &alue fo! the "olu)n adds one !ow* adds as )any !ows as sele"ted by the >ue!y* &N(!RT Add new !ow9s: to the database table* IN(..R96.+: NUM7.DAT.MPNO ."olu)nH**:H I2ALU.L.RT INTO tableG9"olu)nG.R9N: DAT.R9+: (*# Co))an2 Res/lt Na)e --------------------. IN(.

I Inserting null values implicitly !0a)ple (*# Co))an2 Res/lt Inse!t a new e)#lo#yee.RT INTO e)#9e)#no.CT L @ROM e)#.ena)e. 1 !ow "!eated Res/lt !0a)ple (*# Co))an2 To "onfi!) "han%es to the unde!lyin% table )ade by the abo&e state)ents (<LE(. 1 !ow "!eated Inserting null values explicitly !0a)ple (*# Co))an2 Inse!t null &alue e-#li"itly by s#e"ifyin% the NULL 'eywo!d o! e)#ty st!in% within sin%le >uotes in the &alue list* (<LEIN(.de#tno.)%!: + 2ALU.RT INTO e)# + 2ALU.NULL.BBMAN.DATA MANIPULATION AND CONTROL .B41-MA1NFB.L. na)e.+/. $ob.$ob.BB. but only assi%n the e)#loyee nu)be!.(91+4C.R?B.6CFF.CT L @ROM de#t.BMA2?B. !0a)ple (*# Co))an2 Dis#lay all data f!o) table de#t* (<LE(.(91+40.B.+/:.BCL. de#a!t)ent nu)be! and )ana%e! nu)be!* (<LEIN(.6N/+:.NULL. 10 .L.

B. 7ANAALOR.(. --------------------------1/ ACCOUNT( +/ R.CT L @ROM de#t1.ARC3 4/ (AL. D.(90C.I !0a)ple (*# Co))an2 Res/lt Dis#lay all data f!o) table de#t1 (<LE(. 7OM7A1 7ANAALOR.L3I MADRA( 7ANAALOR.RT INTO de#t + 2ALU.ARC3 4/ (AL.DUCATIONB.PTNO DNAM.( 0/ OP.L3I MADRA( 7ANAALOR.(. !0a)ple (*# Co))an2 Res/lt Inse!t the . D. F !ows "!eated* Dis#lay all data f!o) table de#t1 (<LE(.PTNO DNAM.(.L3I MADRA( 7ANAALOR.ARC3 4/ (AL. D. --------------------------1/ ACCOUNT( +/ R.L.L. de#a!t)ent 0C. 1 !ow "!eated* 1C .BCALCUTTAB:. into the D.(.DATA MANIPULATION AND CONTROL .CT L @ROM de#t. D.CT L @ROM de#t1.du"ation de#a!t)ent.( 0/ OP. lo"ation Cal"utta.ARC3 1/ !ows sele"ted* LOC -------------7ANAALOR.L. !0a)ple (*# Co))an2 Res/lt !0a)ple (*# Co))an2 Res/lt Inse!t into the de#t1 table usin% the >ue!y o#tion (<LEIN(.( 0/ OP.PT table* (<LEIN(.RATION( LOC -------------7ANAALOR.RT INTO de#t1 + (.RATION( 1/ ACCOUNT( +/ R.RATION( C/ ACCOUNT( F/ R. D.

BMADRA(B:.B(AL.<U.nte! &alue fo! dna)e @INANC.I !0a)ple (*# Co))an2 Res/lt Inse!t &alues into "olu)ns usin% #a!a)ete!s* (<LEIN(.B@INANC.BTdna)eB.( 9Tde#tno.B7ANAALOR.BTlo"B: New + 2ALU. Old + 2ALU. %ene!ate the de#a!t)ent nu)be! auto)ati"ally and "ont!ol t!ansa"tions* (<LECR. (e>uen"e "!eated* Res/lt (*# Co))an2 Res/lt (<LEIN(.BTlo"B:.DUCATIONB. 1 !ow "!eated* Res/lt 1F . . 1 !ow "!eated* (*# Co))an2 Res/lt (*# Co))an2 (<LE(A2.RT INTO de#t + 2ALU.( 9sDde#tno*N.NT 71 1/ 4 (TART 8IT3 FC.RT INTO de#t + 2ALU.UT2AL.NC.BTdna)eB.POINT a.DATA MANIPULATION AND CONTROL .AT.( 9CC.BPUN.(B.B.nte! &alue fo! de#tno CC . sDde#tno + INCR. (a&e#oint "!eated* (<LEIN(.(9Tde#tno.B:.( 9sDde#tno*N.nte! &alue fo! lo" PUN. .M.B.RT INTO de#t + 2ALU.UT2AL. (.B: 1 !ow "!eated* !0a)ple (*# Co))an2 C!eate new de#a!t)ents.

(. ------------ACCOUNT( R.PTNO --------------1/ +/ 4/ 0/ C/ F/ 0C CC FC 6C 5C NC DNAM.POINT b.( 9sDde#tno*N.DUCATION ADMIN @INANC.ARC3 (AL.RT INTO de#t + 2ALU.B:. D.B7ANAALOR.L3I MADRA( 7ANAALOR. MADRA( 7ANAALOR. 7ANAALOR.DUCATION @INANC. D. 7ANAALOR. 7OM7A1 7ANAALOR.UT2AL.DATA MANIPULATION AND CONTROL .B7ANAALOR.B.B:.B@INANC. CALCUTTA PUN.UT2AL.CT L @ROM de#t. 1 !ow "!eated* !0a)ple (*# Co))an2 Res/lt To "onfi!) "han%es to the unde!lyin% table )ade by the abo&e state)ents (<LE(.ARC3 .( .RT INTO de#t + 2ALU. LOC -------------7ANAALOR.RATION( ACCOUNT( R.I (*# Co))an2 Res/lt (*# Co))an2 Res/lt (*# Co))an2 Res/lt (<LEIN(. 1+ !ows sele"ted* 16 . (AL.(9sD de#tno*N.L. (a&e#oint "!eated* (<LEIN(.( OP.BADMINB.(. 1 !ow "!eated* (<LE(A2.

I !0a)ple (*# Co))an2 Res/lt To !eali. (AL.L3I MADRA( 7ANAALOR.RATION( ACCOUNT( R.POINT a. 7OM7A1 7ANAALOR.DATA MANIPULATION AND CONTROL .e the effe"t of the !ollba"'.(.DUCATION @INANC.ARC3 .Q* 9"olu)n.(.( LOC -------------7ANAALOR.ARC3 (AL. tableGaliasH (. D. CALCUTTA PUN.T I"olu)n O e-#!.CT L @ROM de#t. "o))it and sa&e#oint "o))ands* (<LEROLL7AC? TO (A2.PTNO --------------1/ +/ 4/ 0/ C/ F/ 0C CC FC DNAM. Rollba"' "o)#lete* (*# Co))an2 Res/lt (<LECOMMIT Co))it "o)#lete* (*# Co))an2 Res/lt (<LE(.L. ------------ACCOUNT( R.( OP.Q:O9sub>ue!y:QK Gwhe!e "onditionH 15 . D. MADRA( N !ows sele"ted* Update (tate)ent +/rpose (ynta0 U+DAT! Modify e-istin% !ow9s:* UPDAT."olu)n.

R.T sal O sal L1*C 4 83.(MAN* (<LEUPDAT. e)#no O 1+40. de#tno O 4/. e)# + (.DATA MANIPULATION AND CONTROL .I %1ere Table is na)e of the table to be u#dated sets fields in the s#e"ified "olu)n to the Colu)n O e-#! &alue of e-#!* 9"olu)n.(MANB 4 83. 1 !ow u#dated* Res/lt !0a)ple (*# Co))an2 In"!ease sala!y of all e)#loyees of de#a!t)ent 4/ to 1*C ti)es the #!e&ious sala!y* (<LEUPDAT. F !ows u#dated* Res/lt !0a)ple (*# Co))an2 To "onfi!) the "han%es to the unde!lyin% table )ade by the abo&e state)ents (<LE(.**:O !etu!ned 9sub>ue!y: Condition sets fields in the s#e"ified "olu)ns to the &alue by the sub>ue!y* identifies the !ow9s: to be u#dated* !0a)ple (*# Co))an2 Chan%e the "o))ission of e)#loyee 1+40 to CCC and $ob to (AL.R.T "o)) O CCC.L. $obOB(AL. e)# + (.CT L @ROM e)#. 1N .

(AL COMM D.MPNO .(MAN 6N/+ CCC +/ 6CFF 41-MA1-NF +/ !0a)ple U#date lo" of de#a!t)ents 0/. de#tno IN 90/.R 654N /1-MA1-NC +5C/ 4/ MANAA.R.R? 665+ +4-MAN-NF 14// 1/ (AL. de#tnoO0C: 4 83.(MAN 6FN5 ++-@.(MAN 6FN5 +5-(.R? 6N/+ 16-D.----------CL.----------64FN (MIT3 60NN A(3A 6C+1 8A(IM 6CFF RAMA 6FC0 MARIA 6FN5 7ILL 665+ (UMIT 6655 (UNIL 654N C3RI( 6500 TINA 656F AMIT 6N// MAC? 6N/+ ANIL 6N40 MILAN 1+40 MAC? 1+4C MAN.DAT. 1F !ows sele"ted* MO7 MAR 3IR.(MAN 6FN5 /5-(.PTNO -----------------.R? 6655 1+-MAN-NF 11// +/ CL.R.C-NC 4/// +/ CL.----------.DATA MANIPULATION AND CONTROL .(MAN 6FN5 +/-@.R? 6FN5 /4-D. -----------.CT lo" @ROM de#t 83.--------.NT 16-NO2-NC C/// +/ (AL.F/ of de#t1 table to that of lo" of de#a!t)ent 0C of de#t table*9use of >ue!y "lause of u#date state)ent: (<LEUPDAT.L.P-NC 1+C/ 10// 4/ MANAA.R 654N /+-APR-NC +N6C +/ (AL.C-NF 4/// +/ PR. de#t1 + (.P-NC 1C// 4/ CL.I Res/lt .F/:.----------------.NAM.-------.(ID.C-NC NC/ 4/ ANAL1(T 6CFF /4-D.T lo"O9(. 4 !ows u#dated* (*# Co))an2 Res/lt +/ .7-NC 1F// 4// 4/ (AL.7-NC 1+C/ C// 4/ MANAA.R 654N /N-MUN-NC +0C/ 1/ ANAL1(T 6CFF /N-D.C-NC 5// +/ (AL.

PTNO --------------1/ +/ 4/ 0/ 1/ +/ 4/ 0/ C/ F/ 1/ !ows sele"ted* DNAM.L.RATION( ACCOUNT( R.R. "onditionH %1ere Table Condition is na)e of the table identifies the !ow9s: to be deleted* !0a)ple (*# Co))an2 Res/lt Re)o&e all info!)ation about the de#a!t)ents 0C.( OP.( OP.FC:.I !0a)ple (*# Co))an2 Res/lt Confi!) the "han%es )ade by the abo&e state)ent* (<LE(.(.CC. @ROM table G83.(. D.CC.L3I MADRA( CALCUTTA 7ANAALOR. 4 !ows deleted* +1 .L.ARC3 (AL.(.RATION( ACCOUNT( R.and FC* (<LED.DATA MANIPULATION AND CONTROL . ------------ACCOUNT( R.ARC3 (AL. @ROM de#t + 83.R.L. de#tno IN 90C.T.ARC3 LOC -------------7ANAALOR. D.L3I MADRA( CALCUTTA 7OM7A1 CALCUTTA Delete (tate)ent +/rpose (ynta0 D!#!T! Re)o&e an e-istin% !ow f!o) the table* D.T.CT L @ROM de#t1. D.

D.ARC3 5 !ows sele"ted* LOC -------------7ANAALOR.L.ARC3 4/ (AL.I !0a)ple (*# Co))an2 Res/lt Confi!) the "han%es to the unde!lyin% table )ade by the abo&e state)ent* (<LE(.(.( 0/ OP. --------------------------1/ ACCOUNT( +/ R. Data Control (tate)ents +rivile3es A #!i&ile%e is The !i%ht to e-e"ute a #a!ti"ula! ty#e of (<L state)ent The !i%ht to "onne"t to the database The !i%ht to "!eate a table in you! s"he)a The !i%ht to sele"t !ows f!o) so)eone elseBs tables The !i%ht to e-e"ute so)eone elseBs sto!ed #!o"edu!e The #!i&ile%es of an O!a"le database "an be di&ided into two distin"t "ate%o!ies (yste) privile3es Object privile3es A&ailable only to ad)inist!ato!s and a##li"ation de&elo#e!s* Allow use! to #e!fo!) a #a!ti"ula! a"tion on a s#e"ifi" ob$e"t* Ob$e"t #!i&ile%es a!e %!anted to end-use!s so that they "an use a database a##li"ation to a""o)#lish s#e"ifi" tas's* rant (tate)ent +/rpose $rant A!ant syste) and ob$e"t database #!i&ile%es to use!s* ++ .PTNO DNAM.L3I MADRA( 7ANAALOR. D.CT L @ROM de#t. 7OM7A1 7ANAALOR.RATION( C/ ACCOUNT( F/ R.(.DATA MANIPULATION AND CONTROL .

L. A!ant su""eded* !0a)ple (*# Co))an2 Res/lt !0a)ple (*# Co))an2 Res/lt A!ant all #!i&ile%es to s"ott on de#t table with ability to %!ant sa)e #!i&ile%es to othe!s ARANT ALL ON e)# to s"ott 8IT3 ARANT OPTION A!ant su""eded* Conne"t to s"ott s"he)a (<LE CONN.I (ynta0 ARANT Iob$e"tD#!i& G.L.ob$e"tD#!i& 9"olu)n. use!HQ J PU7LIC K %1ere Ob$e"tD#!i& ALL Colu)n ON TO PU7LIC 8IT3 ARANT OPTION is an ob$e"t #!i&ile%e to be %!anted all ob$e"t #!i&ile%es s#e"ifies a "olu)n f!o) a table o! &iew on whi"h #!i&ile%es a!e %!anted identifies the ob$e"t on whi"h #!i&ile%es a!e %!anted identifies use!s to whi"h the ob$e"t #!i&ile%e is %!anted %!ants ob$e"t #!i&ile%es to all use!s allows %!antee to %!ant the ob$e"t #!i&ile%es to othe! use!s !0a)ple (*# Co))an2 Res/lt A!ant (.CT #!i&ile%es to s"ott on e)# table (<LEARANT (.!!o! in disablin% !oles in #!odu"t use! #!ofile* Conne"ted* +4 .CT ON e)# TO s"ott."olu)n**:**H J ALLK ON ob$e"t TO I use! G.CT s"ottRti%e! 8a!nin% P!odu"t use! #!ofile info!)ation not loaded* .DATA MANIPULATION AND CONTROL .

NAM.--------.( MANAA.RROR at line 1 ORA-/1/41 insuffi"ient #!i&ile%es Revo!e (tate)ent R!VO-! +0 .C-51 4/// 1// +/ 6N40 MILL.P-// C/// 4/// 1/ 654N ?INA PR.R (AL. MO7 MAR 3IR.(MAN 6FN5 +5-(.CT L @ROM e)1. e)1 .R +/+/ 1+-(.NT 16-NO2-51 4/// 1/ 6500 TURN.R? 6FN5 /4-D.C-51 4/// 4/ 6N/+ @ORD ANAL1(T 6CFF /4-D.--------.R 654N /+-APR-51 4/// +/ 6FC0 MARTIN (AL.R? 6N/+ 16-D.R 654N /1-MA1-51 4/// 4/ 665+ CLAR? MANAA.PTNO --------.---------.-----------.N (AL.P-51 4/// / 4/ 656F ADAM( CL. (AL COMM D.(ID. MANAA.I !0a)ple (*# Co))an2 Res/lt !0a)ple (*# Co))an2 Res/lt C!eate a synony) fo! e)# table (<LE CR.DATA MANIPULATION AND CONTROL .--------.AT.(MAN 6FN5 ++-@. (ynony)n "!eated* To sele"t f!o) table #!esent in use!1 s"he)a* (<LE (.R CL.(MAN 6FN5 +/-@.7-51 4/// 4// 4/ 6C+1 8ARD (AL.(MAN 6FN5 /5-(.--------.7-51 4/// C// 4/ 6CFF MON.C-5/ 4/// +/ 60NN ALL.MPNO .P-51 4/// 10// 4/ 6FN5 7LA?. (1NON1M e)1 @OR use!1*e)#.R? 665+ +4-MAN-5+ 4/// 1/ 10 !ows sele"ted* !0a)ple (*# Co))an2 Res/lt U#date e)# table of use!1 s"he)a UPDAT. . e)1 set salOsalV4//.-----------64FN (MIT3 CL.R? 6655 1+-MAN-54 4/// +/ 6N// MAM.R 654N /N-MUN-51 4/// 1/ 1//1 RAM MANAA. UPDAT.DAT.--------.--------.( CL.L.

NC.R P!odu"t use! #!ofile info!)ation not loaded* +C .R. ob$e"tD#!i&9"olu)n. ALL ON de#t @ROM s"ott.CT (COTTRTIA. use!H** J PU7LIC ICA(ACD.CT U(.R1RU(.!!o! in disablin% !oles in #!odu"t use! #!ofile* Conne"ted* !0a)ple (*# Co))an2 Res/lt Re&o'e all #!i&ile%es %i&en to s"ott on de#a!t)ent table (<LE R. Re&o'e su""eded* !0a)ple (*# Co))an2 Res/lt Conne"t to s"ott s"he)a* CONN.R1 8a!nin% P!odu"t use! #!ofile info!)ation not loade!W* .DATA MANIPULATION AND CONTROL . CON(TRAINT( K %1ere CA(CAD! CON(TRA&NT( a!e !e>ui!ed to !e)o&e any @? !efe!en"es )ade to the ob$e"t by )eans of the R. ob$e"tD#!i& G.I +/rpose (ynta0 Re&o'es database o! syste) o! ob$e"t a""ess #!i&ile%es f!o) use!s* R.2O?.@.( #!i&ile%e* !0a)ple (*# Co))an2 Res/lt Conne"t to use!1 s"he)a (<LE CONN."olu)n**:**H J ALL K ON Ob$e"t @ROM Iuse! G. Iob$e"tD#!i& G.2O?.

RROR at line 1 ORA-//N0+ table o! &iew does not e-ist Data Conc/rrency Overvie4 In a sin%le use! database. use! "an )odify data within a t!ansa"tion without "on"e!n fo! othe! use!s )odifyin% the sa)e data at the sa)e ti)e* 3owe&e!.L. .!!o! in disablin% !oles in #!odu"t use! #!ofile !0a)ple (*# Co))an2 Res/lt Dis#lay the "ontents of de#t table #!esent in use!1 s"he)a (<LE (. "ont!ol of data "on"u!!en"y and "onsisten"y is &ital in a )ulti use! en&i!on)ent* #oc5s The #!oble)s asso"iated with data "on"u!!en"y.I .CT L @ROM use!1*de#t. the state)ents within )ulti#le si)ultaneous t!ansa"tions "an u#date the sa)e data* Con"u!!ently e-e"utin% t!ansa"tions )ust be %ua!anteed to #!odu"e the sa)e effe"t as the sa)e t!ansa"tions e-e"uted se!ially* The!efo!e. in a )ulti use! database. inte%!ity and "onsisten"y a!e !esol&ed usin% Data Lo"'s* Lo"'s a!e nothin% but )e"hanis)s used to #!e&ent dest!u"ti&e inte!a"tion between use!s a""essin% the sa)e !esou!"e* In %ene!al you "an use two le&els of lo"'in% in a )ulti use! database* !0cl/sive #oc5 !eleased* (1are2 #oc5 P!e&ents the asso"iated !esou!"e f!o) bein% sha!ed.DATA MANIPULATION AND CONTROL . until the lo"' is Allows the asso"iated !esou!"e to be sha!ed de#endin% on the o#e!ations in&ol&ed 9e*%* se&e!al use!s "an !ead the sa)e data at the sa)e ti)e*: +F .

R+ t!ies to a""ess the anothe! !e"o!d f!o) the sa)e table. UPDAT. whi"h is a uni>ue featu!e of O!a"le* The abo&e e-a)#le shows how O!a"le handles two diffe!ent u#dates that "ontend fo! the sa)e !e"o!d of a table* O!a"le uses the )e"hanis) of Multi-2e!sionin% to handle >ue!ies.R1Bs t!ansa"tion a">ui!es an e-"lusi&e lo"' on the table* This is also !efe!!ed to as !ow-le&el lo"'in%.R1 is a""essin% R.DATA MANIPULATION AND CONTROL .R4 t!ies to a""ess R.UCLU(I2. G. J . U(. O!a"le !eleases the !ollba"' info!)ation but does not i))ediately dest!oy it* The info!)ation !e)ains in the !ollba"' se%)ent to "!eate !ead"onsistent sna#shot of #e!tinent data fo! >ue!ies that sta!ted befo!e the t!ansa"tion "o))ited* To %ua!antee that the !ollba"' data is a&ailable fo! as lon% as #ossible fo! su"h &iews O!a"le w!ites the e-tents of !ollba"' se%)ent se>uentially* M/lti7versionin3 "oc! (tate)ent +/rpose (ynta0 #OCPe!)its sha!ed a""ess to the table by )ulti#le use!s while #!ese!&in% the tableBs Inte%!ity LOC? TA7L. then both the t!ansa"tions a">ui!e a sha!ed lo"' on the table* If U(. O!a"le assi%ns the t!ansa"tion to a !ollba"' se%)ent* @o! the du!ation of a t!ansa"tion. whi"h "ontend with u#dates to !etu!n a""u!ate !esults* @i!st a t!ansa"tion does not a">ui!e !ow lo"'s of any ty#e fo! >ue!ies* This )eans that two t!ansa"tions "an issue e-a"tly the sa)e >ue!y at the sa)e ti)e without any "ontention fo! the sa)e set of !ows* In this "ase fo! e&e!y >ue!y O!a"le !etu!ns a ti)e#oint-based &e!sion of the data o! a !ead-"onsistent sna#shot that the >ue!y !e>uests* O!a"le ensu!es that e&e!y !ow in a >ue!yBs !esult set is "onsistent at the ti)e you issue the >ue!y* 3e!e O!a"le uses !ollba"' se%)ent fo! its )ulti-&e!sionin% )e"hanis)* . the asso"iated use! #!o"ess w!ites !ollba"' info!)ation to the assi%ned !ollba"' se%)ent* 8hen you "o))it a t!ansa"tion. GNO8AITH %1ere Table is the na)e of the table* +6 .CORD1 f!o) the table and U(.a"h ti)e a use!Bs t!ansa"tion be%ins. J (3AR.CORD1 and U(. tableHQ IN I (3AR. K MOD.I (1are26!0cl/sive #oc5 8hen a use!.

e)# IN ..UCLU(I2.DATA MANIPULATION AND CONTROL .NAM. eithe! e-#li"itly 9with a COMMIT o! ROLL7AC? state)ent: o! i)#li"itly 9when a DDL state)ent is issued:* A t!ansa"tion ends when any of the followin% o""u!s • • A COMMIT o! ROLL7AC? 9without a (A2.R:* If the "u!!ent t!ansa"tion "ontains any +5 ..POINT "lause: state)ent is issued* A DDL state)ent is e-e"uted 9su"h as CR. ALT. UPDAT. (3AR.UCLU(I2. NO8AIT. Table9s: Lo"'ed* Transaction Control (tate)ents %1at is a Transaction8 A t!ansa"tion is a lo%i"al unit of wo!' that is "o)#!ised of one o! )o!e (<L state)ents e-e"uted by a sin%le use!* The effe"ts of all the (<L state)ents that "onstitute a t!ansa"tion "an eithe! all be "o))itted 9a##lied to the database: o! all !olled ba"' 9undone f!o) the database: A t!ansa"tion be%ins with the fi!st e-e"utable (<L state)ent* A t!ansa"tion ends when it is "o))itted o! !olled ba"'. (3AR.AT. R. DROP. !etu!n "ont!ol to you so that you )ay ente! othe! "o))ands while you wait fo! the table to be"o)e a&ailable* #!e&ents othe! use!s f!o) lo"'in% o! u#datin% any !ow of the table Allows othe! use!s >ue!y the table but not )odify it . but to !etu!n the "ont!ol if any othe! use! has lo"'ed it* (<LE LOC? TA7L. allows you to u#date !ows of the table while othe! use!s ha&e !ows lo"'ed !0a)ple (*# Co))an2 Res/lt To lo"' the e)#loyee table in e-"lusi&e )ode.I NO8AIT )a'es LOC? TA7L. MOD.

sin%le state)ent t!ansa"tion* A use! dis"onne"ts f!o) ORACL. the t!ansa"tion is fi!st "o))itted.* 9The "u!!ent t!ansa"tion is "o))itted: The!e is an abno!)al te!)ination of a use! #!o"ess* 9The "u!!ent t!ansa"tion is !olled ba"': Afte! one t!ansa"tion ends.I • • DML state)ents.DATA MANIPULATION AND CONTROL . the ne-t e-e"utable (<L state)ent auto)ati"ally sta!ts the followin% t!ansa"tion* Commit Co))ittin% a t!ansa"tion )eans )a'in% #e!)anent the "han%es #e!fo!)ed by the (<L state)ents within the t!ansa"tion* The "han%es )ade by the (<L state)ent9s: of you! t!ansa"tion only be"o)e #e!)anent and &isible to othe! use!s t!ansa"tions that sta!t afte! you! t!ansa"tion has been "o))itted* (tate)ent +/rpose (ynta0 Co))it Co))its "han%es )ade to the tables in the default database COMMIT Rollbac! Rollin% ba"' )eans undoin% any "han%es to data that ha&e been #e!fo!)ed by (<L state)ents within an un"o))itted t!ansa"tion* Afte! a t!ansa"tion is !olled ba"' the affe"ted data is left un"han%ed as if the (<L state)ent in the t!ansa"tion we!e ne&e! e-e"uted* Roll ba"' "an be of two ty#es • Rollin% ba"' of enti!e t!ansa"tion* • Rollin% ba"' of t!ansa"tion to a sa&e#oint* In "ase of !ollba"' of enti!e t!ansa"tion • All "han%es )ade by all the (<L state)ents in the t!ansa"tion a!e undone usin% the "o!!es#ondin% !ollba"' se%)ents* • All the t!ansa"tionBs lo"'s of data a!e !eleased* • The t!ansa"tion is ended* In "ase of !ollba"' e-e"uted afte! the sa&e#oint • Only the state)ents e-e"uted afte! the sa&e#oint a!e !olled ba"'* +N . and the DDL state)ent is e-e"uted and "o))itted as a new.

it "an be "ontinued* (tate)ent +/rpose (ynta0 Rollbac5 Rolls ba"' "han%es )ade to the tables in the database sin"e the )ost !e"ent "o))it* ROLL7AC? Savepoint Inte!)ediate )a!'e!s o! sa&e#oints "an be de"la!ed within a t!ansa"tion* (a&e#oints a!e often used to di&ide a lon% t!ansa"tion into s)alle! #a!ts* Usin% sa&e#oints. you "an a!bit!a!ily )a!' you! wo!' at any #oint within a lon% t!ansa"tion* This allows you the o#tion of late! !ollin% ba"' wo!' #e!fo!)ed befo!e the "u!!ent #oint in the t!ansa"tion but afte! a de"la!ed sa&e#oint within the t!ansa"tion* (a&e#oints a!e also useful in a##li"ation #!o%!a)s in a si)ila! way* If a #!o"edu!e "ontains se&e!al fun"tions.POINT 4/ . if a fun"tion fails.DATA MANIPULATION AND CONTROL .I • • The s#e"ified sa&e#oint is #!ese!&ed. a sa&e#oint "an be "!eated befo!e ea"h fun"tion be%ins* Then.but all data lo"'s a">ui!ed #!e&ious to the sa&e#oint a!e !etained* The t!ansa"tion is still a"ti&e. the data lo"'s obtained by !olled ba"' state)ents a!e !eleased* Othe! t!ansa"tions that we!e waitin% fo! the #!e&iously lo"'ed !esou!"es "an #!o"eed* Othe! t!ansa"tions that want to u#date #!e&iously lo"'ed !ows "an do so* (tate)ent +/rpose (ynta0 (avepoint Ma!' a sa&e#oint within the "u!!ent t!ansa"tion* (A2. but all sa&e#oints that we!e established afte! the s#e"ified one a!e lost* All tables and !ow lo"'s a">ui!ed sin"e that sa&e#oint that a!e !eleased. it is easy to !etu!n the data to its o!i%inal state befo!e the fun"tion be%an and then !e-e-e"ute the fun"tion with !e&ised #a!a)ete!s o! #e!fo!) a !e"o&e!y a"tion* Afte! a !ollba"' to a sa&e#oint.

UNI<U.POINT state)ent* 41 .@.L. C3.1.I (UMMAR. "o))and* Const!aints li)it the &alues ente!ed into its "olu)ns* The &a!ious "onst!aints a!e NOT NULL. "o))and is used* (ub>ue!ies "an also be used in the UPDAT.T.IAN ?. PRIMAR1 ?.C? and and also add o! delete "onst!aints* To inse!t !ows in the table IN(.NC. TA7L.L. "o))and adds "olu)n to the table o! "han%e thei! si. o#tion is used alon% with the @o!ei%n ?ey it allows the deletion of all the "o!!es#ondin% "hild !ows whene&e! a #a!ent !ow is deleted* AL.( 8hen ON D.R.DATA MANIPULATION AND CONTROL . COMMIT is used and to dis"a!d the t!ansa"tions.1 o! R. the ROLL7AC? "o))and is used* One "an dis"a!d all the "han%es u#to a #oint.RT "o))and is used* Pa!a)ete! substitution "an be done fo! inse!tin% &alues into tables by #!efi-in% the "olu)n na)e with the PTB sy)bol* To u#date &alues of a sin%le "olu)n o! a %!ou# "olu)ns in a table UPDAT. in"ludin% tables* Tables a!e "!eated usin% CR. defined with the (A2.T. 97 • • • • • • • • • • • • Data Definition Lan%ua%e 9DDL: is the subset of s>l "o))ands used to )ani#ulate O!a"le database st!u"tu!es. "o))and* D.AT.. @ROM "o))and is used to delete !ows f!o) a table* To )a'e the wo!' #e!)anent. CA(CAD.TR TA7L.