You are on page 1of 27

Database Interfaces

Copyright 2004, Oracle. All rights reserved.

Objectives
After completing this lesson, you should be able to do the following: Use S !"#lus and iS !"#lus to access the Oracle Database $%g Describe the logical structure of tables Use S ! to &uery, manipulate, and define data Identify common database interfaces

4-2

Copyright 2004, Oracle. All rights reserved.

'hat Is S !(
S ! provides statements for a variety of tas)s, including: uerying data Inserting, updating, and deleting rows in a table *reating, replacing, altering, and dropping objects *ontrolling access to the database and its objects S ! unifies all of the preceding tas)s in one consistent language+

4-3

Copyright 2004, Oracle. All rights reserved.

Using S !
,here are several tools for interfacing with the database using S !: Oracle S !"#lus and iS !"#lus Oracle -orms, .eports, and Discoverer Oracle /nterprise 0anager ,hird1party tools

4-4

Copyright 2004, Oracle. All rights reserved.

/nterprise 0anager: Seeing the S !

4-5

Copyright 2004, Oracle. All rights reserved.

'hat Is S !"#lus(
*ommand1line tool Used interactively or in batch mode

$ sqlplus /nolog SQL*Plus: Release 10.1.0.2.0 - Production on Tue e! 1" 0#:1":1$ 200$ %op&rig't (c) 1*+2, 200$, -racle. .ll rig'ts reser/ed. SQL0 connect ric 1nter pass2ord: %onnected. SQL0 S1L1%T * R-3 dual4 5 6 SQL0
4-6 Copyright 2004, Oracle. All rights reserved.

'hat Is iS !"#lus(

4-7

Copyright 2004, Oracle. All rights reserved.

Using iS !"#lus

4-

Copyright 2004, Oracle. All rights reserved.

Describing Data

4-!0

Copyright 2004, Oracle. All rights reserved.

uerying Data
,he S1L1%T has three basic parts: ,he S1L1%T !ist ,he R-3 clause ,he 781R1 condition 2optional3

4-!!

Copyright 2004, Oracle. All rights reserved.

Sorting the Data

SQL0 S1L1%T last9na:e, depart:ent9id, p'one9nu:!er 2 R-3 e:plo&ees ; -R51R <= last9na:e4 L.ST9>.31 51P.RT31>T9?5 P8->19>@3<1R --------------- ------------- -------------------.!el +0 011.$$.1#$$.$2*2#" .nde +0 011.$$.1;$#.#2*2#+ .tAinson B0 #B0.12$.#2;$ .ustin #0 B*0.$2;.$B#* <aer "0 B1B.12;.++++ <aida ;0 B1B.12".$B#; <anda +0 011.$$.1;$#."2*2#+

4-!2

Copyright 2004, Oracle. All rights reserved.

4oining ,ables
5etting data from more than one table

4-!3

Copyright 2004, Oracle. All rights reserved.

0anipulating Data
SQL0 2 ; $ B # " ?>S1RT ?>T- e:plo&ees (13PL-=119?5, ?RST9>.31,L.ST9>.31,13.?L,P8->19>@3<1R, 8?R195.T1,C-<9?5,S.L.R=,%-33?SS?->9P%T, 3.>.D1R9?5,51P.RT31>T9?5) E.L@1S (****,F<o!F,F<uilderF,F!o!Ga!c.co:F,>@LL,s&sdate, F?T9PR-DH,>@LL,>@LL,100,*0)4

1 ro2 created. SQL0 @P5.T1 e:plo&ees S1T S.L.R=I#000 2 781R1 13PL-=119?5 I ****4 1 ro2 updated. SQL0 51L1T1 Jro: e:plo&ees 2 781R1 13PL-=119?5 I ****4 1 ro2 deleted.
4-!5 Copyright 2004, Oracle. All rights reserved.

Defining Data

4-!6

Copyright 2004, Oracle. All rights reserved.

Overview of ,ransactions

,ransaction $

%-33?T4

,ransaction 6

4-!7

Copyright 2004, Oracle. All rights reserved.

,ransaction *ontrol Statements


SQL0 S1L1%T * R-3 local9te:p4 no ro2s selected SQL0 ?>S1RT ?>T- local9te:p E.L@1S 2 (S=S5.T1, "#, B+)4 1 ro2 created. SQL0 S1L1%T * Jro: local9te:p4 T13P95.T1 8?9T13P L-9T13P --------- ---------- ---------2"--%T-0; "# B+ SQL0 R-LL<.%K4 Roll!acA co:plete. SQL0 S1L1%T * R-3 local9te:p4 no ro2s selected
4-!" Copyright 2004, Oracle. All rights reserved.

!oc)ing Data
Oracle Database $%g automatically loc)s data so that only one user can ma)e changes at a time+

4-!

Copyright 2004, Oracle. All rights reserved.

Other Statement *ategories


Session control statements: 0anage the properties of a user session System control statement: 0anages the properties of an Oracle instance /mbedded S ! statements: S ! statements within a procedural language program

4-20

Copyright 2004, Oracle. All rights reserved.

'hat Is #!7S !(
#!7S ! is a bloc)1structured language, which e8tends S ! with: Declarations:
# 9ariables # *onstants # *ursors

*ontrol structures:
# *onditional control # Iterative control # Se&uential control

/rror handling

4-2!

Copyright 2004, Oracle. All rights reserved.

/8ample #!7S ! :loc)


51%L.R1 qt&9on9'and >@3<1R(B)4 <1D?> S1L1%T quantit& ?>T- qt&9on9'and R-3 in/entor& 781R1 product I FT1>>?S R.%K1TF -R @P5.T1 - quantit&4 ? qt&9on9'and 0 0 T81> -- c'ecA quantit& @P5.T1 in/entor& S1T quantit& I quantit& - 1 781R1 product I FT1>>?S R.%K1TF4 ?>S1RT ?>T- purc'ase9record E.L@1S (FTennis racAet purc'asedF, S=S5.T1)4 1LS1 ?>S1RT ?>T- purc'ase9record E.L@1S (F-ut oJ tennis racAetsF, S=S5.T1)4 1>5 ? 4 %-33?T4 1>54

4-22

Copyright 2004, Oracle. All rights reserved.

Uses of #!7S !
:loc)s of #!7S ! are used in: Anonymous bloc)s -unctions #rocedures #ac)ages ,riggers Object types

4-23

Copyright 2004, Oracle. All rights reserved.

'hat Is 4ava(
4ava is an industry1standard, object1oriented programming language+ It includes the following concepts: A 4ava 9irtual 0achine 24903, which provides platform independence Automated storage management techni&ues !anguage synta8 that borrows from * and enforces strong typing

4-24

Copyright 2004, Oracle. All rights reserved.

Oracle and 4ava


A #!7S ! function:
@>%T?-> !alance (acct9id >@3<1R) R1T@R> >@3<1R ?S acct9!al >@3<1R4 <1D?> S1L1%T !al ?>T- acct9!al R-3 accts 781R1 acct9no I acct9id4 R1T@R> acct9!al4 1>54

*alling the function with 4ava:


%alla!leState:ent cst:t I conn.prepare%all(LMN I %.LL !alance(N)OL)4 cst:t.register-utPara:eter(1, T&pes. L-.T)4 cst:t.set?nt(2, acct>o)4 cst:t.ePecute@pdate()4 Jloat acct<al I cst:t.get loat(1)4

4-25

Copyright 2004, Oracle. All rights reserved.

'hat Is O*I(
O*I provides for: ,he Oracle *all Interface 2O*I3 is how all database features are made accessible to application developers+ O*I ma)es scalable and high1performance applications possible+ ;igher1level A#Is and tools use O*I indirectly for database access+

4-26

Copyright 2004, Oracle. All rights reserved.

Other A#Is
4ava Database *onnectivity 24D:*3 #ro"*7*<< #ro"*O:O! Oracle *<< Interface 2O**I3 Open Database *onnectivity 2OD:*3 Oracle Data #rovider for +=/, 2OD#+=/,3 Oracle Objects for O!/ 2OO>O3

4-27

Copyright 2004, Oracle. All rights reserved.

Summary
In this lesson, you should have learned how to: Use S !"#lus and iS !"#lus to access Oracle Database $%g Describe the logical structure of tables Use S ! to &uery, manipulate, and define data Identify common database interfaces

4-2

Copyright 2004, Oracle. All rights reserved.

#ractice >: Using S !


,his practice covers using iS !"#lus to: Describe tables Select from tables Update a table Delete from a table Undo changes

4-30

Copyright 2004, Oracle. All rights reserved.

You might also like