Вы находитесь на странице: 1из 96

10g PL/SQL

SQL Enhancements

SQLPLUS Enhancements External Tables Timestamp Datatypes PL/SQL enhancements

Final Schedule For Oracle1 ! "or#shop


D'TE 20-Sep-06 20-Sep-06 2 -Sep-06 2 -Sep-06 22-Sep-06 22-Sep-06 2 2 3 3 D'( Topics $o&ered 0! SQ2 & P23SQ2 / Hands #n %S F#rms 0! / Hands #n 0Part 1 %S F#rms 0! / Hands #n 0Part 21 $onducted %y Harsh & Vibhuti Pranali Pranali

0! %r$hite$ture, Grid & '%( Vibhuti 0! )a$*up, 'e$#+er, & -et.#r* 0! Per"#rman$e Tunin! Final Test, Quiz and Games Pranali Vibhuti, Harsh, Pranali

SQL Enhancements

4ulti-Table 5nsert 46'G6 Statement G'78P)9 (lause 6nhan$ements (%S6 enhan$ements :75-S / ne. s,nta; 5ntr#du$ti#n T# %nal,ti$al Fun$ti#ns 47<62 (lause 'e!ular 6;pressi#n

)ulti*Table +nsert
8sin! this "eature the 5-S6'T = S626(T statement $an be used t# insert r#.s int# multiple tables as part #" a sin!e <42 statement T,pes> 8n$#nditi#nal 5nsert (#nditi#nal 5nsert (#nditi#nal First 5nsert Pi+#tin! 5nsert

6;ample>
5-S6'T %22 4ulti table 5nsert ",E- S%2 ? 0000 T,E5-T7 sal@hist V%286S 0 64P5< , H5'6<%T6,S%21 ",E- 4G' ? 200 T,E5-T7 m!r@hist V%286S 064P5< , 4G' ,S%2 1 S626(T empn# 64P5< , hire@date H5'6<%T6 , Sal S%2 , m!r 4G' F'74 emp@#ld AH6'6 empn# ? 20 B

$urrent Scenario > +-SE.T +-TO re+enue 0pers#n,m#nth,re+enue1 SELE$T pers#n, C:anC, re+@Dan F'74 re+ert 8-57- %22 SELE$T pers#n, CFebC, re+@"eb F'74 re+ert 8-57- %22 SELE$T pers#n, E%prE ,re+@mar F'74 re+ert B +n /i/1 ! > +nsert 'LL into re+enue +alues 0pers#n ,C:%-C, re+@Dan1 into re+enue +alues 0pers#n, CF6)C, re+@"eb1 into re+enue +alues 0pers#n,E 4%'C, re+@mar1 select pers#n, re+@Dan, re+@"eb, re+@mar, re+@apr, re+@ma,, re+@Dun 0rom re+ertB
. 7

Example 1:Unconditional INSERT INSERT ALL INTO hbg2 VALUES (emp_no,name ) INTO hbg1 VALUES (emp_no,name) SELE T emp_no, name !RO" hbg #$ERE emp_no % 2&

Example 2: Conditional INSERT ALL INSERT ALL WHEN emp_no % ' THEN INTO hbg2 VALUES (emp_no,name ) WHEN emp_no () ' THEN INTO hbg1 VALUES (emp_no,name) SELE T emp_no,name !RO" hbg #$ERE emp_no % 2&

Example ! Conditional INSERT "IRST INSERT "IRST WHEN name )*$a+,h* THEN INTO hbg1 VALUES (emp_no,name) WHEN emp_no ) 2 THEN INTO hbg2 VALUES (emp_no,name) WHEN emp_no %2 an- emp_no ( ' THEN INTO hbg. VALUES (emp_no,name) ELSE INTO hbg' VALUES (emp_no,name) SELE T emp_no, name !RO" hbg&
. 10

Example #! Conditional INSERT ALL INSERT ALL WHEN name )*$a+,h* THEN INTO hbg1 VALUES (emp_no,name) WHEN emp_no ) 2 THEN INTO hbg2 VALUES (emp_no,name) WHEN emp_no %/ an- emp_no ( ' THEN INTO hbg. VALUES (emp_no,name) ELSE INTO hbg' VALUES (emp_no,name) SELE T emp_no, name !RO" hbg&

11

Example $! Pi%oting INSERT INSERT ALL INTO ,ale, VALUES (emp_0-,name,+eg0on1) INTO ,ale, VALUES (emp_0-,name,+eg0on2) INTO ,ale, VALUES (emp_0-,name,+eg0on.) SELE T emp_0-, name, +eg0on1,+eg0on2, +eg0on. !RO" ,ale,_ma0n&

12

Spe$i",in! F+.ST tells #ra$le t# s*ip subseFuent ",E- $lauses a"ter it "inds #ne true "#r the r#. t# be e+aluatedG Ae $an als# use an ELSE $lause t# tell #ra$le .hat t# d# i" n#ne #" the ",E- $lauses e+aluates t# true

13

6;ample 6> Usin! Table 'liases


+-SE.T 'LL ",E- #ttl H 00000 T,E+-TO small@#rders 1'LUES0#id, #ttl, sid, $id1 ",E- #ttl ? 00000 and #ttl H 200000 T,E- +-TO medium@#rders 1'LUES0#id, #ttl, sid, $id1 ",E- #ttl ? 200000 T,E- +-TO lar!e@#rders V%286S0#id, #ttl, sid, $id1 ",E- #ttl ? 2I0000 T,E+-TO spe$ial@#rders SELE$T #G#rder@id #id, #G$ust#mer@id $id, #G#rder@t#tal #ttl, #Gsales@rep@id sid, $G$redit@limit $l, $G$ust@email $em F.O) #rders #, $ust#mers $ ",E.E #G$ust#mer@id J $G$ust#mer@idB

14

Uses
4ulti table inserts are use"ul in data .areh#use s$enari#G 5nstead #" usin! sFlldr t# l#ad data int# multiple table , multi table inserts $#upled .ith an e;ternal table $an be usedG

15

)E.2E Statement
This spe$ialized statement $#mbines insert and update int# a sin!le #perati#nG 5t is intended "#r data .areh#usin! appli$ati#ns that per"#rm parti$ular patterns #" inserts and updatesG Pre+i#us appr#a$h "#r a$hie+in! the same .as> - 5nsert, i" "ailed #n primar, *e, then update - 8pdate, i" SQ2K-7TF78-< then insertG %+#id 4ultiple update statementsG -#., a sin!le SQ2 statement d#es the D#bG

16

Syntax > Ae $an $#nditi#nall, insert r#.s int# table ) "r#m table % .ith help #" sin!le SQ2 statementG )E.2E +-TO hi!h@s$#re@$#p, ) Target table US+-2 hi!h@s$#re % - source (can be a table or view or O- 0 %G nameJ)Gname1
subquerry) condition to either update or insert

",E- )'T$,ED TH6UPD'TE SET )Gs$#reJ%G s$#re ",E- -OT )'T$,ED TH6+-SE.T 1'LUES 0%Gname,%Gs$#re1B

17

Example 1: "e+ge 0n1o hbg1 2,0ng hbg on (hbg.emp_no ) hbg1.emp_no) 3hen ma14he1hen 2p-a1e ,e1 hbg1.name ) hbg.name 3hen no1 ma14he1hen 0n,e+1 (hbg1.emp_no, hbg1.name) 5al2e, (hbg.emp_no, hbg.name)
. 18

Example & : "e+ge 0n1o hbg1 2,0ng hbg on (hbg.emp_no ) hbg1.emp_no) 3hen ma14he1hen 2p-a1e ,e1 hbg1.name ) *hbg* 3hen no1 ma14he1hen 0n,e+1 (hbg1.emp_no, hbg1.name) 5al2e, (hbg.emp_no, hbg.name)
. 19

Example : "e+ge 0n1o hbg1 2,0ng hbg on (hbg.E"6_NO ) hbg1.E"6_NO) 3hen ma14he1hen 2p-a1e ,e1 hbg1.name ) hbg.name 3hen no1 ma14he1hen 0n,e+1 (emp_no, name) 5al2e, (hbg.emp_no, hbg.name)

20

Example #: "e+ge 0n1o hbg1 h 2,0ng hbg g on (h.E"6_NO ) g.E"6_NO) 3hen ma14he1hen 2p-a1e ,e1 h.name ) g.name 3hen no1 ma14he1hen 0n,e+1 (emp_no, name) 5al2e, (g.emp_no, g.name)

21

Enhancements in 1 ! 3
Ae $an n#. spe$i", )7TH in #ne SQ2 instead #" update #r 0and1 insert separate SQ2 statements (an als# delete r#.s "r#m the tar!et table durin! update #perati#n instead #" .ritin! a separate SQ2 statements

22

'd&anta!es3
Simpler t# use than pr#$edural $#de (#nsiderabl, "aster than usin! pr#$edural $#de (an be used in data .areh#usin! appli$ati#ns

23

2.OUP %( $lause Enhancements


'7228P
8sed t# $al$ulate sub-t#tals

(8)6
8sed t# !et $r#ss-tabulati#n results

24

25

26

27

.OLLUP 8sed t# $al$ulate sub-t#talsG 6;ample > SELE T E"6_I7, NA"E, SU"(RE8ION) !RO" ,ale, 8ROU6 9: R'LLUP(emp_0-,name)& Th0, 30ll -0,pla; <o+ g+o2p b; <+om +0gh1 1o le<1. So 1he g+o2p0ng 30ll be -one <0+,1 o< name an1hen o< emp0-

28

29

30

2roupin! Sets > Simple e;tensi#n t# G'78P )9 t# "a$ilitate multiple !r#upin!s


6;ample > sele$t <6PT-7,:7),4G',a+!0sal1 "r#m emp@#ld !r#up b, !r#upin! sets 00deptn#,D#b,m!r1, 0deptn#,m!r1, 0D#b,m!r11B

31

32

8ROU6IN8 SETS
= The example 0n 1he ,l0-e -0,pla;, 1he <ollo30ng: = To1al ,ala+; <o+ e5e+; -epa+1men1 (labele- 1) = To1al ,ala+; <o+ e5e+; -epa+1men1, >ob I7, anmanage+ (labele- 2) = 8+an- 1o1al (labele- .)

33

'd&anta!es
%ll the !r#up b, enhan$ements ma*e #nl, #ne pass #+er the base table (#de readabilit, is impr#+ed

34

$'SE Statement
F#ll#.in! are ne. (%S6 e;pressi#n t,pes Sear$hed (%S6 e;pressi#n -8225F (7%26S(6

35

36

37

38

ASE
= In a ,0mple ASE exp+e,,0on, O+a4le ,ea+4he, <o+ 1he <0+,1 #$EN ... T$EN pa0+ <o+ 3h04h exp+ 0, e?2al 1o 4ompa+0,on_exp+ an- +e12+n, +e12+n_exp+. I< none o< 1he #$EN ... T$EN pa0+, mee1 1h0, 4on-010on, an- an ELSE 4la2,e ex0,1,, 1hen O+a4le +e12+n, el,e_exp+. O1he+30,e, O+a4le+e12+n, n2ll. = :o2 4anno1 ,pe40<; 1he l01e+al NULL <o+ all 1he +e12+n_exp+, an- 1he el,e_exp+
. 39

NULLI!
= = = = = S(ntax NULLI! (expr1, expr2) In 1he ,;n1ax: expr1 0, 1he ,o2+4e 5al2e 4ompa+e- 1o expr2 expr2 0, 1he ,o2+4e 5al2e 4ompa+e- 301h expr1. (I< 01 0, no1 e?2al 1o expr1, expr1 = 0, +e12+ne-.)

40

41

OALES E
= = = = = S(ntax OALES E (expr1, expr2, ... exprn) In 1he ,;n1ax: expr1 +e12+n, 1h0, exp+e,,0on 0< 01 0, no1 n2ll expr2 +e12+n, 1h0, exp+e,,0on 0< 1he <0+,1 exp+e,,0on 0, n2ll an- 1h0, exp+e,,0on 0, no1 = n2ll = exprn +e12+n, 1h0, exp+e,,0on 0< 1he p+e4e-0ng exp+e,,0on, a+e n2ll
. 42

43

4oins
7ra$le Ii pr#+ides supp#rt "#r SQ2> III s,nta; -e. *e,.#rds li*e > / / / / ('7SS :75-%T8'%2 :758S5-G (2%8S6 7- (2%8S6

Full #uter D#in is p#ssible "r#m Ii

44

45

46

47

48

LEFT 4O+SQ2? S626(T eGename,eGdeptn#,dGdname F'74 emp@#ld e 26FT :75- dept d 7- 0 eGdeptn#JdGdeptn# 1B .+2,T 4O+SQ2? S626(T eGename,eGdeptn#,dGdname F'74 emp@#ld e '5GHT :75- dept d 7- 0 eGdeptn#JdGdeptn# 1B FULL 4O+SQ2? S626(T eGename,eGdeptn#,dGdname F'74 emp@#ld e F822 :75- dept d 7- 0 eGdeptn#JdGdeptn# 1B
. 49

+ntroduction To 'nalytical Functions


%nal,ti$ "un$ti#ns $#mpute an a!!re!ate +alue based #n a !r#up #" r#.sG The, di""er "r#m a!!re!ate "un$ti#ns in that the, return multiple r#.s "#r ea$h !r#upG

50

$ommon 'nalytic Functions


'%-L <6-S6@'%-L '7A@-84)6' F5'ST@V%286 3 2%ST@V%286 26%< 2%G

51

.'-5
'%-L $al$ulates the ran* #" a +alue in a !r#up #" +aluesG '#.s .ith eFual +alues "#r the ran*in! $riteria re$ei+e the same ran*G The P%'T5T57- *e,.#rd is used t# de"ine .here the ran* resetsG The spe$i"i$ $#lumn that is ran*ed is determined b, the 7'<6' )9 $lauseG 5" n# partiti#n is spe$i"ied, ran*in! is per"#rmed #+er the entire result setG '%-L assi!ns a ran* #" t# the smallest +alue unless des$endin! #rder is used G

52

Example 13

6a+1010on 0, op10onal an- O+-e+ 9; 0, 4omp2l,o+; SELE T emp_no, name ,ala+;, RAN@() OVER ( OR7ER 9: ,ala+; 7ES ) AS +1 !RO" 1e,11 B

53

Example &! SELE T emp_no, name, ,ala+;, RAN@() OVER (6ARTITION 9: emp_no OR7ER 9: ,ala+; 7ES ) AS +1 !RO" 1e,11

54

Dense .an#
The di""eren$e bet.een .'-5 and DE-SE6.'-5 is that DE-SE6.'-5 lea+es n# !aps in ran*in! seFuen$e .hen there are tiesG That is, i" ,#u .ere ran*in! a $#mpetiti#n usin! DE-SE6.'-5 and had three pe#ple tie "#r se$#nd pla$e, ,#u .#uld sa, that all three .ere in se$#nd pla$e and that the ne;t pers#n $ame in thirdG The '%-L "un$ti#n .#uld als# !i+e three pe#ple in se$#nd pla$e, but the ne;t pers#n .#uld be in "i"th pla$eG

55

'd&anta!e
(an be used t# #btain t#p - #r b#tt#m - ran*in!

(1) SELE T E"6_NO, NA"E, ,ala+;, RAN@() OVER( OR7ER 9: emp_no) AS +2 !RO" 1e,11 (2) SELE T E"6_NO, NA"E, ,ala+;, 7ENSE_RAN@() OVER( OR7ER 9: emp_no) AS +2 !RO" 1e,11

56

LEA)/LA*
= LA8 (5al2e_exp+e,,0on A,o<<,e1B A,-e<a2l1B) OVER (A?2e+;_pa+1010on_4la,eB o+-e+_b;_4la2,e) = LEA7 (5al2e_exp+e,,0on A,o<<,e1B A,-e<a2l1B) OVER (A?2e+;_pa+1010on_4la,eB o+-e+_b;_4la2,e) = 5al2e_exp+e,,0on C an be a 4ol2mn o+ a b20l1C0n <2n410on, ex4ep1 <o+ o1he+ anal;104 <2n410on,. = o<<,e1 C The n2mbe+ o< +o3, p+e4e-0ngD<ollo30ng 1he 42++en1 +o3, <+om 3h04h 1he -a1a 0, 1o be +e1+0e5e-. The -e<a2l1 5al2e 0, 1. = -e<a2l1 C The 5al2e +e12+ne- 0< 1he o<<,e1 0, o21,0-e 1he ,4ope o< 1he 30n-o3. The -e<a2l1 5al2e 0, NULL.

57

Example+ (1) SELE T empno, ename, ,al, LA8(,al, 1, /) OVER (OR7ER 9: ,al) AS ,al_p+e5, ,al C LA8(,al, 1, / ) OVER (OR7ER 9: ,al) AS ,al_-0<< !RO" emp& (2) SELE T empno, ename, ,al, LEA7(,al, 1, /) OVER (OR7ER 9: ,al) AS ,al_nex1, LEA7(,al, 1, /) OVER (OR7ER 9: ,al) C ,al AS ,al_-0<< !RO" emp&

58

"IRST,-ALUE /LAST,-ALUE
!IRST_VALUE D LAST_VALUE 0, an anal;104 <2n410on. I1 +e12+n, 1he <0+,1 D la,1 5al2e 0n an o+-e+e- ,e1 o< 5al2e,. I< 1he <0+,1 D la,1 5al2e 0n 1he ,e1 0, n2ll, 1hen 1he <2n410on +e12+n, NULL 2nle,, ;o2 ,pe40<; I8NORE NULLS. I< ;o2 ,pe40<; I8NORE NULLS, 1hen !IRST_VALUE D LAST_VALUE +e12+n, 1he <0+,1 nonCn2ll 5al2e 0n 1he ,e1, o+ NULL 0< all 5al2e, a+e n2ll.

59

Example+
Lo.e+t %al/e (1) SELE T empno, ename ,,al, LAST_VALUE (ename) OVER (OR7ER 9: ,al -e,4 RO#S 9ET#EEN UN9OUN7E7 6RE E7IN8 AN7 UN9OUN7E7 !OLLO#IN8 ) AS l5 !RO" (SELE T E !RO" emp #$ERE empno (F )& (2) SELE T empno, ename ,,al, !IRST_VALUE (ename) OVER (OR7ER 9: ,al a,4 RO#S 9ET#EEN UN9OUN7E7 6RE E7IN8 AN7 UN9OUN7E7 !OLLO#IN8 ) AS l5 !RO" (SELE T E !RO" emp #$ERE empno (F )& 6a+1010on b; 4an be 2,e. 60

Example+
Hig0e+t %al/e (1) SELE T empno, ename ,,al, !IRST_VALUE(ename) OVER (OR7ER 9: ,al -e,4 RO#S 9ET#EEN UN9OUN7E7 6RE E7IN8 AN7 UN9OUN7E7 !OLLO#IN8 ) AS h5 !RO" (SELE T E !RO" emp #$ERE empno (F )& (2) SELE T empno, ename ,,al, LAST_VALUE(ename) OVER (OR7ER 9: ,al a,4 RO#S 9ET#EEN UN9OUN7E7 6RE E7IN8 AN7 UN9OUN7E7 !OLLO#IN8 ) AS h5 !RO" (SELE T E !RO" emp o+-e+ b; ,al -e,4)&

61

R'WNU12ER
= RO#_NU"9ER 0, an anal;104 <2n410on. I1 a,,0gn, a 2n0?2e n2mbe+ 1o ea4h +o3 1o 3h04h 01 0, appl0e(e01he+ ea4h +o3 0n 1he pa+1010on o+ ea4h +o3 +e12+neb; 1he ?2e+;), 0n 1he o+-e+e- ,e?2en4e o< +o3, ,pe40<0e- 0n 1he o+-e+_b;_4la2,e, beg0nn0ng 301h 1.

= U,e o< 1he <2n410on le1, ;o2 0mplemen1 1opCN, bo11omCN ?2e+;.

62

Example+
SELE T -epa+1men1_0-, la,1_name, emplo;ee_0-, RO#_NU"9ER() OVER (6ARTITION 9: -epa+1men1_0- OR7ER 9: emplo;ee_0-) AS emp_0!RO" emplo;ee,&

63

)ODEL $lause
SQ2 4#del $lause, a p#.er"ul ne. e;tensi#n t# the SQ2 S626(T statement 47<62 $lause, is a s$alable and mana!eable .a, #" $#mputin! business m#dels in the database Aith the SQ2 4#del $lause, .e $an +ie. Fuer, results in the "#rm #" multidimensi#nal arra,s & then appl, "#rmulas t# $al$ulate ne. arra, +aluesG The "#rmulas $an be s#phisti$ated interdependent $al$ulati#ns .ith inter-r#. and inter-arra, re"eren$esG

64

= S:NTAG (p+0o+ 4la2,e, o< SELE T ,1a1emen1% "O7EL Ama0nB A+e<e+en4e mo-el,B A6ARTITION 9: ((4ol,%)B 7I"ENSION 9: ((4ol,%) "EASURES ((4ol,%) AI8NORE NAVB H A@EE6 NAVB ARULES AU6SERT H U67ATEB AAUTO"ATI OR7ER H SEIUENTIAL OR7ERB AITERATE (n) AUNTIL (4on-010on%B B ( (4ell_a,,0gnmen1% ) (exp+e,,0on% ... )

65

E3A1PLE 1
SELE T SU9STR(4o2n1+;,1,2/) 4o2n1+;, SU9STR(p+o-,1,1J) p+o-, ;ea+, ,ale, !RO" ,ale,_50e3 #$ERE 4o2n1+; IN (*I1al;*,*Kapan*) "O7EL RETURN UP)ATE) R'WS 6ARTITION 9: (4o2n1+;) 7I"ENSION 9: (p+o-, ;ea+) "EASURES (,ale ,ale,) RULES ( ,ale,A*9o2n4e*, 2//2B ) ,ale,A*9o2n4e*, 2//1B L ,ale,A*9o2n4e*, 2///B, ,ale,A*: 9ox*, 2//2B ) ,ale,A*: 9ox*, 2//1B, ,ale,A*2_6+o-241,*, 2//2B ) ,ale,A*9o2n4e*, 2//2B L ,ale,A*: 9ox*, 2//2B) OR7ER 9: 4o2n1+;, p+o-, ;ea+&

66

67

E3A1PLE & ! "'R L''P SELE T SU9STR(4o2n1+;,1,2/) 4o2n1+;, SU9STR(p+o-,1,1J) p+o-, ;ea+, ,ale, !RO" ,ale,_50e3 #$ERE 4o2n1+;)*I1al;* "O7EL RETURN U67ATE7 RO#S 6ARTITION 9: (4o2n1+;) 7I"ENSION 9: (p+o-, ;ea+) "EASURES (,ale ,ale,) RULES ( ,ale,A!OR p+o- IN (6+o-1*, M6+o-2*), 2//JB ) 1.. E ,ale,A V(p+o-), 2//1B ) OR7ER 9: 4o2n1+;, p+o-, ;ea+&
. 68

Partiti#n $#lumns de"ine the l#!i$al bl#$*s #" the result set in a .a, similar t# the partiti#ns #" the anal,ti$al "un$ti#ns <imensi#n $#lumns de"ine the multi-dimensi#nal arra, and are used t# identi", $ells .ithin a partiti#n 'ules in the 47<62 $lause are applied t# ea$h partiti#n independent #" #ther partiti#nsG Partiti#ns ser+e as a b#undar, p#int "#r parallelizin! the m#del $#mputati#n

69

'd&anta!es O0 )ODEL $lause Per"#rman$e>4#del $lause pr#$essin! eliminates the need "#r man, SQ2 D#in and uni#n #perati#ns S$alabilit,>The 4#del $lause le+era!es 7ra$le parallelism, e""i$ientl, usin! all s,stem res#ur$es made a+ailable t# itG 4ana!eabilit,>(#mputati#ns are $entralized $l#se t# the data, s# it redu$es in$#nsisten$, & p##r se$urit,

70

.e!ular Expressions
'e!ular e;pressi#ns spe$i", patterns t# sear$h "#r in strin! data % re!ular e;pressi#n $an spe$i", $#mple; patterns #" $hara$ter seFuen$es 'e!ular e;pressi#n supp#rt in SQ23P2SQ2 is implemented .ith "un$ti#ns li*e > / .E2E7P6L+5E, / .E2E7P6.EPL'$E / .E2E7P6+-ST.

71

Example
SQ2? S626(T "irst@name, last@name F'74 empl#,ees AH6'6 '6G6MP@25L6 0"irst@name,CNSte0+Oph1enPC1B 6;amine the strin!, l##*in! "#r the "irst substrin! b#unded b, $#mmas SQ2? S626(T '6G6MP@S8)ST'0CQ00 7ra$le Par*.a,, 'ed.##d Sh#res, (%C, C,RN,ST,C1 U'6G6MP'@S8)ST'U F'74 <8%2B

72

EGA"6LES (1) SELE T N0p !RO" N0p4o-e #$ERE RE8EG6_LI@E(N0p, *AOA:-0g01:BB*)& Re,2l1 : ab12. 12.x; (2) SELE T RE8EG6_INSTR(*Koe Sm01h, 1//'J 9e++; Lane, San Ko,eph, A P12.'*, *AA:-0g01:BBQJRS*) AS +x_0n,1+ !RO" -2al& Re,2l1 : 'J (.) SELE T RE8EG6_SU9STR(*<0+,1 <0el-, ,e4on- <0el- , 1h0+- <0el-*, *, AO,BE,*) !RO" -2al& Re,2l1 : , ,e4on- <0el- ,

73

EGA"6LES (') SELE T RE6LA E(*Koe Sm01h*,* *, * *) AS +epla4e !RO" -2al& Re,2l1 : Koe Sm01h (J) SELE T RE8EG6_RE6LA E(*Koe Sm01h*, *( )Q2,R*, * *) AS RG_RE6LA E !RO" -2al& Re,2l1 : Koe Sm01h (F) SELE T RE8EG6_RE6LA E(*Ellen $0l-0 Sm01h*, *(.E) (.E) (.E)*, *T., T1 T2*)& Re,2l1 : Sm01h, Ellen $0l-0

74

SQL PLUS Enhancement


Ae ha+e enabled displa,in! database name at SQ2Pr#mpt )ut "r#m SQ2 pr#mpt, i" #ne $#nne$ts t# di""erent database, the ne. database name is n#t displa,ed This se$urit, "la. is addressed in 0! -(SS2V? conn username/password@HISTLV Connected. H5ST2V?

75

Sp##l $#mmand is enhan$ed / %ppend #r repla$e p#ssible t# e;istin! sp##l "ile -e. <6F5-6 +ariables / @<%T6 de"ault the @<%T6 +ariable is d,nami$ and sh#.s the $urrent date / @P'5V526G6 The @P'5V526G6 +ariable indi$ates the pri+ile!e le+el #" the $urrent $#nne$ti#n / @8S6' The @8S6' +ariable $#ntains the user name $#nne$ted set sFlpr#mpt C&@user &@pri+ile!e &@date SQ2P28S? C
. 76

External Tables

77

"hat are External Tables8


These are li*e re!ular tables e;$ept that> - The, are read-#nl, tables - <42 #perati#ns 3 5nde; $reati#n n#t p#ssible - <ata is st#red e;ternall, in "lat-"iles (an be Fueried li*e a n#rmal table Supp#rts parallelism St#res #nl, the mappin! in"# bet.een table $#lumns and "lat-"ile $#ntents
. 78

(reate the table as


$reate table emp@l#ad 0 64P-7 -84)6'0V1 ,<6PT-7 -84)6'021 1 7'G%-5W%T57- 6MT6'-%2 0 t,pe #ra$le@l#ader de"ault dire$t#r, data@dir a$$ess parameters 0 bad"ile EempGbadX l#!"ile EempGl#!X "ields terminated b, C,C 1 l#$ati#n 0CempGdatC1

79

= 6+0o+ 1o O+a4le 1/g, ex1e+nal 1able, 3e+e +ea-Conl;. $o3e5e+, 0n 1/g, ex1e+nal 1able, 4an al,o be 3+011en 1o. = Loa-0ng an2nloa-0ng 4o2l- be -one 0n pa+allel0,m. (6ARALLEL 4la2,e)

80

%ene0its
Generate "lat "iles #n the tar!et s,stem seriall, #r in parallel Helps in $ases .here 6;ternal table dri+er $ann#t handle $#mple; 6T20 e;tra$ti#n trans"#rmati#n l#adin!1 5n this data is internall, $#n+erted "r#m #ra$le internal representati#n t# nati+e e;ternal representati#nG

81

Usa!e
8sed in TS%T t# !enerate !raphs based #n tradin!s,stem data (an be used in <ataAareH#usin! 60;tra$ti#n1T0rans"#rmati#n120#adin!1 pr#$ess (an d# a.a, .ith T'%<6S (apture pr#$ess in 7P4S and 5-<6M

82

Date*Time support

83

Int4od/ction
7a1eC10me -a1a 1;pe,
/ T546ST%4P / T546ST%4P A5TH T546 W7-6 / T546ST%4P A5TH 27(%2 T546 W7-6

In1e+5al -a1a 1;pe,


U INTERVAL 7A: TO SE ON7 U INTERVAL :EAR TO "ONT$

84

T+)EST')P Data Types


The T546ST%4P datat,pe is an e;tensi#n #" the <%T6 datat,peG 5t als# st#res "ra$ti#nal part #" se$#ndsG Spe$i", the T546ST%4P datat,pe as "#ll#.s> T546ST%4P R0"ra$ti#nal@se$#nds@pre$isi#n1S .here "ra$ti#nal@se$#nds@pre$isi#n is number #" di!its in "ra$ti#nal part #" S6(7-< "ieldG
. 85

+nter&al Data Types


8sed t# st#re the di""eren$e bet.een datetime +aluesG There are t.# $lasses #" inter+als > / 9ear-m#nth inter+als / <a,-time inter+als 5nter+al date t,pes are use"ul "#r "le;ible arithmeti$ #perati#ns G

86

Ae $an add +ari#us date data t,pes t# ea$h #ther Example> 5nter+al da,-t#-se$#nd data t,pe SQL> select interval '12 ' da!"#$ % interval '&'1 ' (our to minute % interval ') ' second 2 *rom dual+ I,T-.V/L'12 '0/1"#$%I,T-.V/L'&'1 'H23.T24I,3 T-%I,T-.V/L') 'S-C2,0 55555555555555555555555555555555555555555555 55555555 % 12 &'1 ') .

87

Usa!e 8sed in 5-<6M t# "ind trade time la! bet.een stratus and 72TP databases P#ssible usa!e in 7P4S , 5-<6M and #ther 72TP appli$ati#ns, i" sub-se$#nd data is reFuired 8sa!e als# in 7'<6'S appli$ati#n

88

PL / SQL Enhancements

89

'SSO$+'T+1E '..'(S
%ss#$iati+e arra,s are sets #" *e,-+alue pairs, .here ea$h *e, is uniFue and is used t# l#$ate a $#rresp#ndin! +alue in the arra,G Startin! .ith 7ra$le Ii , the *e, $an be a strin! data t,peG Eg: t,pe p#pulati#n@t,pe is T%)26 #" -84)6' 5-<6M )9 V%'(H%'20201B state@p#pulati#n p#pulati#n@t,peB state@p#pulati#n0CT%452-%<8C1>J20000B

90

7E LARE T:6E 4o2n1+;_1ab IS TA9LE O! VAR $AR2(J/) IN7EG 9: VAR $AR2(J)& 1_4o2n1+; 4o2n1+;_1ab& 9E8IN CC 6op2la1e looV2p 1_4o2n1+; (*U@*) :) *Un01e- @0ng-om*& 1_4o2n1+; (*US*) :) *Un01e- S1a1e, o< Ame+04a*& 1_4o2n1+; (*!R*) :) *!+an4e*& 1_4o2n1+; (*7E*) :) *8e+man;*& CC !0n- 4o2n1+; name <o+ ISO 4o-e W7EW 79"S_OUT6UT.6UT_LINE(*ISO 4o-e W7EW ) * HH 1_4o2n1+; (*7E*))& EN7&
. 91

8ses %nd %d+anta!es 2i*e SQ2 table > retrie+e +alues based #n primar, *e, / %ppr#priate "#r small l##*up tables / 5t helps in "ast l##*up "#r an indi+idual element .ith#ut *n#.in! its p#siti#n .ithin the arra, and .ith#ut ha+in! t# l##p thr#u!h all the arra, elements / Subs$ripts $an be ne!ati+e and n#n-seFuential / P23SQ2 aut#mati$all, $#n+erts bet.een h#st arra,s and ass#$iati+e arra,s / )ul*-bindin! #" h#st arra,s i3# t# ass#$iati+e arra,s usin! P23SQ2 bl#$*s

92

PL/SQL -ati&e $ompilation


Speeds up P23SQ2 pr#$edures b, $#mpilin! them int# nati+e $#de residin! in shared librariesG Pr#$edures are translated int# ( $#de, $#mpiled and lin*ed int# the #ra$le pr#$ess ),passes the runtime interpretati#n !i+in! "aster runtime per"#rman$e <ebu!!in! t##ls "#r P23SQ2 d# n#t handle pr#$edures $#mpiled "#r nati+e e;e$uti#nG
.

93

Setup 'nd +mplementation


(reate a dire$t#r, "#r st#rin! the shared librar, and set this path as P2SQ2@-%T5V6@25)'%'9@P%TH %lter Sessi#n set plsFl@$#de@t,peJE-%T5V6 E %lter Sessi#n set plsFl@$#mpiler@"la!s J C-%T5V6CB (reate #r 'epla$e #r alter the Subpr#!rams 'un an, s$ript .hi$h $reates a set #" 7ra$le Supplied pa$*a!esG (reate a <) usin! a pre$#n"i!ured init "ile .ith plsFl@$#de@t,pe J -%T5V6G = SELE T ob>e41_name, pa+am_name, pa+am_5al2e !RO" 2,e+_,1o+e-_,e110ng, #$ERE pa+am_name LI@E *pl,?lXMAn- ob>e41_name IN (*LOA7ER*, *79RG_UTIL*)&
. 94

Table Functions
8sed t# pr#du$e a $#lle$ti#n #" r#.s that $an be Fueried li*e a database table #r assi!ned t# a P23SQ2 $#lle$ti#n +ariableG 5nput is a $#lle$ti#n #" r#.s in "#rm #" V%''%9, P23SQ2 table #r '6F (8'S7'G %re in+#*ed "r#m S626(T statementXs F'74 $lauseG The $#lle$ti#n #" r#.s returned $an be pipelinedG The e;e$uti#n #" a table "un$ti#n $an be parallelizedG

95

96

Вам также может понравиться