You are on page 1of 119

Oracle Developer A Tutorial on Oracle Forms, Reports and Graphics

Covering Developer version 6.0 and 6i for indo!s "#$"%$&T$'000

Richard (olo!c)a*
Computers Information Systems Department Zicklin School of Business, Baruch College, CUNY and Center for Information Management, Integration and Connecti ity !CIMIC" #utgers Uni ersity richard$holo%c&ak'(aruch)cuny)edu
Version 4.0 Thu Apr 12 21:07:06 EDT 2001 Please feel free to use these tutorials for your own personal use, education, advancement, training, etc. However, I kindly ask that you respect the time and effort I have put into this work by not distributing copies, either in whole or in part, for your personal gain. You may not under any circumstances download, cache or host copies of these tutorials on your own servers. Use of these tutorials for commercial training requires a special arrangement with the author or authors.

Contents

*) Introduction +) ,rere-uisites .) De eloper /ools


o o

.)* Starting De eloper tools under 0indo%s 123143N/3+555 .)+ Starting De eloper tools under UNI6

7) /he 8racle 9orms Designer Main Screen


o o

7)* 8racle 9orms 8(:ect Na igator 7)+ Connecting to the Data(ase

2) 9orms Design ;) Creating a 9orm %ith a Single Block


o o

;)* Creating a Ne% Block ;)+ /he <ayout =ditor

o o

;). Displaying ,roperties ;)7 Sa ing, >enerating and #unning 9orms


;)7)* Sa ing a 9orm ;)7)+ Compiling3Building a 9orm ;)7). #unning a 9orm ;)7)7 #unning a 9orm as a ?a a @pplication or @pplet ;)7)7 Auery By =Bample

;)2 =BerciseC Creating a Single Block 9orm

D) Creating a MasterEDetail 9orm


o o

D)* /he MasterEDetail #elationship D)+ Steps to Create a MasterEDetail 9orm


D)+)* Create the Master Block D)+)+ Create the Detail Block

o o o o

D). #elation ,roperties of a MasterEDetail 9orm D)7 ,rogram Units in a MasterEDetail 9orm D)2 =Btending MasterEDetail 9orms D); =BerciseC Creating a Master3Detail 9orm

4) <ist of Falues !<8Fs" and NonEBase /a(le 9ields


o

4)* Creating a <ist of Falues


4)*)* Create a ne% <8F 8(:ect 4)*)+ Specify the <8F Auery /eBt 4)*). Specify the Column Mapping ,roperties 4)*)7 @ttach the <8F to the item 4)*)2 /est the <8F

4)+ NonEBase /a(le fields


4)+)* @dding a Ne% Item to an =Bisting Data Block 4)+)+ Creating a /rigger

4)+). Create a ne% <ist of Falues

4). =BerciseC Creating an <8F and NonEBase /a(le field

1) 8racle 9orms ,rogram Units and Stored ,rogram Units


o

1)* Creating ,rocedures in 8racle 9orms


1)*)* @dd a ne% item to the =M,<8Y== Block 1)*)+ Create a ,rocedure to Count 8ther Department Mem(ers 1)*). Create a /rigger to Call the ,rocedure 1)*)7 Sa e, Compile and #un the 9orm

o o

1)+ Creating Stored ,rogram Units !,rocedures" in SA<G,lus 1). @dditional Stored ,rocedures and /riggers

1).)* >enerating uni-ue or consecuti e identifiers using the ta(le 1).)+ >enerating uni-ue or consecuti e identifiers using an 8racle Se-uence 1).). Checking constraints at the client 1).)7 @dding @lerts !,opEup Messages" 1).)2 ,opulate items %ith default alues 1).); @ttaching functionality to command (uttons 1).)D ,assing parameters (et%een forms

1)7 =BerciseC ,rocedures and /riggers

*5) 8racle #eports Basics


o o o o

*5)* Starting De eloper tools under 0indo%s 123143N/3+555 *5)+ /he 8racle #eports 8(:ect Na igator *5). Creating #eports in 8racle #eports *5)7 Creating a SingleE/a(le #eport

*5)7)* Specify the Data Model and <ayout *5)7)+ Sa ing, >enerating and #unning the #eport

*5)2 =BerciseC Creating a #eport

*5); Creating a MasterEDetail #eport


*5);)* Specify the MasterEDetail Data Model and <ayout *5);)+ Sa ing and #unning the MasterEDetail #eport

o o

*5)D =BerciseC Creating a MasterEDetail #eport *5)4 ,arameter forms in 8racle #eports

*5)4)* Building a Custom ,arameter 9orm

** Creating Menus in 8racle 9orms


o o

**)* /he 8racle 9orms Menu Hierarchy **)+ Creating a Custom Menu

*+ >raphics and the Chart 0i&ard


o o

*+)* >raphics and the Chart 0i&ard *+)+ =BerciseC @dding a Chart to a #eport

*. 8racle Schema Builder


o o o

*.)* Creating Ne% Schema 8(:ects *.)+ Displaying =Bisting Schema 8(:ects *.). @dding #elationships (et%een /a(les

+. ,ntroduction
/his tutorial introduces the 8racle De eloper ;)5 and ;i suite of tools %hich include 8racle 9orms ;)5, 8racle #eports ;)5, 8racle >raphics ;)5, 8racle Schema Builder ;)5 and 8racle ,rocedure Builder ;)5) /he main o(:ecti es are to demonstrate and pro ide handsEon instructions on creating and modifying data entry and -uery forms in arious configurations, reports and graphics) In addition, the final section gi es some instructions on the use of the Schema Builder) /his set of 8racle tools !as of @pril, +55*" is no% (undled along %ith 0e(DB and 8racle ?De eloper in the 8racle Internet De eloper Suite CD ,ack) Ca eatsC ,lease note that 8racle tends to change things like menu items, prompts and other small things (et%een each ma:or !certainly" and often minor release) Depending on the eBact release of De eloper ; or ;i you ha e, you may find some small discrepencies (et%een %hat is sho%n in this tutorial and %hat you see on your screen)

'. -rere.uisites
Before follo%ing this tutorial, a student must ha e a alid user account in an 8racle ser er) Contact your DB@ or systems administrator to learn the details of ho% 8racle ser er is set up in your organi&ation) /his tutorial relies on the eBistence of a fe% ta(les in the studentIs schema) Use the 8racle SA<G,lus tool to create three ta(les named EMPLOYEE, DEPARTMENT and DEPENDENT %ith the follo%ing attri(utes) NoteC /his schema originally appears in the (ookC #ame& =lmasri and Shamkant B) Na athe, Fundamentals of Database Systems) Second =dition) @ddisonE0esley ,u( Co, *117) /0-3O4// /a(le D/-ART0/&T /a(le Attri1ute Data T2pe Attri1ute Data T2pe 9N@M= F@#CH@#!4" DN@M= F@#CH@#!*2" MINI/ F@#CH@#!+" DNUMB=# NUMB=#!+" <N@M= F@#CH@#!4" M>#SSN NUMB=#!*+" SSN NUMB=#!*+" M>#S/@#/D@/= D@/= BD@/= D@/= @DD#=SS F@#CH@#!.5" D/-/&D/&T /a(le S=6 F@#CH@#!*" Attri1ute Data T2pe S@<@#Y NUMB=#!D" =SSN NUMB=#!*+" SU,=#SSN NUMB=#!*+" D=,=ND=N/$N@M= F@#CH@#!*5" DN8 NUMB=#!+" S=6 F@#CH@#!*" BD@/= #=<@/I8NSHI, D@/= F@#CH@#!*5"

/he follo%ing C#=@/= /@B<= and INS=#/ statements can (e used to create the a(o e ta(les and insert some (aseline data using the 8racle SA<G,lus tool) Note that different ersions of 8racle accept either + digit or 7 digit year designations in the D@/= datatype) It seems the latest ersions !8racle4 and 8racle4i" default to accept 7 digit years) /he INS=#/ statements (elo% should (e formatted accordingly)
CREATE TA LE e!p"o#ee $%NAME VARC&AR2$1'()

M*N*T LNAME ++N DATE ADDRE++ +E. +ALARY +,PER++N DNO

VARC&AR2$2() VARC&AR2$1'() N,M ER$12( NOT N,LL) DATE) VARC&AR2$-'() VARC&AR2$1() N,M ER$7( NOT N,LL) N,M ER$12() N,M ER$2( NOT N,LL( /

ALTER TA LE e!p"o#ee ADD CON+TRA*NT p01e!p"o#ee PR*MARY 2EY $ssn(/ CREATE TA LE DEPARTMENT $DNAME VARC&AR2$1'() DN,M ER N,M ER$2( NOT N,LL) M3R++N N,M ER$12() M3R+TARTDATE DATE( / ALTER TA LE 4ep5r6!en6 ADD CON+TRA*NT p014ep5r6!en6 PR*MARY 2EY $4nu!7er(/ CREATE TA LE DEPENDENT $E++N DEPENDENT1NAME +E. DATE RELAT*ON+&*P N,M ER$12() VARC&AR2$1'() VARC&AR2$1() DATE) VARC&AR2$12(( /

ALTER TA LE 4epen4en6 ADD CON+TRA*NT p014epen4en6 PR*MARY 2EY $essn) 4epen4en61n5!e(/ ALTER TA LE 4epen4en6 ADD CON+TRA*NT 801e!p"o#ee %ORE*3N 2EY $essn( RE%ERENCE+ e!p"o#ee $ssn(/ ALTER TA LE e!p"o#ee ADD CON+TRA*NT 8014ep5r6!en6 %ORE*3N 2EY $4no( RE%ERENCE+ 4ep5r6!en6 $4nu!7er(/ *N+ERT *NTO DEPARTMENT VAL,E+ $9RE+EARC&9) ') ---44'''') 922:MAY:1;7<9( / *N+ERT *NTO DEPARTMENT VAL,E+ $9ADM*N*+TRAT*ON9) 4) ;<76'4-21) 901:=AN:1;<'9( / *N+ERT *NTO DEPARTMENT VAL,E+ $9&EAD>,ARTER+9) 1) <<<66'''') 91;:=,N:1;719( / *N+ERT *NTO EMPLOYEE VAL,E+ $9=O&N9)9 9)9+M*T&9)12-4'67<;)90;:=AN:1;''9)97-1 %ONDREN) &O,+TON) T.9) 9M9)-0000)---44'''')'( / *N+ERT *NTO EMPLOYEE VAL,E+ $9%RAN2L*N9)9T9)9?ON39)---44'''')90<:DEC:1;4'9)96-< VO++)&O,+TON T.9) 9M9)40000)<<<66'''')'( / *N+ERT *NTO EMPLOYEE VAL,E+ $9AL*C*A9)9=9)9@ELAYA9);;;<<7777)91;:=,L:1;'<9)9--21 CA+TLE) +PR*N3) T.9) 9%9)2'000);<76'4-21)4( / *N+ERT *NTO EMPLOYEE VAL,E+ $9=ENN*%ER9)9+9)9?ALLACE9);<76'4-21)920:=,N:1;-19)92;1 ERRY) ELLA*RE) T.9) 9%9)4-000)<<<66'''')4( /

*N+ERT *NTO EMPLOYEE VAL,E+ $9RAME+&9)929)9NARAYAN9)666<<4444)91':+EP:1;'29)9;7' %*RE OA2) &,M LE) T.9) 9M9)-<000)---44'''')'( / *N+ERT *NTO EMPLOYEE VAL,E+ $9=OYCE9)9A9)9EN3L*+&9)4'-4'-4'-)9-1:=,L:1;629)9'6-1 R*CE) &O,+TON) T.9) 9%9)2'000)---44'''')'(/ *N+ERT *NTO EMPLOYEE VAL,E+ $9A&MAD9)9V9)9=A AR9);<7;<7;<7)92;:MAR:1;';9)9;<0 DALLA+) &O,+TON) T.9) 9M9)2'000);<76'4-21)4( / *N+ERT *NTO EMPLOYEE VAL,E+ $9=AME+9)9E9)9 OR39)<<<66'''')910:NOV:1;279) 94'0 +TONE) &O,+TON) T.9) 9M9)''000)N,LL)1( / *N+ERT *NTO DEPENDENT *N+ERT *NTO DEPENDENT *N+ERT *NTO DEPENDENT *N+ERT *NTO DEPENDENT *N+ERT *NTO DEPENDENT *N+ERT *NTO DEPENDENT 1;'79)9+PO,+E9(/ *N+ERT *NTO DEPENDENT VAL,E+ VAL,E+ VAL,E+ VAL,E+ VAL,E+ VAL,E+ $---44'''')9AL*CE9)9%9)90':APR:1;769)9DA,3&TER9( / $---44'''')9T&EODORE9)9M9)92':OCT:1;7-9)9+ON9( / $---44'''')9=OY9)9%9)90-:MAY:1;4<9)9+PO,+E9(/ $12-4'67<;)9M*C&AEL9)9M9)901:=AN:1;7<9)9+ON9(/ $12-4'67<;)9AL*CE9)9%9)9-1:DEC:1;7<9)9DA,3&TER9(/ $12-4'67<;)9EL*@A ET&9)9%9)90':MAY:

VAL,E+ $;<76'4-21)9A NER9)9M9)926:%E :1;-29)9+PO,+E9(/

5. Developer Tools
8racle De eloper contains . main componentsC *) 8racle 9orms E 9or designing data entry forms) +) 8racle #eports E 9or designing reports) .) 8racle >raphics E 9or designing graphics such as charts that can (e added to forms or reports) @dditional components includeC *) ,rocedure Builder E @n integrated de elopment en ironment to %rite and de(ug stored procedures !program units" for use in the 8racle data(ase or in any of the De eloper tools) +) Auery Builder E @ >UI (ased -uery (uilder tool) Aueries can (e stored in the data dictionary or in a file system for later use and sharing) .) Schema Builder E @ >UI tool for creating and modifying ta(les, ie%s and constraints) 7) /ranslation Builder E @ tool for creating foreign language ersions of applications %ritten in De eloper) 2) ,ro:ect Builder E @ soft%are de elopment pro:ect management system that manages source code for all De eloper components)

;) ,=CS E /he 8racle ,erformance = aluation3Collection System E 9or profiling the eBecution and performance of applications de eloped %ith 8racle tools) D) Disco erer E @ data (ro%sing tool that can (e customi&ed for endEusers) /his tutorial co ers the De eloper 9orms, #eports and >raphics components and gi es a (rief introduction to the Schema Builder and ,rocedure Builder tools) In the follo%ing section, the procedures to run 8racle 9orms under MS 0indo%s 123143N/3+555 %ill (e gi en)

5.+ 6tarting Developer tools under

indo!s "#$"%$&T$'000

@ typical installation of De eloper creates se eral folders under the Start ,rograms menu) /he main folders for the De eloper programs for 8racle 9orms ;i are found under the menu itemC
Or5A"e %or!s 6i and include the following items:

/o run 8racle 9orms ;i under 0indo%s 123143N/3+555, click on the +65r6 :B ProCr5!s :B Or5A"e %or!s6i :B %or! ui"4er menu item) /o run 8racle #eports under 0indo%s 123143N/3+555, click on the +65r6 :B ProCr5!s :B Or5A"e Repor6s 6i :B Repor6
ui"4er

menu item)

/o run 8racle >raphics under 0indo%s 123143N/3+555, click on the +65r6 :B ProCr5!s :B Or5A"e %or!s D Repor6s 6i :B 3r5phiAs ui"4er menu item) 9or older ersions of 8racle De eloper the start menu %ould might ha e items such asC DeEe"oper 2000 R2.1 or DeEe"oper 2000 R2.0 and so on) NoteC In your organi&ation, De eloper may (e installed or configured slightly differently) In particular, the programs may (e grouped under different menus) ,lease contact your DB@ or systems administrator, or refer to any local documentation to learn ho% to run the De eloper tools)

5.' 6tarting Developer tools under 7&,8


8racle also makes a ersion of De eloper ;i that runs under UNI6) /his ersion uses 6E 0indo%s %ith the Motif 6E0indo%s li(raries as a graphical user interface) If your ersion of De eloper is installed under UNI6, use the follo%ing command lines to start the different toolsC

Developer Tool 9orms De eloper ;)5 for 6E0indo%s Motif ,rocedure Builder ;)5 for 6E0indo%s Motif

7&,8 Command f;5desm pl(ild;5m

>raphics De eloper ;)5 for 6E0indo%s Motif g;5desm #eports De eloper ;)5 for 6E0indo%s Motif r%(ld;5 Under UNI6, it may (e necessary to set certain en ironment aria(les such as /J;5$IC8N, UI$IC8N, 98#MS;5$,@/H and so on) Upon installation, eBample shell scripts to set these en ironment aria(les are installed in the 8racle Home directory)

9. The Oracle Forms Designer 0ain 6creen


8nce the appropriate menu item has (een clicked on !for 0indo%s 123143N/3+555", the 8racle 9orms Builder 0elcome Screen %ill appearC

9orms ;)5 displays this %elcome screen as a -uick %ay to start %orking and designing forms) 9or this tutorial, %e %ill %ork directly from the 8(:ect Na igator since this is this most general %ay to %ork %ith forms) /o continue to the 8(:ect Na igator from the 0elcome screen, click on the Cancel (utton or select the KBuild a form ManuallyK option and click 8J) In either case, the 8(:ect Na igator %ill appear)

9.+ Oracle Forms O1:ect &avigator


@fter starting up 8racle 9orms, the main screen %ill (e presented)

/his screen is called the Object Navigator and displays all of the form elements, data (locks, menu items, user defined code li(raries, (uilt in procedures and functions, and data(ase o(:ects !ta(les, ie%s") /he display is in the form of a collapsi(le tree) In general, clicking on a ; %ill eBpand the current item to sho% its details) Clicking on a < %ill collapse the current list details) /he menu (ar across the top pro ides access to almost all of the features of 8racle 9orms)

/he %i"e menu has options to create, open, sa e and print forms) /his menu also includes an option to connect to the data(ase and the @dministration option that is used to compile forms and menu code) /he last option on the %i"e menu is the EFi6 option that %ill eBit 8racle 9orms Builder) /he E4i6 menu has options to cut, copy and paste o(:ects, to in oke an editor and to undo an operation) /he VieG menu toggles the o(:ect na igator display (et%een isual elements and o%nership elements)

/he N5EiC56or menu has items that control the display of the o(:ect na igator including eBpanding and collapsing tree (ranches) /he N5EiC56or menu can also (e used to create and delete o(:ects using the Cre56e and De"e6e menu options respecti ely) /he ProCr5! menu has items that control form compilation, generation and eBecution !#un") /riggers, ,rocedures and other ,<3SA< code can also (e created from this menu) /he +!5r6 TriCCers menu option displays the most commonly used triggers according to the type of o(:ect currently selected in the o(:ect na igator) /he Too"s menu has options to s%itch (et%een se eral different screens including the <ayout editor, Menu editor and 8(:ect Na igator) /here are also se eral %i&ards that can (e launched from this menu including the Data Block %i&ard, the <ayout %i&ard, the Chart %i&ard and the <8F !<ist of Falues" %i&ard) /he ?in4oGs menu displays menu items for each of the %indo%s you ha e open) By default, only one item E the 8(:ect Na igator E is displayed) 9inally, the &e"p menu can (e used to display help topics)

By default, a (utton (ar is pro ided on the left hand side of the 8(:ect Na igator %indo%) =ach (utton duplicates some functionality on the menus) 9or eBample, clicking on the top icon !an opened folder" is the same as pulling do%n the %i"e menu and choosing the Open option) /o see %hat a (utton might do if pressed, place the mouse cursor o er the (utton and a short message %ill appear descri(ing the (uttonIs function) In De eloper ;)5, a form, report or graphic is generally referred to as a Module) 0hen first starting the 9orms Builder, a default module is created calledC MOD,LE1 /he content of the 8(:ect Na igator is (roken do%n into ; ma:or sectionsC
1. %or!s E Contains form o(:ects and all of their su(Eo(:ects such as data (locks, triggers,

alerts, can ases, program units !procedures and functions", parameters and %indo%s) More than one form can (e open at a time) 2. Menus E Contains menu o(:ects and all of their su(Eo(:ects such as menu items, parameters and program units) More than one menu can (e open at a time)
3. PLH+>L Li7r5ries E /hese are li(raries of ,<3SA< code !stored either in the data(ase or

in .p"7 files") <i(raries can (e shared among different forms and among different de elopers)
4. O7IeA6 Li7r5ries E /hese are li(raries containing a collection of o(:ects !anything that

can appear on a form")


5.
ui"6:in P5A05Ces E <ists all of the packages !,<3SA< procedures" a aila(le (y default to all forms, reports, etc)

6. D56575se O7IeA6s E <ists all of the data(ase o(:ects !/a(les, Fie%s, ,<3SA< <i(raries,

and Stored ,rogram Units" in the userIs 8racle data(ase schema)

@s o(:ects are created, they are displayed under the appropriate section) ConteBt sensiti e menus can (e displayed for each o(:ect (y clicking on an o(:ect %ith the right mouse (utton)

9.' Connecting to the Data1ase


/he first step in %orking %ith any of the De eloper tools is to esta(lish a connection to an 8racle data(ase) /his is accomplished (y pulling do%n the %i"e menu and selecting the ConneA6 menu item) 9ill in your 8racle Username and 8racle ,ass%ord !press the ta( key to mo e (et%een the fields") 9or the D56575se field, type in the ser ice name for your 8racle data(ase) 9or eBample, if you are using ,ersonal 8racle <ite, the D56575se: %ould (e OD C:POL*TE) If you ha e a local data(ase running on the same machine, you may (e a(le to connect directly to it (y lea ing this field (lank) If you are %orking in a client3ser er en ironment %here the 8ralce ser er resides on another machine, you %ill ha e to configure the 8racle Net4 middle%are to esta(lish a connection %ith that ser er) You %ould then supply the Net4 ser ice name in the Data(ase field) @lternati ely, contact your system administrator to learn the ser ice name for your 8racle data(ase and pro ide that information in the D56575se: field)

Click on the ConneA6 (utton to complete the connection !Under some ersions of UNI6, the (utton is la(eled O2") If the user name or pass%ord is mistyped or incorrect, the dialog (oB %ill (e reEdisplayed) Be sure to pro ide your 8racle username and pass%ord !not your UNI6 host or <ocal @rea Net%ork pass%ord") =ach time any of the De eloper Builder tools are eBecuted, the first step %ill (e to connect to an 8racle data(ase in this fashion)

#. Forms Design
@ typical data(ase schema contains do&ens of ta(les, each %ith se eral columns of arious data types) 0e de elop applications !forms, reports, menus, etc)" to make the :o( of manipulating data in those ta(les easier for users) In 8racle 9orms, a form !or data entry form" acts like a %indo% into the data(ase schema) @n indi idual focuses the attention of the user to one or a fe%

of the ta(les at a time) In addition, a form can gi e prompts so the user kno%s %hat kind of input is eBpected and ho% data is to (e entered and manipulated) By default, e ery form in 8racle 9orms has the capa(ility to -uery eBisting data in a ta(le, modify eBisting data and add ne% data !records" to the ta(le) @ form is (uilt up using one or more data blocks that correspond to ta(les in the data(ase) 9ields %ithin the data (lock correspond to columns in the data(ase ta(le) @ data (lock is similar to a Data0indo% o(:ect in ,o%erBuilder) In the follo%ing figure, a typical form is sho%n)

/his form has t%o data (locks, one for the EMPLOYEE ta(le, and one for the DEPENDENT ta(le) /hese data (locks are arranged in a Master/Detail setup %here a single =mployee record !the master" is associated %ith one or more Dependents records !the details") By default, forms also gi es a (utton (ar and a menu) /hese can (e used to scroll through the records in a (lock, na igate (et%een (locks, set up and perform -ueries against the ta(les, insert, update and delete records, clear the form and eBit the form) 9inally, at the (ottom of each form is a status (ar that displays any rele ant prompts or error messages and an indication of the records in the current data (lock) /here are four main types of forms that can (e designed)

Single Block 9orm) /his form contains a single data (lock corresponding to a single data(ase ta(le)

Master3Detail 9orm) /his form contains t%o data (locks that are arranged in a master3detail !one to many" relationship)

Single (lock 9orm %ith lookup field) /his form contains a single data (lock corresponding to a single data(ase ta(le %ith the addition of one or more fields that display data from some other ta(les) Such data is Klooked upK %hen the form runs) Master3Detail 9orm %ith lookup fields) /his form is similar to the Master3Detail (ut has the additional lookup fields in the master and3or detail (locks)

/here are additional ariations such as a Master3Detail3Detail form %ith . (locks and so on) Ho%e er, the four types illustrated a(o e are the most common ones) In this tutorial, all four types %ill (e demonstrated)

6. Creating and Running a Form !ith a 6ingle =loc*


In this section, the (asic steps for creating a (asic data entry and -uery form for a single data(ase ta(le %ill (e co ered) In general, a Data Block on a form corresponds to a ta(le in the data(ase) /his is called the Base Table for the data (lock) 9or each ta(le displayed on the form, a ne% data (lock %ill (e created) 9or this eBample, only one data (lock %ill (e created for the EMPLOYEE ta(le) @ (lock appears on a Canvas %hich is contained in a indo!) /here are many options to control multiple can as ie%s and multiple %indo%s per form) In these eBamples, %e concentrate on a simple arrangement using a single can as and a single %indo%) /here are a num(er of %ays to create a data (lock) 8ne %ay is to manually define the (ase ta(le and columns, and their positions on the form) 0hile this is possi(le, it can (e ery tedious) 8racle 9orms ;)5 pro ides t%o %i&ards !programs that guide the de eloper in performing common tasks" to create data (locksC

*) /he Data Block !i"ard guides the de eloper through the steps of choosing a (ase ta(le and columns) +) /he #ayout !i"ard guides the de eloper through arranging the (ase ta(le and columns on the form)

6.+ Creating a &e! =loc*


/o create a ne% (lock, pull do%n the Too"s menu and select the D565 item) /he follo%ing dialog (oB %ill appearC
"oA0 GiJ5r4

menu

Click on the NeBt (utton) /he follo%ing dialog (oB %ill appearC

/here are t%o types of data (locks that can (e created) /a(le3Fie% and ,rocedures) 9or this eBample, choose /a(le3Fie% and click on the NeBt (utton) /he neBt step is to choose a (ase ta(le and columns that %ill (elong to the data (lock) /he follo%ing dialog (oB should appearC

/o associate a data(ase ta(le %ith the (lock, click on the roGse... (utton to the right of the /a(le or Fie% field) /he follo%ing dialog (oB %ill pop up)

Make sure the Curren6 ,ser and T57"es (uttons are selected @ list of your ta(les %ill appear) Highlight the name of the data(ase ta(le !=M,<8Y== in this eBample" and click on the O2 (utton)

/he %i&ard should reappear %ith the name of the ta(le and a list of a aila(le columns displayed) /o include a column in the data (lock, highlight the column name and click on the right arro%) /he name of the column should mo e o er to the right hand side) 9or this eBample, select the 9N@M=, <N@M=, SSN, BD@/=, S@<@#Y and DN8 as in the follo%ing figureC

Click on the NeBt (utton, and the final dialog (oB for the Data Block %i&ard %ill appearC

In this eBample, %e %ant to continue on to the <ayout %i&ard in order to specify ho% the ne% form %ill appear) Make sure the Cre56e 6he 7"oA0) 6hen A5"" 6he L5#ou6 GiJ5r4 option is selected and click on the 9inish (utton) /he data (lock %ill (e created !as can (e seen in the 8(:ect Na igator in the (ackground") /he o(:ects created include the =M,<8Y== data (lock containing items for each of the columns that %ere selected in the third step of the %i&ard) 8nce the ne% data (lock and items are created, the first dialog (oB in the <ayout %i&ard %ill appearC

Click on the NeBt (utton and the follo%ing dialog (oB %ill appearC

/he layout for a data (lock may (e placed on any eBisting can as) In this case, there are no can ases so the only option a aila(le is to create a ne% can as) Click on the NeBt (utton to display the follo%ing dialog (oBC

In this dialog (oB, the columns from a gi en (ase ta(le on a data (lock can (e added to the layout) Since %e are laying out the =M,<8Y== data (lock, it is highlighted automatically) Mo e all of the @ aila(le Columns o er to the Displayed Items side (y clicking on the dou(le right arro% and click on the NeBt (utton) In this dialog (oB, the field la(els, field si&es and field heights can (e altered) Change the field la(els as (elo% and click on the NeBt (uttonC

/he follo%ing dialog (oB %ill appearC

/here are t%o main styles for forms) @ /a(ular layout arranges the field la(els across the top of the form %ith a num(er of records (elo% as in a spreadsheet) @ Form layout places the field la(els to the left of the fields) >enerally only one record is displayed at a time) 9or this eBample, choose a 9orm layout and click on the NeBt (utton) In the follo%ing dialog (oB, type a title for the frame !around the data (lock" and check the option to include a scroll (ar) /he num(er of records displayed for a Form layout should (e *) /he num(er of records displayed in a Tabular layout can (e more than *)

Click on the NeBt (utton and the final dialog (oB for the <ayout %i&ard %ill appear)

Click on the 9inish (utton to create the layout) @ ne% Can as %ill (e created @t this point the <ayout =ditor should appear and the ne% form %ith the data (lock %ill appear)

6.' The 3a2out /ditor


/o ie% the actual form and its (locks and fields, pull do%n the Too"s menu and select the L5#ou6 E4i6or menu item !if it not already displayed")

In the <ayout =ditor, fields and la(els can (e mo ed around (y clicking and dragging) 8ther teBt, lines and (oBes, etc) can (e added using the tool palette on the left side of the %indo%) Some common operations on the <ayout =ditor includeC

Mo e a field or a field la(el (y clicking and dragging the item %ith the left mouse (utton) Change the teBt of a la(el (y choosing the teBt tool (utton from the tool (ar and then clicking on a la(el) /o stop editing the la(el, click any%here outside of the la(el teBt) @dd teBt to the (lock (y choosing the teBt tool (utton from the tool (ar and then clicking on a open area) /ype the ne% teBt) /o change the font, highlight the teBt, pull do%n the %or!56 menu and click on the %on6 menu item) /o change the teBt color of a la(el, use the pointer tool to highlight a la(el and then click on the TeF6 Co"or palette (utton to choose the color)

Change the %idth of a field (y clicking on the field) /hen drag one of the handles !small (lack (oBes around the field" to reEsi&e the field)

9or eBampe, on the employee form, you may %ish to make the S=6 field %ider to accomodate the capital letter IMI)

Use the Zoom In tool use the Zoom 8ut tool

to &oom in to the form !e)g), make e erything appear larger") 8r to &oom out of the form)

6.5 Displa2ing -roperties


0hile in the <ayout =ditor, dou(le clicking on an o(:ect %ill (ring up that o(:ectIs $ro$erties) 8ptionally, clicking on an o(:ect %ith the right mouse (utton %ill (ring up a small menu %hich has the ,roperties menu item on it) /he follo%ing figure sho%s the properties for the %NAME item)

=ach type of o(:ect has a slightly different set of properties) 9or eBample, dou(le clicking on the =M,<8Y== data (lock in the 8(:ect Na igator %ill display that data (lockIs properties)

Some properties of interest for a data (lock includeC


(/R/ Clause E specify a 0H=#= clause to filter the selection of ro%s from the (ase ta(le) ORD/R =4 Clause E specify an 8#D=# BY clause to alter the displayed order of the records) Delete Allo!ed, ,nsert Allo!ed, >uer2 Allo!ed and 7pdate Allo!ed E toggle these properties to allo% or pre ent the action) 9or eBample, setting Delete Allo!ed to %AL+E pre ents users from deleting records from the corresponding (ase ta(le using this form) /here are numerous other properties that affect the fonts, colors, si&e and position of o(:ects in the (lock)

6.9 6aving, Compiling and Running Forms


9orms can (e sa ed in files in a directory of your choosing) /he Ksource codeK for a form is stored in a file %ith a .8!7 eBtension) Com$iled forms ha e a .8!F eBtension)

Under MS 0indo%s 123143N/3+555, forms can (e sa ed in a folder !su(directory" on the local hard disk, on a file ser er or on a floppy disk) It is desira(le to maintain separate su(directories !folders" for forms associated %ith different pro:ects) 6.9.+ 6aving a Form /o sa e a form, pull do%n the %i"e menu and select the +5Ee menu item) Under MS 0indo%s 123143N/3+555, this dialog (oB looks likeC

Note that in your company or organi&ation, forms and other files may ha e to (e sa ed on floppy disk or in a special directory) /he a(o e figure is simply an eBample) 9ill in a file name in the %i"e N5!e: field) Be sure it ends %ith .8!7 Click on the +5Ee (utton to sa e the file) 9or this eBample, use the file name e!p"o#ee.8!7 /o sa e this form on a floppy disk in the A: dri e, use the file nameC A:Ke!p"o#ee.8!7 /o enhance porta(ility of forms across different operating systems, use file names that (egin %ith a letter, contain no spaces or punctuation !eBcept for the underscore character", ha e all lo%er case letters and are relati ely short) If you are %orking on a form and %ish to sa e it under a different file name, follo% the same steps as a(o e, only select the +5Ee As menu item in place of the +5Ee menu item) 9or eBample, if you ha e finished %orking on the =mployee form and %ish to sa e off a copy (efore adding some code or programming some program units, the +5Ee As menu item can (e used to sa e off a copy (efore proceeding)

6.9.' Compiling$=uilding a Form Before a form can (e eBecuted !run", it must (e Com$iled and Built) Compiling runs a ,<3SA< compiler on all of the procedures and triggers in the form) Building !or compiling the file" creates the .8!F file that is then used to run the form) /o compile a form, first make sure the form is sa ed) ,ull do%n the ProCr5! menu and select the Co!pi"e menu item) /hen choose A"" in the flyout menu) If a form has errors !e)g), in the ,<3SA< code, or if the data(ase schema changes" they %ill (e displayed in a %indo% as they are encountered) @ record of the compilation process, including error messages, is kept in a file %ith a .err eBtension) 9or eBample, if the form is named e!p"o#ee then the record of the compilation %ill (e stored in e!p"o#ee.err /o Build the .8!F file for a form, pull do%n the %i"e menu, click on the A4!inis6r56ion menu item and then choose Co!pi"e %i"e from the flyEout menu) If the forms generation is successful, the phrase Module built successfully %ill appear on the status (ar at the (ottom of the screen) @lternati ely, 8racle 9orms defaults to automatically (uilding the form each time it is eBecuted !run" from the forms designer as %ill (e demonstrated in the neBt step) 9or more details on the default (eha ior, pull do%n the Too"s menu and check the Pre8erenAes menu item) 6.9.5 Running a Form @fter a form has (een sa ed and (uilt, it can (e eBecuted) /o run the form, pull do%n the ProCr5! menu and select the Run %or! :B C"ien6H+erEer menu item) /he form %ill display in a ne% %indo%) /he 8racle #unform program is eBecuted (y passing in the name of the form !e!p"o#ee.8!F in this case" as a parameter)

Use the arious menus and items to -uery the form, enter ne% data and sa e ne% and changed data) ,lease read the section (elo% on Auery By =Bample to see ho% to -uery data from the underlying ta(les and populate the fields in the form) 6.9.9 Running a Form as a ?ava Application or Applet If you ha e also installed the 9orms Ser er !0indo%s N/3+555 only" you may also run the form in K0e(K mode (y selecting the ,rogram menu and then K0e(K) In 8racle 9orms ; and ;i, the .8!F file is loaded and eBecuted in a ?a a @pplication) In this mode the 9orms ser er handles the processing of the (usiness logic and interacts %ith the user interface elements that run in the ?a a @pplication) @n eBample of a simple =mployee data entry form running in a ?a a @pplication is sho%n (elo%C

@nother option for running 8racle forms is to run them %ithin a %e( (ro%ser as a ?a a @pplet) /he (asic steps for this in ol e setting up a %e( ser er !such as 8racle @pplication Ser er or 8racle 0e(DB" to ser e the .8!F file and a series of ?a a application class files to the %e( (ro%ser client) 8racle pro ides their o%n ?a a runtime en ironment !?#=" called the ?EInitiator that must (e installed on each client) ?EInitiator hooks into the clientIs %e( (ro%ser using a special MIM= data type that launches 8racle ?#= %hen an 8racle form is loaded into the (ro%ser) Belo% is an eBample of the same data entry form running as a ?a a @pplet inside of the Netscape Na igator %e( (ros%er)

9orms ;i pro ides a simple test %e( page located under the 8racle 9orms ;i program group called K#un a 9orm on the 0e(K) 8ne can make use of that to test if the 9orms ser er, load (alancer, and %e( ser er on the middle tier are running correctly) ,lease note that getting 8racle 9orms and #eports to run in this fashion is not a tri ial undertaking) It re-uires eBtensi e kno%ledge of %e( ser ers, 0indo%s N/3+555 ser ices and the %ay in %hich the forms applications are processed across the three tier architecture) /he a(o e discussion is meant as a (asic introduction to the ?a a @pplication and @pplet features of 8racle 9orms) It is (eyond the scope of this tutorial to present the details for configuring ser ers and ser ices to pro ide this capa(ility) ,lease refer to the onEline documentation that comes %ith 98rms ;i for more detailed descriptions and configuration instructions) 6.9.9 >uer2 =2 /@ample 0hen a De eloper 9orm is first eBecuted, no records %ill appear) /hat is, the (lank form %ill appear %ith no data in the fields) /his is similar to running a %ord processor %here the opening

screen is (lank) 9rom this (lank or empty form, the user can immediately (egin to enter ne% data records (y simply typing them in) Ho%e er, in may cases, the user %ould first like to see if there are any records in the data(ase) /o do this, the user must %uery the data(ase using the -uery capa(ilities that are (uilt into e ery 8racle form) /his %ill (ring a copy of the records from the data(ase into the form) 0hen a tool such as SA<G,lus is used, the user must form the SA< -uery (y typing it directly in) In the case of em(edded SA<, the SA< statements are programmed into the host language !such as KCK or ?a a" and automatically eBecuted for the user) In the case of 8racle 9orms, compleB -ueries can (e formulated and su(mitted to the data(ase using a techni-ue called Auery By =Bample or AB=) In AB=, the name of the ta(le or ta(les is fiBed as are the names of the columns that %ill (e returned from the ta(les) /he user can supply their o%n criteria (y supplying alues for the fields) /hese alues (ecome part of the -uery that is su(mitted to the data(ase on (ehalf of the user) Auerying a form in 8racle 9orms is a t%o step process) Clicking on the Auery (utton or choosing En6er >uer# from the >uer# menu places the form in &nter 'uery mode) In enter -uery mode, the form is cleared and the user can na igate in the arious fields) =Bample alues can (e supplied as criteria for the -uery) 9or eBample, a user looking for all employees in the #=S=@#CH department might type a K2K in the DN8 field %hile in enter -uery mode) Clicking on the Auery (utton a second time eBecutes the current -uery using any supplied data as criteria in a 0H=#= clause) If no criteria are supplied, then all records in the ta(le %ill (e displayed) Continuing the a(o e eBample, supplying a K2K for the DN8 field %hile in enter -uery mode %ould cause the follo%ing SA< -uery to (e su(mitted to the data(aseC
+ELECT 8n5!e) "n5!e) ssn) 7456e) s5"5r#) 4no %ROM e!p"o#ee ?&ERE 4no L '/

Most of the commands on the menus and on the (utton (ar can also (e acti ated using special key com(inations or function keys) 9or eBample, under MS 0indo%s 123143N/3+555, pressing the %7 function key places the form in =nter Auery mode) ,ressing the %< function key eBecutes a -uery) /o see a list of keys and their functions, pull do%n the &e"p menu and choose the 2e#s option) 8nce data has (een -ueried, it is retrie ed from the data(ase and stored in a (uffer in the associated data (lock on the form) /his means that a local copy of the data no% eBists in the clientIs memory) @ppropriate locks are placed on the data so that the client maintains a consistent ie% of the data in the associated ta(les) /he user can na igate through the data in a (lock (y pressing the up and do%n arro% keys to scroll (et%een records) /o change data in a form, the user can /@B to the field of interest, and type o er the eBisting data)

/o enter ne% data into the form, the user can scroll to the last record and then do%n once more to mo e to a (lank record) Data can then (e typed into the fields and the /@B key can (e pressed to mo e (et%een fields on the form) /o sa e (oth changed and ne% records on a form, pull do%n the AA6ion menu and choose the +5Ee menu item) @ny records that ha e (een changed are collected and su(mitted to the data(ase as SA< U,D@/= statements) @ny ne% records are collected and su(mitted to the data(ase as INS=#/ statements) /hese statements are su(mitted as a single logical unit of %ork) /hus if a failure occurs during any of the statements, the entire transaction %ill (e rolled (ack) If the user attempts to clear the (lock or eBit the form and there are some changes that ha e not yet (een applied to the data(ase, they %ill (e prompted to commit the changes (efore eBiting or clearing the form) /he (lock is cleared %hen the =nter Auery mode is in oked) @ (lock can also (e cleared using the C"e5r "oA0 and C"e5r %or! menu items) /o eBit from a running form, pull do%n the AA6ion menu and select the EFi6 menu item) @s a re ie%, here are a fe% (asic functions that can (e performed (y default in any 9ormC Forms function Auerying a form &otes /o see all records in the ta(le, simply K=Becute AueryK ! ia Auery menu or (y pressing 94 in 0indo%s") /o filter the record, Kenter -ueryK mode, specify the -uery parameters in the fields and then K=Becute AueryK)

Scroll to the last record and then scroll once more to get a (lank record) /ype in data for each field and then commit these changes (y pulling do%n the AA6ion Inserting ne% menu and choose the +5Ee menu item) records 9or master3detail forms !discussed (elo%" first either -uery a master record or insert and sa e a master record !in the master data (lock", then na igate to the detail (lock and insert ne% records there) Updating eBisting records Auery the data(ase and scroll to the record of interest) Change the alues in the fields and then sa e the changes) 9or master3detail forms, changes to the key in the master (lock may (e pre ented if detail records eBist !thus insuring relational integrity") Auery the data(ase and scroll to the record of interest) ,ull do%n the #ecords menu and choose Delete record) /hen sa e the changes) 9or master3detail forms, attempting to delete a master record %hen detail records eBist typically results in an error) In such cases, all of the detail records should (e deleted first and then the master record should (e a(le to (e deleted)

Deleting records

6.# /@erciseA Creating a a 6ingle =loc* Form

9or this eBercise, create a simple data entry form for the D=,@#/M=N/ ta(le %ith the follo%ing characteristicsC

Select and display all of the columns in the D=,@#/M=N/ ta(le) In the layout %i&ard, use the /a(ular layout and display 2 #ecords in the form) @dd a scroll(ar) In the <ayout =ditor, make the DN@M= field a (it %ider to accommodate longer department names) Change the ,roperties of the D=,@#/M=N/ (lock so that that data is 8#D=# BY DNUMB=#) Sa e the form under the file nameC 4ep5r6.8!7

/he resulting form should look like the follo%ingC

Use the enter -uery mode and eBecute -uery functions to -uery the department ta(le for a specific department name and3or num(er)

B. Creating a 0aster<Detail Form


In this section, the (asic steps for creating a Master3Detail form are introduced) @ Master3Detail form is a form that has t%o (locks arranged in a masterEdetail relationship)

B.+ The 0aster<Detail Relationship

/he MasterEDetail relationship is a common relationship (et%een entities in a (usiness) In an =ntityE#elationship diagram, these are sho%n as K8ne to ManyK relationships) In a physical data(ase design, a single Master record references one or more detail records in another ta(le) @ record in the detail ta(le %ill relate to eBactly one master record in the master ta(le) @nother name for this relationship is called parentEchild) =Bamples of this relationship includeC @ Customer 8rder %ith many 8rderItems) @ Department %ith many =mployees)

@n =mployee %ith many Dependents) @ Company %ith many Branch 8ffices) @ #ecipe %ith many #ecipeSteps) @n In entory location %ith many In entory Items)

8racle 9orms implements the masterEdetail relationship using t%o data (locks) /he first (lock corresponds to the master ta(le and the second (lock corresponds to the detail ta(le) /here are t%o ma:or functions in a MasterEDetail formC

8racle 9orms coordinates alues (et%een the t%o (locks through a series of form and (lock le el triggers) 8racle 9orms guarantees that the detail (lock %ill display only records that are associated %ith the current record in the master (lock)

Note that a MasterEDetail form is simply one %ay of ie%ing the data in t%o related ta(les) 9orms do not affect the schema in terms of creating, dropping or enforcing data(ase le el referential integrity constraints)

B.' 6teps to Create a 0aster<Detail Form


In this section, a set of step (y step instructions for creating a MasterEdetail form are gi en) /he form %ill allo% a user to -uery a gi en department in the company and then %ill display all of the employees in that company) /he schema used is the same one suggested in the ,rere-uisites section at the (eginning of this tutorial) Notice that the DN8 column in the EMPLOYEE ta(le gets its alues from the DNUMB=# column in the DEPARTMENT ta(le) In other %ords, to :oin the t%o ta(les in a -uery, one might specify a 0H=#= clause such thatC EMPLOYEE.DNO L DEPARTMENT.DN,M ER)

B.'.+ Create the 0aster =loc* In the 8(:ect Na igator, click on the %or!s (ranch at the ery top) Create a ne% form (y pulling do%n the %i"e menu and choosing the NeG menu item) /hen choose %or! from the flyout menu) Using the same steps gi en in the prior section on Creating a 9orm %ith a Single Block, create a ne% (lock named DEPARTMENT that contains all of the columns in the DEPARTMENT ta(le) BrieflyC
1. ,ull do%n the Too"s menu and choose the Data Block %i&ard)

+) Create a data (lock for a ta(le3 ie%) .) Specify the D=,@#/M=N/ ta(le and select all of the columns !DN@M=, DNUMB=#, M>#SSN and M>#S@#/D@/=") 7) Create the data (lock and then go on to the <ayout %i&ard) 2) @pply the Department data (lock to a ne% can as) ;) @dd all of the columns as Displayed Items) D) Change the la(els toC Dept) Name Dept) Num(er Mgr) Ssn Mgr) Start Date 4) Choose a Form layout) 1) Specify a frame title of KDepartmentsK and select only * record to (e displayed)

10. Sa e the form as 4ep6e!p.8!7 and then compile and run it to make sure it is %orking

properly)
11. Use the AB= features to retrie e only those departments %ith DNUMB=# greater than +)

/hen, do another AB= -uery to retrie e only those departments %ith the letter & in their name !try M&M") @fter this first step, the 4ep6e!p form should look like the follo%ingC

B.'.' Create the Detail =loc* No% that %e ha e the master (lock D=,@#/M=N/ created, %e can no% create the detail (lock =M,<8Y== and associate it %ith the master (lock) ,erform the follo%ing stepsC 1. #eturn to the 8(:ect Na igator !pull do%n the Too"s menu and choose O7IeA6 N5EiC56or") +) In the 8(:ect Na igator, click on the Data Blocks (ranch of the D=,/=M, form !do not click on the department data (lock, ho%e er") .) ,ull do%n the /ools menu and choose the Data Block %i&ard) Note( If the D=,@#/M=N/ data (lock !or any of its items" is still selected, acti ating the Data Block %i&ard %ill cause the eBisting (lock to (e edited instead of creating a ne% (lock !%hich is %hat is re-uired in this part of the tutorial") 7) Select the =M,<8Y== ta(le and include the 9N@M=, <N@M=, SSN, BD@/=, S@<@#Y and DN8 columns)

2) Because at least one data (lock already eBists in the form, the neBt step in the %i&ard %ill (e to create a relationship (et%een the eBisting data (lock !D=,@#/M=N/ in this case" and the ne% (lock (eing created) /he %i&ard can construct the relationship (ased on ta(le le el constraints it learns from the data(ase schema) 9or eBample, in the C#=@/= /@B<= and @</=# /@B<= statements gi en at the start of this tutorial, foreign key constraints %ere specified (et%een D=,@#/M=N/ and =M,<8Y==, and (et%een =M,<8Y== and D=,=ND=N/) Ho%e er, such relationships are not al%ays implemented in ta(le le el constraints) /he de eloper can also specify the relationship manually) In this case, the relationship %ill (e specified manually) DeEselect the Au6o:Ioin 4565 7"oA0s option) Click on the Cre56e Re"56ionship (utton to list the a aila(le data (locks) In the neBt dialog (oB #elation /ype, choose 5se4 on 5 Ioin Aon4i6ion and click the O2 (utton)

0hen the list of (locks appears, choose the D=,@#/M=N/ data (lock)

@rrange the Detail Item !DNO" and Master Item !DN,M ER" such as that the :oin condition (ecomesC EMPLOYEE.DNO L DEPARTMENT.DN,M ER

;) Create the data (lock and then call the <ayout %i&ard) D) Be sure to choose the eBisting can as !C@NF@S+ in this eBample" and include all of the items e)ce$t t*e DNO as displayed) /he DN8 column !item" %ill still (e a part of the =M,<8Y== data (lock, ho%e er, it %ill not (e displayed to the user) 4) /ouch up the la(els for the fields and choose the Tabular layout) 1) >i e the 9rame /itle as K=mployeesK and select 2 #ecords displayed %ith 5 distance (et%een records)
10. Sa e the form !it should already ha e the name 4ep6e!p.8!7" and then compile and run

it) Note that after compilation, any errors encountered %ill (e displayed) /he follo%ing figure sho%s the masterEdetail form runningC

Notice that (y scrolling the master (lock D=,@#/M=N/ to a ne% department num(er !using the up and do%n arro% keys", the employees for that department are automatically -ueried and displayed) /o na igate (et%een the Master and Detail (locks, useC

/o go to the neBt (lockC ,ress CTRL:P5CeDoGn or pull do%n the "oA0 menu and choose
NeF6

/o go to the pre ious (lockC ,ress CTRL:P5Ce,p or pull do%n the "oA0 menu and choose PreEious

B.5 Relation -roperties of a 0aster<Detail Form


/here are a num(er of properties in a masterEdetail form that can (e changed to suit particular (eha ior of the form) In the figure (elo%, the 8(:ect Na igator has se eral ne% o(:ects on it including +elations)

/o ie% the properties for the D=,@#/M=N/$=M,<8Y== relation, open up the D=,@#/M=N/ (lock and then open the #elations (lock (y clicking on the N sym(ols) /hen click on the D=,@#/M=N/$=M,<8Y== relation %ith the right mouse (utton and select ,roperties) /here are se eral interesting properties in the relations property sheetC

&ame E /he name of the #elation) /his is typically made up of the names of the (locks) Relation T2pe E /he type of the relationC ?oin or #ef) @ ?oin relation uses the typical SA< :oin !in the 0here clause" to (ring the t%o ta(les !data (locks" together) /he +ef relation type is used for a(stract data types and o(:ect references) Detail Data =loc* E /he name of the detail data (lock specified %hen the detail data (lock %as created) ?oin Condition E /his is the :oin condition in effect for -ueries to the data(ase) /his %as specified %hen the detail data (lock %as created) Delete Record =ehavior E Used to specify ho% the deletion of a record in the master (lock affects records in the detail (lock) It supports the follo%ing settingsC
o

NonEisolatedC ,re ents the deletion of a master record if associated detail records eBist in the data(ase) IsolatedC Deleting the master record %ill not affect the associated detail records in the data(ase) CascadingC Deletes the master record and automatically deletes any associated detail records)

Coordination < Deferred E Indicates %hen detail records should (e -ueried %hen a master record is -ueried)

YesC 9orm does not -uery the detail records until the user na igates to the detail (lock) NoC Detail records are fetched immediately %hen a user -ueries the master record)

Deferred is sometimes set to Yes in cases %here there are a lot of detail records for each master record) In such cases, a lot of data must (e -ueried and deli ered to the client each time a ne% record is displayed in the master (lock) 0hen Deferred is set to Yes, the user can scroll do%n to the master record of interest and then na igate to the detail (lock !C/#<E,ageDo%n" to -uery the related detail records)

Coordination < Auto<.uer2 E @pplied to deferred -ueries only o YesC the -uery is automatically eBecuted %hen the user na igates to the detail (lock)
o

NoC the -uery must (e eBecuted manually (y the user after they na igate to the detail (lock)

-revent 0asterless operation E Specifies %hether users are allo%ed to -uery or insert records in a detail (lock %hen no master record is in place)
o o

YesC Users may not -uery or insert %hen no master record is in place) NoC Users may -uery or insert %hen no master record is in place)

/hese settings are used to KtuneK the o erall performance of a masterEdetail form) @s mentioned a(o e, in cases %here a large num(er of detail records are associated %ith each master record, it is a good idea to set coordinationEDeferred to Yes to a oid unnecessary transfers of data (et%een the ser er and client) /his %ill also speed up the display of master records as the user can freely scroll through them %ithout a pause to -uery and deli er the detail records)

B.9 -rogram 7nits in a 0aster<Detail Form


0hen a MasterEdetail form is created, three (asic ,rogram -nits !,<3SA< ,rocedures" are created (y default) /hese procedures are used to coordinate the -uery and na igation of the detail records %hen the master record is changed !e)g), %hen the user scrolls to a different master record", updated or deleted) /he procedures can (e seen listed in the 8(:ect Na igatorC

,<3SA< is 8racleIs procedural language eBtensions to SA<) /o ie% the ,<3SA< code for a ,rogram Unit, click on the name of the program unit %ith the right mouse (utton and then choose PLH+>L E4i6or from the popEup menu) /he code for the CH=CJ$,@CJ@>=$9@I<U#= procedure is sho% hereC

/he CH=CJ$,@CJ@>=$9@I<U#= procedure checks to see if a prior form command or SA< statement %as successful or if it failed) Belo% is the ,<3SA< code for the AU=#Y$M@S/=#$D=/@I<S procedure) /he teBt after the :: !t%o minus signs" are comments)
PROCED,RE >uer#1M5s6er1De65i"s$re"1i4 Re"56ion)4e65i" C&AR( *+ o"4!sC C&AR$2(/ :: O"4 Mess5Ce LeEe" +e66inC re"4e8 C&AR$'(/ :: Re"56ion De8erre4 +e66inC E3*N :: :: *ni6i5"iJe LoA5" V5ri57"e$s( :: re"4e8 :L 3e61Re"56ion1Proper6#$re"1i4) DE%ERRED1COORD*NAT*ON(/ o"4!sC :L :+#s6e!.Mess5Ce1LeEe"/ :: :: *8 NOT De8erre4) 3o6o 4e65i" 5n4 eFeAu6e 6he Ouer#. :: *% re"4e8 L 9%AL+E9 T&EN 3o1 "oA0$4e65i"(/ CheA01P5A05Ce1%5i"ure/ :+#s6e!.Mess5Ce1LeEe" :L 9109/ EFeAu6e1>uer#/ :+#s6e!.Mess5Ce1LeEe" :L o"4!sC/ EL+E :: :: Re"56ion is 4e8erre4) !5r0 6he 4e65i" 7"oA0 5s un:Aoor4in56e4 :: +e61 "oA01Proper6#$4e65i") COORD*NAT*ON1+TAT,+) NON1COORD*NATED(/ END *%/ E.CEPT*ON ?&EN %or!1TriCCer1%5i"ure T&EN :+#s6e!.Mess5Ce1LeEe" :L o"4!sC/ RA*+E/ END >uer#1M5s6er1De65i"s/

/he AU=#Y$M@S/=#$D=/@I<S procedure is eBecuted %hene er the user na igates to the detail (lock in a master detail form) If the Deferred Coordination property is set to false, then the detail (lock is automatically -ueried) 9inally, the C<=@#$M@S/=#$D=/@I<S procedure is called each time a ne% master record is retrie ed !e)g), %hen the user scrolls to a different master record" or deleted) In this case, if any of the detail records ha e (een inserted, updated or deleted, the changes must (e sa ed into the data(ase (efore the detail (lock can (e cleared) If there are any outstanding changes to (e sa ed, the user %ill (e prompted to sa e those changes (efore the detail (ock is cleared)

B.# /@tending 0aster<Detail Forms

MasterEDetail forms can (e eBtended to include additional le els of details) 9or eBample, consider a Customer listing %ith detail on 8rders a customer has placed) 9or each 8rder, there are then many Items) @n eBtension to the a(o e eBample %ould (e to include the D=,=ND=N/S of the employees as a details of the =M,<8Y==S (lock) /he steps outlined a(o e can (e repeated allo%ing se eral le els of detail to (e added) =ach additional le el of detail %ill add a ne% (lock that is related to the le el a(o e it)

B.6 /@erciseA Creating a 0aster$Detail Form


9or this eBercise, create a Master3Detail form using the =M,<8Y== and D=,=ND=N/ ta(les) =mployee %ill (e the Master (lock and Dependents %ill (e the Detail (lock) /he :oin condition (et%een the t%o ta(les is %here the SSN column of =M,<8Y== is e-ual to the =SSN column of D=,=ND=N/) /he follo%ing is an outline of the stepsC *) Create the =mployee data (lock and include the 9N@M=, <N@M=, SSN, @DD#=SS and S=6 fields on the form) Use the 9orm layout and only display one record at a time) +) >o (ack to the 8(:ect Na igator and select the KData BlocksK tree) Make sure the =M,<8Y== (lock is not selected and run the Data Block 0i&ard again)
3. Create the Dependents data (lock and include all of the columns)

9or the master3Detail relationship, deEselect the KautoK option, use a ?oin relationship, choose the =M,<8Y== data (lock as the Master and set DEPENDENT.E++N L EMPLOYEE.++N for the :oin relationship) 7) In the <ayout 0i&ard for the Dependents data (lock, display all of the fields e)ce$t t*e &SSN field) /he =SSN field %ill remain part of the data (lock (ut it %ill not (e isi(le on the form) Choose a /a(ular style and display 7 up to records at once %ith 5 space (et%een each record)
5. Sa e the form using the nameC e!p4epn.8!7

/he completed form should look like the follo%ingC

Auery the master (lock and practice na igating (et%een the t%o (locks using the C/#<E ,ageDo%n and C/#<E,ageUp keys) 0hile in the =mployee (lock, scroll to the =mployee named ?=NNI9=# 0@<<@C=, na igate to the Dependents (lock and add a ne% record for a S8N named @ND#=0 (orn on +5E8C/E *1;+) Na igate (ack to the =mployee (lock and attempt to scroll to another employee record) @ prompt should (e displayed to sa e the ne% Dependent record) 0hile in the Master (lock for =mployees, scroll to an employee %ho has some dependents) /ry to delete the =mployee record and see if an error message appears) 9inally, alter the =M,<8Y==$D=,=ND=N/ relation properties and set the CoordinationE Deferred to Yes and then run the form) Notice no% that the detail records %ill not (e displayed automatically) Na igate to the Dependents (lock and hit the =Becute -uery (utton !or pull do%n the >uer# menu and choose EFeAu6e") Notice that only those Dependent records matching the =mployee are displayed)

%. 3ist of Calues D3OCsE and &on<=ase Ta1le Fields


It is cum(ersome for a user to ha e to remem(er arious codes and num(ers %hile entering data into a data entry form) 9or eBample, in the =mployee form, it might (e difficult to ha e all of the department num(ers memori&ed %hen inserting ne% employee data)

8ne solution to this pro(lem is to make a list of appropriate alues a aila(le %hen the user na igates to Department Num(er field !DN8") In 8racle 9orms, these are called <ist of Falues !<8Fs") /he neBt section %ill illustrate creating <8Fs for fields) /hese eBamples are (ased on the single (lock =mployee form created at the (eginning of this tutorial) /o prepare for this part of the tutorial, close any forms you currently ha e open (y pulling do%n the %i"e menu and selecting the C"ose menu item) 8nce all of the forms are closed, pull do%n the %i"e menu and choose the Open menu item to open up the e!p"o#ee.8!7 form that %as created pre iously) @ <ist of Falues is (ased on a +ecord .rou$) In 8racle 9orms, a record group is a -uery that returns some collection of records) #ecord groups can (e used to populate (locks or <8Fs and they can (e used in procedures) 0hen the user na igates to an item %ith an <8F attached to it, the <8F key !91 in MS 0indo%s" can (e pressed to call up the <8F) @t that time, the -uery associated %ith the record group is eBecuted and the results are displayed in a pop up %indo%) 8nce the user makes a selection from the list, the alue or alues are returned to the form and placed in the appropriate fields) In the eBample (elo%, a record group and <8F for the DN8 !department num(er" field in the =mployee ta(le %ill (e created)

%.+ Creating a 3ist of Calues


Creating a <ist of Falues re-uires 7 (asic steps) %.+.+ Create a ne! 3OC O1:ect /o create an <8F, click on the <8Fs node in the 8(:ect Na igator) /hen pull do%n the N5EiC56or menu and choose the Cre56e menu item) @ dialog (oB %ill appear asking if you %ould like to create the <8F manually or if you %ould like to use the <8F 0i&ard)

Choose KUse the <8F 0i&ardK and click the 8J (utton) /he first step of the <8F 0i&ard %ill appear as (elo%C

/he default is set to create a ne% #ecord >roup) Make sure this selection is highlighted and then click the NeBt (utton) In most cases, you %ill not ha e a record group created pre iously) Ho%e er, one can (e created on the fly at this point (y specifying a -uery) In this eBample, enter the <8F -uery as follo%sC
+ELECT DN,M ER %ROM DEPARTMENT

/hen click on the NeBt (utton) /he neBt step is to specify %hich columns in the record group %ill (e returned to for use (y the <8F) In this eBample, %e only return DNUMB=# so select that column as sho%n (elo% and click NeBt)

/he neBt step is to specify the display properties of the <8F columns and also to map the <8F item to the field on the form)

/o map the <8F column to a field, click on the DNUMB=# entry and then click on the K<ook up return ItemK (utton) Highlight the =M,<8Y==)DN8 field and click on the 8J (utton)

Note that if your <8F contains more than one item, at this time you %ould also map them as %ell !this is not the case %ith this eBample, (ut in the neBt eBample %e %ill need to map t%o <8F columns") Click on the NeBt (utton) Specify a title for <8F %indo%) @t this point you may also specify the si&e and positioning of the <8F) 9or this eBample, lea e them as the defaults and click the NeBt (utton)

/he ad anced properties relate to ho% the records should (e fetched for the <8F) If there are many hundreds or thousands of possi(le records returned (y the <8F, you may consider changing these options) 8ther%ise, for this eBample, simply click NeBt)

In this final step, the <8F is returning some columns and they %ere assigned to fields on the form in a pre ious step) @t this point, %e need to associate the <8F %ith a particular item on the form) 9or eBample, (y assigning the <8F to the =M,<8Y==)DN8 field, the user %ill (e a(le to call up the <8F only %hen the cursor is positioned in the =M,<8Y==)DN8 field) Choose =M,<8Y==)DN8 and click the NeBt (utton)

9inally, click 9inish to create the #ecord >roup and the <8F)

In the figure (elo%, the <8F has (een created) @ default name of <8F7 %as gi en to (oth the <8F and to its associated record group) Depending on %hat other parts of this tutorial you ha e completed, the default name may (e slightly different)

Sa e, Compile and #un the form) 0hen entering ne% data, na igate to the DN8 !Department num(er" field) Notice at the (ottom of the form, a message appearsC Lis6 o8 V5"ues indicating a list of alues is a aila(le for this field) Under UNI6, the key to display the list of alues is ControlEl) Under MS 0indo%s 123143N/3+555 the key to display the list of alues is 91) /o see the appropriate keys to press, pull do%n the &e"p menu and choose the 2e#s item)

%.' &on<=ase Ta1le fields


In the pre ious eBample of adding a <ist of Falues, the supplied list of appropriate alues can (e useful in cases %here the alues themsel es are selfEeBplanatory) Ho%e er, in the prior eBample, the department num(ers may not ha e meaning to the user) It %ould (e more helpful to include the name of the department (oth in the popEup list of alues and on the form) Ho%e er, the department name is not part of the =M,<8Y== ta(le or data (lock) /hus %e need a %ay to display this information on the =M,<8Y== data (lock in a non base table field) @dding this item and making it functional %ill take se eral stepsC *) 9irst the ne% item %ill ha e to (e added to the =M,<8Y== data (lock) 0eIll call this ne% item D=,/N@M=) 2. NeBt, the D=,/N@M= field should (e populated %ith the department name each time the alue of the DN8 field changes) @ 6riCCer %ill (e created to handle this functionality) .) 9inally, the list of alues %ill (e changed to include the Department name in the <8F) %.'.+ Adding a &e! ,tem to an /@isting Data =loc*

S%itch to the <ayout =ditor (y clicking on the Too"s menu and selecting the L5#ou6 E4i6or menu item)

Click on the /eBt Item tool and create a ne% field on the =M,<8Y== (lock (y clicking and dragging the mouse neBt to the DN8 item)

Display the properties for the ne% /eBt Item (y dou(le clicking on it) Change its name to D=,/N@M=) Change the follo%ing properties for D=,/N@M=C /na1ledA Yes Fe21oard &aviga1leA No Data1ase ,temA No >uer2 Onl2A No -rimar2 Fe2A No ,nsert Allo!edA No >uer2 Allo!edA No 7pdate Allo!edA No

By setting Jey(oard Na iga(le to No, %e pre ent the user from ta((ing into this field) Since this field is not used for data entry or -uerying, this pre ents the potential confusion)

/he Data(ase Item property is set to No %hich indicates that this filed does not map to an actual column in the =M,<8Y== ta(le) /he remaining properties are all set to No to keep the field from participating in any of these acti itiesC Delete, Insert, Update and Auery)

@t this point, the ne% item D=,/N@M= has (een added to the =M,<8Y== data (lock as a nonE(ase ta(le field) Sa e the form at this point (y pulling do%n the %i"e menu and choosing the +5Ee option) %.'.' Creating a Trigger NeBt, %e %ill create a trigger to populate the D=,/N@M= field %hene er the alue of DN8 changes) /riggers in 8racle 9orms ha e four general formsC PRE: /rigger fires (efore an e ent is eBecuted) PO+T: /rigger fires after an e ent is eBecuted)
?&EN: 2EY:

/rigger fires in place of the eBecution of an e ent)

/rigger fires %hen a particular key is pressed)

In this eBample, %e %ould like to populate the D=,/N@M= field %ith the appropriate department name :ust after the DN8 field changes on the =M,<8Y== (lock) /hus %e %ill use a PO+T:C&AN3E trigger on the :EMPLOYEE.DNO field) S%itch to the 8(:ect Na igator ie% (y clicking on the Too"s menu and choosing the O7IeA6 N5EiC56or menu item) 8pen up the =M,<8Y== data (lock and the DN8 item)

Click on the Triggers property and create a ne% trigger (y pulling do%n the N5EiC56or menu and choosing the Cre56e menu item) @ list of possi(le trigger names appears) Choose the PO+T:C&AN3E trigger and click on the 8J (utton)

0hen the ,<3SA< editor appears, type the follo%ing ,<3SA< codeC
:: Popu"56e 6he non:75se 657"e 8ie"4 :EMPLOYEE.DEPTNAME :: usinC 5 E5"ue 8ro! 6he DEPARTMENT 657"e. E3*N +ELECT DNAME *NTO :EMPLOYEE.DEPTNAME %ROM DEPARTMENT ?&ERE DEPARTMENT.DN,M ER L :EMPLOYEE.DNO/ END/

Items on a (lock are preceded (y a full colon to differentiate them from columns in a ta(le)

Compile the trigger (y clicking on the Compile (utton)

Close the ,<3SA< editor (y clicking on the Close (utton) /hen sa e, compile3(uild and run the form to test the functionality) Notice that %hen the =M,<8Y== (lock is -ueried, the associated department name no% appears in the ne% D=,/N@M= field)

%.'.5 Create a ne! 3ist of Calues 9inally, a ne% list of alues should (e created to display (oth the department num(er and name %hen the user calls up the <8F) 9rom the 8(:ect Na igator, click on the <8Fs for the =M,<8Y== form) ,ull do%n the N5EiC56or menu and choose the Cre56e menu item) Choose the <8F 0i&ard) /ype the follo%ing SA< statement into the >uer2 Te@t fieldC
+ELECT DEPARTMENT.DN,M ER) DEPARTMENT.DNAME %ROM DEPARTMENT

/hen click on the NeBt (utton) Include (oth the DNUMB=# and DN@M= columns from the #ecord >roup in the <8F) Map the DNUMB=# <8F column to the C=M,<8Y==)DN8 teBt item and map the DN@M= <8F column to the C=M,<8Y==)D=,/N@M= teBt item !created in the pre ious section")

>i e a title for your list of alues and return (oth DNUMB=# and DN@M= from the <8F) 9inally, Sa e, Compile and #un the form) Note that displaying the <8F for the DN8 item no% causes (oth the department num(er and the name to appear)

%.5 /@erciseA Creating an 3OC and &on<=ase ta1le field

9or this eBercise, create a ne%, single data (lock form (ased on all of the columns in the D=,@#/M=N/ ta(le) /hen add a nonE(ase ta(le field for the last name of the department manager and create an <8F to populate itC Create a ne% form called 4ep5r6!C.8!7 that includes all of the columns in the D=,@#/M=N/ ta(le) In the layout %i&ard, use the /a(ular layout and display 2 #ecords in the form) @dd a scroll(ar) In the <ayout =ditor, create a ne% teBt item called M>#$<@S/$N@M= in the D=,@#/M=N/ data (lock) Be sure the D=,@#/M=N/ (lock is selected %hen the ne% item is created) Change the properties of M>#$<@S/$N@M= so it is not a Data(ase item)

Create a list of alues called <8F$M># (ased upon the -ueryC


+ELECT ssn) "n5!e %ROM e!p"o#ee

@ssign <8F$M># to the M>#SSN item)


Create a ,8S/ECH@N>= trigger on the M>#SSN item so that %hen it changes, the follo%ing code %ill eBecuteC
+ELECT *NTO %ROM ?&ERE "n5!e :DEPARTMENT.M3R1LA+T1NAME e!p"o#ee e!p"o#ee.ssn L :DEPARTMENT.M3R++N/

/his %ill automatically populate the non (ase ta(le field M>#$<@S/$N@M= on the form %hen the form is -ueried) /he form should look like the follo%ingC

". Oracle Forms -rogram 7nits and 6tored -rogram 7nits


8racle 9orms pro ides a mechanism to store procedures !called ,rogram Units" %ritten in the ,<3SA< language %ithin a form) ,rogram Units can (e used to add functionality that is not possi(le through Structured Auery <anguage !SA<" or through the 8racle 9orms interface) Some eBamples of ,rogram Units %ere gi en in the discussion on ,rogram Units in a MasterEDetail 9orm) By storing a ,rogram Unit %ithin a form, many (locks in the form can take ad antage of the same procedure %hich reduces code duplication and impro es the maintaina(ility of the code) ,rocedures %ritten in ,<3SA< may also (e stored %ithin the 8racle Data(ase itself as an o(:ect in the schema) Such Stored ,rogram Units !also called Stored ,rocedures" are ideal for situations %here highly standardi&ed (usiness rules or applications logic must (e implemented across many forms or applications) In addition, procedures that re-uire se eral -ueries (e made to the data(ase may (e (est implemented in the data(ase as this reduces the net%ork traffic and can significantly impro e performance) @ user may create stored procedures %ith the 8racle SA<G,lus command line tool) 8racle 9orms can make calls to (oth internal ,rogram Units as %ell as to Stored ,rogram Units) /his fleBi(ility allo%s application designers eBtensi e control o er the eBecution of applications and facilitates performance tuning) In the follo%ing sections, eBamples of 8racle 9orms ,rogram Units and Stored ,rogram Units %ill (e gi en)

".+ Creating -rogram 7nits in Oracle Forms


In this section, %e %ill augment the =M,<8Y== form (y adding a count of other mem(ers of a gi en employeeIs department) /o add this functionality, %e %ill add a ne% field item to the =M,<8Y== (lock, %rite a ,rocedure in ,<3SA< to gather the data and then %rite a /rigger that %ill call the ,rocedure each time a ne% =mployee record is -ueried) ".+.+ Add a ne! item to the /0-3O4// =loc* @dd a ne% item on the =M,<8Y== (lock to store the count of other employees in the department) See the section on @dding a Ne% Item to an =Bisting Block for details) Call this field OT(/RG0/0=/R6) Be sure it is a nonEdata(ase field and that a user %ill not (e a(le to na igate there, insert, update or delete data in the field) >o to the ,roperties and check each of themC /na1ledA /rue &aviga1leA No Data1ase ,temA No >uer2 Onl2A No -rimar2 Fe2A No ,nsert Allo!edA No >uer2 Allo!edA No 7pdate Allo!edA No

@dd a la(el to this field (y s%itching to the <ayout =ditor, choosing the teBt tool and clicking neBt to the 8/H=#$M=MB=#S field)

".+.' Create a -rocedure to Count Other Department 0em1ers In this step, create a ,rogram Unit !procedure" in 8racle 9orms to count the num(er of other mem(ers in the same department) 9or this procedure, %e %ill pass in a parameter called IN$=M,<8Y==$SSN that %ill contain an employeeIs social security num(er) /he procedure %ill return a alue in the parameter 8U/$C8UN/$8/H=#$M=MB=#S that %ill contain the num(er of other employees %ho are in the same department) /o create this procedure, s%itch to the 8(:ect Na igator and scroll do%n to the -rogram 7nits (ranch) ,ull do%n the N5EiC56or menu and choose the Cre56e menu item) @ dialog (oB %ill appear asking you to name the ne% procedure) /ype in the name OT&ER1DEPARTMENT1MEM ER+ and click on the 8J (utton) @t this point, the ,<3SA< editor %ill appear) /ype in the follo%ing procedure (ody) @n eBplanation of each part of the procedure is gi en after%ardsC
:: 3iEen 5n E!p"o#ee9s ++N) re6urn 6he nu!7er o8 o6her e!p"o#ees :: in 6he s5!e 4ep5r6!en6. PROCED,RE OT&ER1DEPARTMENT1MEM ER+ $*N1EMPLOYEE1++N *N N,M ER) O,T1CO,NT1OT&ER1MEM ER+ O,T N,M ER( *+ TEMP1CO,NT N,M ER/ E3*N TEMP1CO,NT :L 0/ :: P"5Aeho"4er 8or Aoun6 :: *ni6i5"iJe 6o 0

:: Tr# 5n4 8i"" TEMP1CO,NT Gi6h 6he Aoun6 o8 o6her :: E!p"o#ees in 6he 4ep5r6!en6 +ELECT CO,NT$P( *NTO TEMP1CO,NT %ROM EMPLOYEE ?&ERE EMPLOYEE.DNO L $+ELECT EMPLOYEE.DNO %ROM EMPLOYEE ?&ERE EMPLOYEE.++N L *N1EMPLOYEE1++N(/ :: +ee i8 Ge Co6 5 !e5ninC8u" resu"6 *% $NVL$TEMP1CO,NT) 0( QB 0( T&EN O,T1CO,NT1OT&ER1MEM ER+ :L $TEMP1CO,NT : 1 (/ EL+E O,T1CO,NT1OT&ER1MEM ER+ :L 0/ END *%/ END/

/he procedure is %ritten in three main sections) @ny lines starting %ith :: are comments and are ignored (y 8racle forms) /he heading for the procedure definition indicates that one parameter, IN$=M,<8Y==$SSN, is a NUMB=# data type and the procedure should eBpect a alue to (e passed in) /he other parameter, 8U/$C8UN/$8/H=#$M=MB=#S, is also a NUMB=# data type and a alue %ill (e passed (ack to the calling program through it) /o finish off the procedure header, the /=M,$C8UN/ aria(le is declared for use %ithin this procedure only) /he B=>IN statement starts the (ody of the procedure) /=M,$C8UN/ is initiali&ed to 5 and then a -uery is performed on the data(ase to find the total num(er of employees in the same department as the employee %hose SSN %as supplied to the procedure) /he result in /=M,$C8UN/ is checked to see if it is a NU<< alue) If /=M,$C8UN/ is not NU<< and it is not 5, then 8U/$C8UN/$8/H=#$M=MB=#S is set to e-ual /=M,$C8UN/E *) 8ther%ise 8U/$C8UN/$8/H=#$M=MB=#S is set to 5) /he last =ND statement ends the (ody of the procedure) Be sure to check to see that the procedure compiles (y clicking on the Co!pi"e (utton) @ny errors in the procedure %ill (e highlighted) Some common pro(lems include forgetting to use :L in an assignment statement !like the ,ascal language" and lea ing off the END *% to finish up *% ... T&EN statements) 0hen done, click on the C"ose (utton to close the ,<3SA< editor) ".+.5 Create a Trigger to Call the -rocedure

Create a trigger to call the 8/H=#$D=,@#/M=N/$M=MB=#S procedure) In the 8(:ect Na igator, open up the =M,<8Y== (lock and the SSN item) Highlight the Trigger (ranch for the SSN item, pull do%n the N5EiC56or menu and choose the Cre56e menu item) @ pop up list of trigger names %ill appear) Choose ,8S/ECH@N>= and click on the 8J (utton to open the ,<3SA< editor for this ne% trigger) /ype in the follo%ing code for the ,8S/E CH@N>= trigger on the SSN itemC
DECLARE re6urn1Aoun6 N,M ER/ E3*N :: C5"" 6he %or!s ProAe4ure 6o Ce6 6he :: Aoun6 o8 o6hers in 6he 4ep5r6!en6. OT&ER1DEPARTMENT1MEM ER+$:EMPLOYEE.++N) re6urn1Aoun6(/ :: AssiCn 6he re6urn Aoun6 6o 6he 8ie"4 on :: 6he EMPLOYEE 7"oA0. :EMPLOYEE.OT&ER1MEM ER+ :L re6urn1Aoun6/ END/

@gain, click on the Co!pi"e (utton to (e sure the trigger compiles correctly and then click on the C"ose (utton to return to the 8(:ect Na igator) ".+.9 6ave, Compile$=uild and Run the Form /o this point, %e ha e added a ne% nonE(ase ta(le field to the =M,<8Y== (lock, %ritten a procedure !,rogram Unit" to count other employees in the same department and added a trigger to call the procedure each time a ne% employee record is -ueried) /o sa e you %ork, use the +5Ee As menu item on the %i"e menu and sa e this form under the nameC e!p1!e!7.8!7 Sa e, Compile3Build, and #un the form to check its functionality) Note that %hen scrolling to a ne% employeeIs record, the 8/H=#$M=MB=#S field is automatically populated %ith alues indicating the num(er of other employees in the same department)

".' Creating 6tored -rocedures in 6>3H-lus


In the pre ious eBample, %e added a procedure !,rogram Unit" in 8racle 9orms to perform a -uery on the data(ase) /he procedure is stored as part of the formIs source code and is compiled %hen the form is (uilt) Upon eBamination, each call of this procedure producesC *) @ local call from the ,8S/ECH@N>= trigger to the procedure passing an employeeIs SSN) +) @ remote access from the procedure to the data(ase passing a SA< -uery) .) @ remote return from the data(ase containing a count) 7) @ small amount of processing in the procedure !I9 ))) /H=N") 2) @ local return from the procedure to the trigger) In this eBchange, the highest costs are incurred (y the net%ork traffic re-uired to go (ack and forth (et%een client and ser er !steps + and .") /he lo%est costs are incurred (y the local calls (et%een trigger and procedure and the local processing !steps *, 7 and 2") In this eBample, the SA< Auery in steps + and . does not return a significant amount of data) Ho%e er, there are situations %here, if a large amount of data %ere to (e returned for each -uery, such -ueries %ould se erely impact performance) 8ne solution to this pro(lem is to mo e the -ueries and as much processing as possi(le KcloserK to the data in the data(ase) /hus our eBample for this section %ill (e to implement the 8/H=#$D=,@#/M=N/$M=MB=#S procedure in the 8racle data(ase) /o achie e this, %e %ill need to use 8racle SA<G,lus !a commandEline tool" to create a stored procedure) <og in to SA<G,lus and enter the follo%ing C#=@/= ,#8C=DU#= statement) @lternati ely, sa e this statement in a teBt file and eBecute it using the +TART command in SA<G,lus)

CREATE PROCED,RE OT&ER1DEPARTMENT1MEM ER+ $*N1EMPLOYEE1++N *N N,M ER) O,T1CO,NT1OT&ER1MEM ER+ O,T N,M ER( A+ :: 3iEen 5n E!p"o#ee9s ++N) re6urn 6he nu!7er o8 o6her e!p"o#ees :: in 6he s5!e 4ep5r6!en6. TEMP1CO,NT N,M ER/ E3*N TEMP1CO,NT :L 0/ :: P"5Aeho"4er 8or Aoun6 :: *ni6i5"iJe 6o 0

:: Tr# 5n4 8i"" TEMP1CO,NT Gi6h 6he Aoun6 o8 o6her :: E!p"o#ees in 6he 4ep5r6!en6 +ELECT CO,NT$P( *NTO TEMP1CO,NT %ROM EMPLOYEE ?&ERE EMPLOYEE.DNO L $+ELECT EMPLOYEE.DNO %ROM EMPLOYEE ?&ERE EMPLOYEE.++N L *N1EMPLOYEE1++N(/ :: +ee i8 Ge Co6 5 !e5ninC8u" resu"6 *% $NVL$TEMP1CO,NT) 0( QB 0( T&EN O,T1CO,NT1OT&ER1MEM ER+ :L $TEMP1CO,NT : 1 (/ EL+E O,T1CO,NT1OT&ER1MEM ER+ :L 0/ END *%/ END/

@fter typing in this statement, (e sure to R,N the command in the SA<G,lus (uffer (y typing R,N or (y typing the for%ard slash H NoteC 0hile creating a stored procedure, you may recei e an error similar to the follo%ingC
ORA:010-1: insu88iAien6 priEi"eCes

/his indicates the DB@ has not granted you the authori&ation to create stored procedures) ,lease contact your DB@ to o(tain this authori&ation) /o see if the procedure compiled correctly, look in ie% US=#$=##8#S as follo%sC
+>LB +ELECT P %ROM user1errors/

If

no roGs se"eA6e4 the message no roGs se"eA6e4

appears, then no errors %ere found in the trigger)

@nother alternati e is to use the SA<G,lus command called shoG errors) @fter su(mitting a trigger or a stored procedure, any errors found during compilation can (e displayed using the shoG errors command) In some ersions of SA<G,lus, the shoG errors command %ill not %ork due to a lack of (uffer memory on the client computer) @n error message may appear as in the follo%ing eBampleC

+>LB CREATE PROCED,RE 6es6 A+ 2 E3*N +ELECT +Y+DATE *NTO :6e!p %ROM 4u5"/ 4 END/ ' H ?5rninC: ProAe4ure Are56e4 Gi6h Ao!pi"56ion errors. +>LB shoG errors 7u88er oEer8"oG. ,se +ET Ao!!5n4 6o re4uAe ARRAY+*@E or inAre5se MA.DATA. No errors.

If the 7u88er oEer8"oG message appears, set the @##@YSIZ= aria(le to a lo%er num(er such as + %ith the follo%ing commandC
+>LB +ET ARRAY+*@E 2

/hen use the shoG errors command as descri(edC


+>LB shoG errors Errors 8or PROCED,RE TE+T: L*NEHCOL ERROR :::::::: :::::::::::::::::::::::::::::::::::::::::::: -H2PL+:0004;: 754 7in4 E5ri57"e 9TEMP9

/o see %hat stored procedures you ha e created, -uery the US=#$S8U#C= ie% in the data dictionary) /he only ma:or difference (et%een the stored procedure created in the data(ase schema through SA<G,lus and the procedure created in 8racle 9orms is the %ay the header is formatted) Creating a stored procedure uses the follo%ing syntaBC
CREATE PROCEDURE OT&ER1DEPARTMENT1MEM ER+ $*N1EMPLOYEE1++N *N N,M ER) O,T1CO,NT1OT&ER1MEM ER+ O,T N,M ER(

AS

Contrast this %ith the procedure done in 8racle 9ormsC

PROCEDURE OT&ER1DEPARTMENT1MEM ER+ $*N1EMPLOYEE1++N *N N,M ER) O,T1CO,NT1OT&ER1MEM ER+ O,T N,M ER( IS

8nce the 8/H=#$D=,@#/M=N/$M=MB=#S procedure !,rogram Unit" has (een created in SA<G,lus, it is stored as an o(:ect in your schema and %ill remain there until a DROP PROCED,RE

statement is issued) @ny 8racle 9orm, #eport or other procedure can make calls to 8/H=#$D=,@#/M=N/$M=MB=#S as if it %ere a local procedure)
OT&ER1DEPARTMENT1MEM ER+

/o see the stored procedure in action, open the e!p1!e!7.8!7 form and remo e !delete" the ,rogram Unit !procedure" 8/H=#$D=,@#/M=N/$M=MB=#S from it) Sa e the form, compile, generate and run it) /he ,8S/ECH@N>= trigger on C=M,<8Y==)SSN %ill automatically make a call to the stored procedure ersion of 8/H=#$D=,@#/M=N/$M=MB=#S located in the schema) /o ie% the a aila(le Stored ,rogram Units from %ithin 8racle 9orms, s%itch to the 8(:ect Na igator and open up the Data1ase O1:ects tree) 9rom there, a list of schemas !users" %ill appear) Scroll do%n to your username and open it up) /hen open up the Stored ,rogram Units tree) @ list of your stored procedure should then appear)

".5 Additional 6tored -rocedures and Triggers


/here are countless %ays in %hich stored procedures and triggers can (e used to enforce (usiness rules and to process data in an application) In this section, a fe% of the most commonly used triggers and procedures are descri(ed)

".5.+ Generating uni.ue or consecutive identifiers using the ta1le


Many of the keys used in ta(les are (ased on a num(er se-uence) 9or eBample, in our D=,@#/M=N/ ta(le, the DNUMB=# is an integer that should increase for each ne% department) /o automatically generate a ne% DNUMB=#, create a -uery to capture the largest current DNUMB=# alue and add * to it) /hen assign this ne% alue to the DNUMB=# item in the D=,@#/M=N/ data (lock) @ trigger to do this could (e created at the (lock le el and should eBecute (efore any ne% record is inserted into the data(ase) @ PRE:*N+ERT trigger on the D=,@#/M=N/ data (lock %ould (e used for this eBampleC
E3*N +ELECT MA.$ 4nu!7er ( N 1 *NTO :4ep5r6!en6.4nu!7er %ROM 4ep5r6!en6/ END/

@ ,#=EINS=#/ trigger eBecutes :ust (efore the INS=#/ statement for a ne% record is sent to the data(ase)

".5.' Generating uni.ue or consecutive identifiers using an Oracle 6e.uence


8ne pro(lem %ith the a(o e method is that many users %orking on the same form to insert ne% records %ill run into concurrency pro(lems) 9or each ne% record to (e inserted, a full ta(le scan must (e done to find the largest identifier)

8ne solution to this pro(lem is to use an 8racle Se-uence) @n 8racle Se-uence is a schema o(:ect that keeps track of a simple integer and automatically increments this counter %hen it is accessed) 9or eBample, in our D=,@#/M=N/ ta(le, the DNUMB=# is an integer that should increase for each ne% department) /o automatically generate a ne% DNUMB=#, create an 8racle Se-uence using the SA<G,lus toolC
CREATE +E>,ENCE 4ep5r6!en61seO *NCREMENT Y 1 +TART ?*T& 1 MA.VAL,E ;;;;; NOCYCLE/

/he a(o e 4ep5r6!en61seO se-uence %ill (egin counting from * and increment (y * until it reaches 11111) @fter that, accessing the se-uence %ill produce an error) /his is reasona(le since it is highly unlikely an organi&ation %ill e er ha e more than 11111 departments) /he neBt step is to assign the neBt alue of the se-uence to the DNUMB=# item in the D=,@#/M=N/ data (lock) @ trigger to do this %ould (e created at the (lock le el and should eBecute (efore any ne% record is inserted into the data(ase) @ PRE:*N+ERT trigger on the D=,@#/M=N/ data (lock %ould (e used for this eBampleC
E3*N :: 3e6 6he neF6 E5"ue 8or DN,M ER 8ro! 6he :: 4ep5r6!en61seO seOuenAe. +ELECT 4ep5r6!en61seO.neF6E5" *NTO :4ep5r6!en6.4nu!7er %ROM 4u5"/ END/

/he 4u5" ta(le is a dummy ta(le that contains eBactly one record !ro%") 0e can use it in a S=<=C/)))IN/8 statement to consistently return a single alue) /he neF6E5" accessed in the se-uence %ill return the current se-uence alue and then automatically increment it to the neBt alue) @ ,#=EINS=#/ trigger eBecutes :ust (efore the INS=#/ statement for a ne% record is sent to the data(ase) 8racle Se-uences are not applica(le for masterEdetail forms such as purchase orders %here an item num(er needs to (e assigned in the detail ta(le) 9or eBample, purchase order items are typically num(eredC 1) 2) -...) /he neBt ,8 %ill also num(er the items 1) 2) -) ...) @n 8racle Se-uence is designed to deli er uni-ue identifiers for primary keys and should not (e used for such item num(ers)

".5.5 Chec*ing constraints at the client


In any data(ase system, it is al%ays desira(le to constrain the alues certain columns can take on) It is possi(le to add constraints to the data(ase ta(les themsel es in order to enforce constraints,

ho%e er, the enforcement only takes place %hen a transaction reaches the data(ase) In addition, many constraints on the data that in ol e alues of data from other ta(les may not (e easily implemented as ta(le constraints) Many types of constraints on data can (e checked in the client using triggers) 9or eBample, in our =M,<8Y== data entry form, %e may %ant to enforce a constraint that no employee can act as their o%n super isor) /hus for any record, SSN may not e-ual SU,=#SSN) /o implement such a constraint, create a ?&EN:VAL*DATE:*TEM trigger on the SU,=#SSN item in the =M,<8Y== data (lockC
E3*N *% $:+,PER++N L :++N( T&EN ME++A3E$9E!p"o#ees !5# no6 superEise 6he!se"EesR9(/ RA*+E %ORM1TR*33ER1%A*L,RE/ END *%/ END/

/he 98#M$/#I>>=#$9@I<U#= %ill cause the eBecution of the item alidation to (e halted and the user %ill ha e to change the SU,=#SSN (efore mo ing on to another item)

".5.9 Adding Alerts D-op<up 0essagesE


In the pre ious eBample, the M=SS@>= procedure is used to display the error along the status (ar at the (ottom of the 9orms %indo%) @ (etter approach may (e to force the userIs attention to the pro(lem) /his can (e accomplished (y creating a popEup dialog (oB that forces the user to read the message and click an 8J (utton !or some other (utton") In 8racle 9orms, this is called an @lert) /o set up an @lertC

Use the 8(:ect Na igator to display the @lerts area) ,ull do%n the Na igator menu and choose Create) Click on the default name that is gi en for the ne% alert !something like @<=#/7" and rename itC +,PERV*+OR1ALERT Bring up the ,roperty ,alette for this @lert and fill in the follo%ing propertiesC TitleA Super isor @lert Message 0essageA =mployees may not super ise themsel esL Alert 6t2leA S/8, =utton + 3a1elA 8J <ea e the =utton ' 3a1el and the =utton 5 3a1el (lank Default Alert 1uttonA Button * <ea e all of the other properties %ith their defaults and close the ,roperty palette) Change the a(o e ?&EN:VAL*DATE:*TEM trigger on the SU,=#SSN item in the =M,<8Y== data (lock toC
DECLARE re6urn15"er6 N,M ER/ E3*N

*% $:+,PER++N L :++N( T&EN re6urn15"er6 :L +&O?1ALERT $9+,PERV*+OR1ALERT9(/ RA*+E %ORM1TR*33ER1%A*L,RE/ END *%/ END/

/he SH80$@<=#/ procedure calls up the specified alert and o(tains the return alue !(ased on the (utton the user clicks on" to assign to a local aria(le called re6urn15"er6) Belo% is an eBample of the @lert in actionC

In general, @lerts may pro ide se eral different (uttons for the user to click on) 9or eBample, to confirm eBiting a form, a ,8S/E98#M trigger might in oke an K@re you sure you %ant to =BitK @lert %ith KYesK and KNoK (uttons) 8r, to confirm deleting a record, a ,#=EC8MMI/ trigger might in oke an K@re you sure you %ant ot delete this =mployeeMK @lert %ith KYesK and KNoK (uttons) Based on the return$alert alue, either a commit or roll(ack might (e issued)

".5.# -opulate items !ith default values


/here are many cases %here default alues can (e suggested for certain data items (ased upon alues already supplied in other data items) /he method here is to use a ,8S/EI/=M or 0H=NE F@<ID@/=EI/=M trigger to populate another field, only if the other field is currently (lank) 9or eBample, to populate the SU,=#SSN data item of the =M,<8Y== (lock (ased upon the M>#SSN of the employeeIs department, the follo%ing 0H=NEF@<ID@/=EI/=M trigger code might (e used on the DN8 data itemC

E3*N *% :+,PER++N *+ N,LL T&EN +ELECT 4ep5r6!en6.!Crssn *NTO :e!p"o#ee.superssn %ROM 4ep5r6!en6 ?&ERE 4ep5r6!en6.4nu!7er L :e!p"o#ee.4no/ END *%/ END/

Note that the I9 statement uses :+,PER++N *+ N,LL to check to see if any alue has (een supplied for SU,=#SSN) If nothing %as typed into the SU,=#SSN data item, then its alue is NU<<) If the user types anything at all into the SU,=#SSN data item, then the I9 statement %ill e aluate to false and no alue %ill (e suggested)

".5.6 Attaching functionalit2 to command 1uttons


Command (uttons can (e added on a form to carry out functions such as eBiting a form, committing3sa ing changed records and so on) /he (asic command (utton o(:ect contains properties for the (utton <a(el !the teBt pro ided on the (utton itself") @dditional properties include isual attri(utes including the a(ility to display a (itmap image in place of the (uttonIs normal appearance) 8nce a (utton has (een physically placed on a form, functionality is added (ut %riting a ?&EN: ,TTON:PRE++ED trigger) @s one might eBpect, this trigger eBecutes %hen the user clicks on the (utton) So, for eBample, to create a (utton to eBit the form %hen the user clicks on it the ?&EN: ,TTON:PRE++ED trigger might look likeC
DECLARE re6urn15"er6 N,M ER/ E3*N re6urn15"er6 :L +&O?1ALERT $9E.*T1ALERT9(/ *% $re6urn15"er6 L 5"er617u66in1( T&EN E.*T1%ORM/ END *%/ END/

/he a(o e code assumes there is an @lert called =6I/$@<=#/ %ith t%o (uttonsC KYesK and KNoK) If the user clicks on the first (utton !KYesK" then the =6I/$98#M procedure is called and the form %ill eBit !close") If the user clicks on any other (utton, then the @lert %ill close and the form %ill remain open)

".5.B -assing parameters 1et!een forms


/here are many occasions that re-uire the passing of data from one form to another) 8ne such eBample is %hen %e -uery a certain record on one form and then %ish to call up another form %ith the same record automatically retrie ed) In general, data alues can (e passed (et%een forms using ><8B@< aria(les !treat C><8B@< as a (lock a aila(le in all forms" or (y using ,arameter lists) In the eBample, (elo%, the parameter list features %ill (e used to demonstrate ho% data can (e passed from one form to another)

9or this eBample, %e %il make use of t%o formsC @ (asic =M,<8Y== form %ith all fields and the =M,<8Y==3D=,=ND=N/ master3detail form !created in a pre ious eBercise E the file name should ha e (een e!p4epn.8!7") /he idea is to place to (utton on the =M,<8Y== form that %hen pressed, %ill call the =M,<8Y==3D=,=ND=N/ form and automatically -uery the dependents for the employee (eing ie%ed on the =M,<8Y== form) /he main steps areC

8n the =M,<8Y== form, create a (utton and la(el it KAuery DependentsK) Create a 0H=NEBU//8NE,#=SS=D trigger %ith the follo%ing code !comments are enclosed in the code"C
DECLARE HP DeA"5re p"1i4 5s 6he i4en6i8ier 8or 6he p5r5!e6er "is6 PH p"1i4 P5r5!Lis6/ E3*N HP +ee i8 6h56 p5r5!e6er "is6 5"re54# eFis6s. *8 so) 4es6ro# i6 PH p"1i4 :L 3e61P5r5!e6er1Lis6$96!p45659(/ *% NOT *41Nu""$p"1i4( T&EN Des6ro#1P5r5!e6er1Lis6$ p"1i4 (/ END *%/ HP Cre56e 5 8resh p5r5!e6er "is6 PH p"1i4 :L Cre56e1P5r5!e6er1Lis6$96!p45659(/ HP A44 5 neG p5r5!e6er 6o 6his "is6 A5""e4 EMPLOYEE++N PH HP AssiCn 6his p5r5!e6er 6he Aurren6 E5"ue o8 6he :++N 8ie"4 PH A441P5r5!e6er$p"1i4) 9EMPLOYEE++N9) TE.T1PARAMETER) :++N(/ HP NoG run 5 neG 8or! A5""e4 9e!p4epn9 $!us6 7e in 6he s5!e PH HP 4ireA6or# 5s 6he e!p"o#ee 8or! Ge 5re noG e4i6inC. PH HP P5ss 5"onC 6he i4en6i8ier o8 our p5r5!e6er "is6 $p"1i4( PH Run1Pro4uA6$%ORM+) 9e!p4epn9) +YNC&RONO,+) R,NT*ME) %*LE+Y+TEM) p"1i4) N,LL(/ END/

Compile and sa e this form) No% open up the e!p4epn !=M,<8Y==3D=,=ND=N/" form) Using the 8(:ect Na igator, create a ne% ,@#@M=/=# called =M,<8Y==SSN) /his parameter %ill automatically (e assigned a alue (ased on the parameter list passed to the form (y the a(o e #UN$,#8DUC/ procedure call) Create a ne% trigger called 0H=NEN=0E98#MEINS/@NC=) /his trigger %ill eBecute %hene er the form is first run)
DECLARE HP DeA"5re 5 8or!s 7"oA0 i4en6i8er PH 7"01i4 "oA0/ E3*N

PH

HP O765in 6he 7"oA0 *D o8 6he EMPLOYEE 7"oA0. This is 6he PH HP M5s6er 7"oA0 in 6he e!p4epn !5s6erH4e65i" 8or!. PH 7"01i4 :L %in41 "oA0$9EMPLOYEE9(/ *% NOT *41Nu""$7"01i4( T&EN HP CheA0 6o !50e sure our p5r5!e6er h5s 5 E5"ue. *8 6his 8or! PH HP Gere eFeAu6e4 7# i6se"8) 6hen 6he p5r5!e6er Gi"" 7e nu"". PH HP *8 6his 8or! is A5""e4 8ro! EMPLOYEE 6hen 6he p5r5!e6er Gi"" PH HP 7e p5sse4 5"onC 5n4 5ssiCne4 6o :PARAMETER.e!p"o#eessn PH *% $:PARAMETER.e!p"o#eessn is no6 nu""( T&EN HP +inAe Ge h5Ee 5 p5r5!e6er) use i6 6o 5"6er 6he ?&ERE C"5use PH HP proper6# so 6h56 i6 7eAo!es ?&ERE ssnL:PARAMETER.e!p"o#eessn +ET1 LOC21PROPERTY$7"01i4)DE%A,LT1?&ERE)9ssnL9 SS :PARAMETER.e!p"o#eessn(/ HP N5EiC56e 6o 6he EMPLOYEE 7"oA0 5n4 eFeAu6e 5 Ouer# 5u6o!56iA5""# PH 3O1 LOC2$9EMPLOYEE9(/ E.EC,TE1>,ERY/ END *%/ END *%/ END/

Compile and sa e the e!p4epn form) No% run the =M,<8Y== form, -uery an employee record and click on the KAuery DependentsK (utton) /he e!p4epn form should appear %ith the dependents automaticaly -ueried)

/he a(o e eBamples are :ust a fe% of the great many things one can do %ith 8racle 9orms) /he onEline help that ships %ith 9orms ; contains many eBample forms and eBample pieces of code !see the 9orms ,<3SA< #eference" that go far (eyond the simple techni-ues demonstrated a(o e)

".9 /@erciseA -rocedures and Triggers


/he follo%ing are some suggested eBercises using arious com(inations of triggers and proceduresC Create an 8racle Se-uence !using SA<G,lus" that %ill generate ne% Department num(ers for the D=,@#/M=N/ ta(le) @dd the re-uisite ,#=EINS=#/ trigger code to insert a uni-ue DNUMB=# each time a ne% department record is created) Create an alert that displays a %arning if an employeeIs salary is larger than their super isorIs) In a 0H=NEF@<ID@/=EI/=M trigger, run a -uery to check if the employeeIs salary is greater than their super isorIs and if so, sho% the alert)

,ut in some alidation code that %ill check to make sure if a D=,=ND=N/ is a S8N or D@U>H/=#, then the D=,=ND=/NIs BD@/= must (e less than the =M,<8Y==Is BD@/=) If this is not the case, sho% an alert)

@fter you learn ho% to create #eports !see the neBt section" create a simple D=,@#/M=N/ data entry form %ith a (utton that, %hen pressed, %ill run a report for that department (y passing along the DNUMB=# as a parameter)

+0. Oracle Reports =asics


0e no% turn our attention to another De eloper tool called 8racle #eports) /he 8racle #eports Builder allo%s the de eloper to create sophisticated reports in a ariety of layouts and contains many customi&ation features) In this section, the (asic steps for creating a simple report and a MasterEDetail report %ill (e gi en)

+0.+ 6tarting Developer tools under

indo!s "#$"%$&T$'000

@ typical installation of De eloper creates se eral folders under the Start ,rograms menu) /he main items for the 8racle #eports ;i programs are found under the menu itemC Or5A"e Repor6s 6i and include the follo%ing itemsC

/o run 8racle #eports Builder under 0indo%s 123143N/3+555, click on the +65r6 :B ProCr5!s :B Or5A"e Repor6s 6i :B Repor6 ui"4er menu item) @s %ith 8racle 9orms, an initial screen %ill appearC

Click on the Cancel (utton to proceed directly to the 8(:ect Na igator)

+0.' The Oracle Reports O1:ect &avigator


/he 8racle #eports main screen is called the 8(:ect Na igator !similar to 8racle 9orms" and can (e seen in the follo%ing figureC

/he main sections of the 8(:ect Na igator areC *) Data 0odel E Contains information a(out -ueries used for a report) +) 3a2out E Contains information a(out ho% a report is formatted including headers, footers, margins, fonts, etc) .) -arameter Form E Contains information a(out the initial screen that is displayed %hen a form first runs) 7) Report Triggers E ,<3SA< code that can (e eBecuted (efore, during or after a report has (een eBecuted)

@s %ith 8racle 9orms, the first step in using 8racle #eports is to Connect to an 8racle ser er) /his is accomplished (y pulling do%n the %i"e menu and selecting the ConneA6 menu item) 9ill in your 8racle Username and 8racle ,ass%ord !press the ta( key to mo e (et%een the fields") 9or the D56575se field, type in the ser ice name for your 8racle data(ase) 9or eBample, if you are using ,ersonal 8racle <ite, the D56575se: %ould (e OD C:POL*TE) Contact your system administrator to learn the ser ice name for your 8racle data(ase and pro ide that information in the D56575se: field)

Click on the ConneA6 (utton to complete the connection !Under some ersions of UNI6, the (utton is la(eled O2") If the user name or pass%ord is mistyped or incorrect, the dialog (oB %ill (e reEdisplayed) Be sure to pro ide your 8racle username and pass%ord !not your UNI6 host pass%ord")

+0.5 Creating Reports in Oracle Reports


Creating reports follo%s a 7 step processC *) Define the Data Model E /his step specifies %hich -ueries should (e run on the data(ase including ho% multiple -ueries are related and ho% they are grouped) /his step must (e done (y hand) Aueries that ha e (een created else%here can (e imported into 8racle #eports) +) Define the <ayout E /his step specifies the layout of the report including the o erall orientation of -uery results and the suppression of repeating groups) /here are a num(er of default report layouts that can automatically (e applied to a data model) .) Create and3or Customi&e the ,arameter 9orm E If some user input is re-uired in order to run the report, then a parameter form must (e customi&ed) @ll reports ha e a default parameter form) 7) !optional" Create any triggers or program units that %ill (e eBecuted %ith the report) 8racle #eports .)5 and ;)5 support a %i&ard that takes the de eloper through all of these steps) /his approach %ill (e demonstrated neBt)

+0.9 Creating a 6ingle<Ta1le Report

In this section, %e go through the steps for creating a report that ie%s the contents of a single ta(le) +0.9.+ 6pecif2 the Data 0odel and 3a2out /he first step is to specify the data model and layout of the report) 0e %ill use the #eport %i&ard to accomplish this) 9rom the 8(:ect Na igator, pull do%n the Too"s menu and choose Repor6
GiJ5r4...

/he first screen for the reports %i&ard %ill appear prompting for the style of the report and for the #eport /itle)

/he eight layout choices includeC *) /a(ular E Simple ta(le %ith column headings at the top and data records in consecuti e ro%s (elo%) +) 9ormE<ike E Column headings on the left hand side %ith data alues neBt to them on the right) .) Mailing <a(el E No column headings and records grouped into repeating sections si&ed to print directly to a sheet of mailing la(els) 7) 9orm <etter E @r(itrary placement of data items %ithin a teBt (ody)

2) >roupE<eft E @ Master3Detail3Detail style %here the master records are grouped on the left hand side %ith details to the right) ;) >roupE@(o e E @ Master3Detail3Detail style %here the master records appear a(o e the detail records) D) MatriB E Column la(els on (oth the left and the top %ith data alues in the middle) Similar to a spreadsheet) 4) MatriB %ith >roup E @ com(ination of Master3Detail !>roupE@(o e" and MatriB) 9or this report, type in K=mployee #eportK as the title, choose the Ta1ular <ayout and click on the NeBt (utton) /he neBt step is to specify the /ype of -uery the report %ill (e (ased on) /he t%o main choices are a SA< -uery and an 8racle =Bpress !8<@," -uery) 98r this eBample, choose the KSA< StatementK and click the neBt (utton) /he neBt step is to specify the -uery that %ill form the (asis of the report) In this case, type the follo%ing -uery in the SA< Auery StatementC teBt (oBC
+ELECT %NAME) LNAME) ++N) +ALARY) DNO %ROM EMPLOYEE /

/hen click on the NeBt (utton to mo e to the neBt step) NoteC If you did not Connect to the data(ase, you %ill (e prompted for the Username, ,ass%ord and Data(ase) In the neBt %i&ard dialog (oB, specify %hich columns from the SA< Auery %ill (e displayed in the report output) /o specify all columns, click on the dou(le right arro% to (ring all of the /vailable Fields to the Dis$layed Fields side)

Click on the NeBt (utton to mo e to the neBt dialog (oB) In the neBt step, aggregate functions can (e applied to the fields on the report) 9or this eBample, %e %ill display the a erage salary as %ell as a count of employees) Highlight the S@<@#Y field and click on the /verage (utton) /hen highlight the SSN field and click on the Count (utton)

/he neBt dialog (oB allo%s you to change the field la(els and display %idths for arious fields in the report)

@s a final step, a design template can (e applied to the report) Design templates include specifications for fonts, colors and layout of the report) 9or this eBample, choose the Corporate + template and then click on the 9inish (utton)

@fter a short delay, the #eports <i e ,re ie%er %ill appear sho%ing the eBecuting report)

It is possi(le to make changes to the layout of the report (y using the tool palette on the left hand side) 0hen you ha e finished touching up the report, close the #eports <i e ,re ie%er and the 8(:ect Na igator %ill reappear) /o ie% the report again, pull do%n the ProCr5! menu and choose Run Repor6) +0.9.' 6aving, Generating and Running the Report /o sa e a report, pull do%n the %i"e menu and choose the +5Ee option) /his is similar to sa ing an 8racle 9orm) /he source code for 8racle #eports are sa ed in files %ith an .r48 file name eBtension) Compiled and generated reports are sa ed %ith a .rep eBtension) 9or this eBample, sa e this report as e!p"o#ee.r48

8nce the report is sa ed, it can (e run (y pulling do%n the VieG menu and choosing the Run6i!e PreEieG menu item) @s the report is running, an @cti ity screen %ill appear gi ing an indication of the processing that is currently under%ay)

/he @cti ity %ill go through . stagesC Client @cti ity %hile the -ueries are prepared, Ser er @cti ity %hen the -ueries are eBecuted and finally Client @cti ity as the report is formatted) 0hen this is finished, the report %ill appear on screen)

+0.# /@erciseA Creating a Report


9or this eBercise, create a report to display all of the records in the D=,@#/M=N/ ta(le including a :oin %ith the =M,<8Y== ta(le to display the last name of the department manager) Start up the #eport %i&ard) Use KDepartmentsK as the title and enter the follo%ing SA< Statement as the -ueryC
+ELECT 4nu!7er) 4n5!e) !Crs65r6456e) !Crssn) "n5!e %ROM 4ep5r6!en6) e!p"o#ee ?&ERE 4ep5r6!en6.!Crssn L e!p"o#ee.ssn/

Summari&e the report %ith an a erage of the Salary column) Sa e the ne% report as 4ep5r6!C.r48

/he finished report should look something like the follo%ingC

+0.6 Creating a 0aster<Detail Report


In this section, the steps for creating a report that ie%s the contents of t%o ta(les in a MasterE Detail !one to many" relationship are gi en) /o a oid any confusion, Sa e and Close any eBisting reports (efore proceeding) +0.6.+ 6pecif2 the 0aster<Detail Data 0odel and 3a2out @s in the singleEta(le report, %e (egin (y specifying the data model and layout for the MasterE Detail report (y using the #eport 0i&ard) In oke the %i&ard (y pulling do%n the Too"s menu and choosing Repor6 GiJ5r4) 9ollo%ing these steps to complete the %i&ardC *) 9or the #eport /itle useC Departments and =mployees +) 9or the +e$ort Style, choose .rou$ /bove) .) Choose a SA< Statement and the SA< AueryC
4. '. 6. +ELECT DNAME) %NAME) LNAME) +ALARY %ROM DEPARTMENT) EMPLOYEE ?&ERE DEPARTMENT.DN,M ER L EMPLOYEE.DNO

D) Designate the DN@M= field as a .rou$ field !<e el *") Click on the DN@M= field and then on the right arro% (utton) 4) Display all fields in the report) 1) Choose @ erage Salary as a Totals field) Click on the S@<@#Y field and then click on the @ erage (utton) *5) /ouch up the fields and la(els as follo%sC
11. 12. 1-. 14. 1'. 16. 17. %ie"4s 5n4 To65"s DNAME %NAME LNAME +ALARY AEC+ALARYperDNAME AEC+ALARYperRep L57e"s Dep5r6!en6 N5!e %irs6 N5!e L5s6 N5!e +5"5r# AEer5Ce: AEer5Ce %or 5"" E!p"o#ees:

*4) Use the Corporate + template) 9rom this point, click on 9inish to display the <i e #eport ,re ie%C

+0.6.' 6aving, Generating and Running the 0aster<Detail Report @t this point, the report can (e sa ed and =Becute !#un") 9or this eBample, sa e the MasterEDetail report as 4ep61e!p.r48

+0.B /@erciseA Creating a 0aster<Detail Report


In this eBercise, a masterEdetail report %ill (e created that displays each =M,<8Y== record, %ith a group of D=,=ND=N/ (elo%)

Create a ne% #eport using the %i&ard) >i e a titleC K=mployees and /heir DependentsK Select the >roup @(o e report type and use the follo%ing SA< -ueryC
+ELECT e!p"o#ee.8n5!e) e!p"o#ee."n5!e) e!p"o#ee.7456e A+ E!p 456e) e!p"o#ee.seF A+ E!p+eF) 4epen4en6.4epen4en61n5!e) 4epen4en6.7456e A+ Dep 456e) 4epen4en6.seF A+ Dep+eF) 4epen4en6.re"56ionship e!p"o#ee) 4epen4en6 e!p"o#ee.ssn L 4epen4en6.essn/

%ROM ?&ERE

Note the use of column aliases !@S" to differentiate the (date and seB columns)

Select the "n5!e) 8n5!e) e!pseF) e!p7456e fields as the K>roup *K fields) /hese should all (e from the =M,<8Y== ta(le) Select all fields to display in the report and do not select any fields for the calculate totals step) /ouch up the report in the li e pre ie%er to fit on one screen) Sa e the report as fileC e!p4epen.r48

/he report should look similar to the follo%ing %hen completedC

+0.% -arameter forms in Oracle Reports


9or each of the 8racle #eports eBamples thus far, all of the records in the respecti e ta(les %ere returned as part of the report) Ho%e er, there may (e situations %here only a su(set of the data(ase records are re-uired) In these cases, %e %ould like to prompt the user to enter some criteria that can (e used to filter the report) In 8racle #eports, a ,arameter Form fulfills this role) ,arameter forms are simple 8racle forms that prompt the user for some information (efore a report is eBecuted) /his information can (ecome part of the 0H=#= clause in the report -uery and is used to filter the records returned in the report) ,arameters in 8racle #eports can either (e filled in (y the user on a parameter form or can (e filled in automatically (y passing the parameters in from another 8racle 9orms form !see the eBample of parameter passing in the pre ious section on 8racle 9orms") In the follo%ing eBample, a simple parameter form is automatically created (y 8racle #eports to restrict a -uery on the =M,<8Y== ta(le (y sho%ing only employees in a gi en department num(er !DN8" supplied (y the user) *) Create a ne% report using the report %i&ard) Specify K=mployeesK as the report title and use a /a(ular report layout)

+) Use the follo%ing SA< -uery eBactly as %ritten) Note the use of the full colon in the 0H=#= clause)
-. 4. '. +ELECT P %ROM e!p"o#ee ?&ERE e!p"o#ee.4no L :DNO1PARAMETER/

In the a(o e -uery, CDN8$,@#@M=/=# is the name of a run time parameter) 0hen the report is eBecuted, the user %ill supply a alue for this parameter thus completing the 0H=#= clause for the -uery) Clicking on the NeF6 (utton %ill produce the follo%ing alertC

;) Choose all of the columns !fields" for display in the report) Do not choose any fields for summary information) D) 0hen the report %i&ard is finished, the report and parameter form !(ased upon the parameters gi en in the SA< -uery" %ill (e created) @s the li e pre ie%er is running, the ne% parameter form %ill (e displayedC

9or this eBample, choose department 2 !type the num(er 2 in the field" and press the enter key) Notice that only employees in department 2 are displayed in the li e pre ie%er) +0.%.+ =uilding a Custom -arameter Form

@t this point, %hene er the report is run, a default parameter form sho%ing the DN8$,@#@M=/=# %ill (e displayed) Ho%e er, it is possi(le to create a custom parameter form as sho%n in the follo%ing steps)
1. S%itch to the 8(:ect Na igator, pull do%n the Too"s menu and choose the P5r5!e6er
%or! ui"4er)

/his is sho%n (elo%C

@ num(er of (uiltEin system parameters are displayed and can (e highlighted (y clicking on them %ith the right mouse (utton) Note that at the (ottom of this list is the DN8$,@#@M=/=# and it should already (e selected)
2. 9or this eBample, in addition to the DN8$,@#@M=/=# also select the D=S/Y,=,

D=SN@M= and C8,I=S parameters) /hen click the O2 (utton) @ ne% parameter form %ill (e automatically created as sho%n (elo%)

3. Sa e the report as e!pp5r5!.r48) 0hen the form is eBecuted !pull do%n the ProCr5!

menu and choose Run Repor6", the ne% parameter form %ill (e displayed as sho%n (elo%C

In the a(o e eBample, * copy of the report %ill (e sent to the printer named KH, <aser?et Series IIK) /he report %ill only sho% employees in department 7)

8ther Destination /ype options include Screen, 9ile and =Email) ,arameter forms can (e highly customi&ed to include list of alues user prompts and other userE friendly features) /he techni-ues used for 8racle 9orms can (e easily applied to parameter forms in 8racle #eports)

++. Creating 0enus in Oracle Forms


NoteC /he properties for Menus in different ersions of 9orms seem to change %ith e ery minor re ision) ,lease keep in mind, the ersion of 9orms you are %orking %ith may differ slightly from %hat is sho%n in this tutorial)

/hus far, %e ha e co ered the (asics for creating forms and reports using 8racle De eloper) Some ad anced features such as using stored procedures !,rogram Units" ha e also (een introduced) In a complete Data(ase System, the applications consist of many forms and reports that might (e used (y a num(er of users) @ccess to forms and reports is typically accomplished through menus) In 8racle De eloper, menus can (e created to guide users into forms and reports of interest) Menus are designed as part of the 8racle 9orms designer) In 8racle 9orms, e ery form runs %ith one of the follo%ingC *) /he default menu %hich includes the @ction, =dit, Block, 9ield, #ecord, Auery, 0indo%, Help menus) /he structure of the default menu cannot (e changed)

+) @ custom menu that you define as a separate module and then attach to the form for runtime eBecution) .) No menu at all) /he default menu is part of the form module) Ho%e er, custom menu modules are separate from form modules) So, %hen a singleEform application runs using a custom menu, there %ill (e t%o eBecuta(le filesC

an .%M. form module an .MM. menu module

In a multiEform application, Multiple forms can share the same menu, or each form can in oke a different menu) /o eBplicitly specify the default menu in 9orms ;iC 1. Select the name of the form3module in the /o eBplicitly specify the default menu in older ersions of De eloperC

8(:ect Na igator) Click %ith the right mouse (utton and choose Proper6ies from the popE up menu) +) In the 0enu 0odule property, type D=9@U</NSM@#/B@# to get the default menu and a (utton (ar (elo% it) If you %ant the form to run %ithout a menu, lea e the 0enu 0odule property (lank)

1. Select the name of the form3module

in the 8(:ect Na igator) Click %ith the right mouse (utton and choose Proper6ies from the popEup menu) +) In the 0enu 0odule property, type D=9@U</) If you %ant the form to run %ithout a menu, lea e the 0enu 0odule property (lank)

/he default menu is suita(le for control o er the current form (eing eBecuted, ho%e er, it does not contain custom menu items pertaining to a specific application) In the follo%ing section, the steps to create a custom menu structure %ill (e introduced)

++.+ The Oracle Forms 0enu (ierarch2


/he 8racle 9orms menu hierarchy contains three o(:ect categoriesC *) 0enu modules E <ike form modules, a menu module can contain its o%n items !menus and menu items", program units and other o(:ects) +) 0enus E Including main menus, indi idual menus, and su(menus .) 0enu items

++.' Creating a Custom 0enu


Designing a custom menu re-uires fi e (asic stepsC *) Creating a menu module +) Creating menus and menu items .) @ssigning commands to menu items 7) Sa ing and generating the menu module 2) @ttaching a menu module to a form ++.'.+ Creating a 0enu 0odule /he first step in designing a custom menu is to create a menu module) /here are se eral %ays to create a ne% menu moduleC 1. ,ull do%n the %i"e menu, highlight the NeG menu item and then select the Menu menu item) 2. Na igate do%n to the 0enus su(tree in the 8(:ect Na igator, pull do%n the N5EiC56or menu and choose the Cre56e menu item) @ ne% menu module %ill (e created and a default name %ill (e assigned) Click on this default menu name and assign it a more meaningful name such as !#!enu) ++.'.' Creating menus and menu items Creating menus and menu items can (e accomplished using the 0enu /ditor) /o acti ate the menu editor, first highlight the name of your menu, then pull do%n the Too"s menu and click on the Menu E4i6or item)

/he main menu items go across the top of the screen) /o add a ne% menu across the top, click on the =uild Across icon on the tool(arC

Su(Emenus and menu items appear (elo% each one) /o add a ne% su(Emenu or menu item, click on the =uild Do!n icon on the tool(arC /o change the name of a menu or menu item, click in the menu o(:ect and o erE%rite the name that appears there) Using the icons, create and reEla(el se eral menus and menu items to appear as follo%sC

8nce this is completed, the (asic menu structure %ill (e in place) /he neBt step is to add functionality to each menu item) ++.'.5 Assigning Commands to 0enu ,tems /he default (eha ior for clicking on any menu is for that menuIs items to (e displayed) /he neBt step is to assign commands to each of the menu items so that %hen a user clicks on a menu item, a form, report or SA<G,lus script is eBecuted) /o assign a command to a menu itemC
1. Select the desired menu item in the Menu =ditor) Click %ith the right mouse (utton and

choose Proper6ies to (ring up the properties of that menu item)


NoteC /he popEup menu may sho% Proper6# P5"e66e

+) /he properties of interest here areC


o

Command t2peA Indicates %hat kind of command should (e runC 9orm, #eport, ,<3SA<, other menu) In general, the ,<3SA< command type is used to launch 8racle 9orms and 8racle #eports) /he specific 9orm and #eport command types are maintained for (ack%ards compati(ility only) 0enu ,tem Code !or Command Te@t"C /he teBt of the actual command to run)

/o run a form from the menu item, choose Command T2pe ,<3SA<) Dou(le click on the 0enu ,tem Code !or Command Te@t" property and type in the ,<3SA< editorC
E3*N R,N1PROD,CT$%ORM+) 9e!p"o#ee9) +YNC&RONO,+) R,NT*ME) %*LE+Y+TEM) 99) 99(/ END/

#UN$,#8DUC/ is a ,<3SA< (uiltEin function that runs another 8racle De eloper product) /he parameters to #UN$,#8DUC/ areC
o o o o o o o

,roductC 98#MS or #=,8#/S Document3ModuleC name of the file in single -uotes Command ModeC SYNCH#8N8US or @SYNCH#8N8US =Becuta(le ModeC #UN/IM= <ocationC 9I<=SYS/=M or D@/@B@S= ,arameter <istC @ list of parameters to pass to the form or NU<< DisplayC /ype of display to sho% the product on) Can (e NU<< to indicate the current display) NoteC Starting %ith 9orms 2)5, !%hich uses ,<3SA< ersion +)." you may not use NU<< in the call to #UN$,#8DUC/ here) You must use t%o single -uotes !indicating a &ero length character string")

Compile this code (y clicking on the Co!pi"e (utton) /hen close the ,<3SA< editor) #epeat the a(o e steps for each menu item) @ final menu item should (e created to =Bit the application) Call the menuC /@it Application and enter the follo%ing ,<3SA< codeC
E3*N E.*T1%ORM/ END/

=6I/$98#M is a (uiltEin procedure that eBits the current form) @ Fie% of the complete !#!enu is sho% (elo%C

++.'.9 6ave and Generate the 0enu 0odule @t this point, all of the menu structure has (een created and commands for each menu item ha e (een specified) /he menu module must no% (e sa ed to a file !%ith a .!!7 eBtension" and >enerated or Compiled) /o sa e the menu module, make sure the name of the menu is highlighted, pull do%n the 9ile menu and choose the +5Ee menu item) Specify a file name %ith a .!!7 eBtension) /his is the Ksource codeK for the menu) 9or this eBample, use the file name !#!enu.!!7) /o generate or compile the menu module, pull do%n the %i"e menu, click on the A4!inis6r56ion menu item and choose 3ener56e from the flyout menu) In some ersions of the 9orms Builder, the menu item might (e called Co!pi"e %i"e) >enerating or compiling a menu module results in a file %ith a .!!F eBtension) In this eBample, the generated menu module (ecomesC !#!enu.!!F ++.'.# Attaching a 0enu 0odule to a Form @ custom menu must (e attached to a form in order to (e displayed) /ypically, a form %ith no data entry on it is used as the main screen to host the custom menu) /he follo%ing steps are different depending on the ersion of 9orms (eing used) For Oracle Forms version 9.#
1. Create a ne% form %ith no (locks or

For Oracle Forms version 6i


1. Create a ne% form %ith no (locks or

items on it) ,ull do%n the %i"e menu, select NeG and then select %or!)
2. Display the properties for the form and

set the 0enu 0odule property to the file

items on it) ,ull do%n the %i"e menu, select NeG and then select %or!) Click on the name of the form in the o(:ect na igator and rename it as

name of the menu module !see pre ious step") 9or this eBample, it should (eC
!#!enu.!!F

7"5n08or!)

2. 8pen up the property palette for the

3. Make sure the 7se File property is set to


True)

form and set the follo%ing propertiesC 0enu 6ourceC 9ile E /he menu information %ill come from a file) 0enu 0oduleC !#!enu.!!F E /he file name of the compiled menu module) You may ha e to gi e the eBplicit path to this .!!F file) 9or eBample, if this file is on your @C dri e then type
5:K!#!enu.!!F

4. Sa e the form as file 7"5n08or!.8!7 and

generate this form) !Note you should sa e the this form in the same dri e and directory as your menuIs .!!F file") 2) #un the form)
3. Sa e the form as file 7"5n08or!.8!7

and generate this form) !Note you should sa e the this form in the same dri e and directory as your menuIs .!!F file") 7) #un the form) Notice that %hen running this (lank form, the default menu is replaced (y the !#!enu Menu Module)

/he (lank form that is used to host the menu need not (e (lank) You may %ish to use the <ayout =ditor to place some graphics and a title of the application on the can as) @nother use for this space %ould (e for some simple instructions the user can read to get started %ith the data(ase application)

+'.+ Graphics and the Chart

i)ard

/he 8racle >raphics Designer can (e used to create a ariety of graphs and charts including (ar charts, line plots and pie graphs) /ypically, a graphic o(:ect designed %ith 8racle graphics is included on either a form or a report) /he 8racle 9orms Designer includes a %i&ard that %ill automatically construct an 8racle graphic o(:ect using data from an eBisting data (lock)

+'.+ Adding a Chart to a Form


In the follo%ing eBample, an 8racle >raphics o(:ect %ill (e added to a (asic Master3Detail form) @s a first step, create a ne% Master3Detail form using the D=,@#/M=N/ ta(le !DNUMB=# and DN@M= columns" as the master (lock and the =M,<8Y== ta(le !9N@M=, <N@M=, DN8 and S@<@#Y columns" as the detail (lock) /he chart added to this form %ill compare the S@<@#Y alues of the employees in a gi en department) @n eBample layout is sho%n (elo% !note the DN8 column in the =M,<8Y== (lock is not displayed"C

Be sure to sa e this form on disk (efore mo ing on to create the chart) /o start the Chart 0i&ard, click on any open area of the form %hile in the layout ie%) /hen pull do%n the Too"s menu and choose the Ch5r6 ?iJ5r4) /he first screen of the Chart 0i&ard %ill appear as (elo%C

Click the NeF6 (utton to mo e to the neBt step in the %i&ard) In the neBt step, choose the type of chart !and su(type if applica(le" to (e created) 9or this eBample, choose Pie and Dep6h as sho%n (elo% and click on the NeF6 (uttonC

/he neBt step is to choose %hich data (lock the chart should (e (ased on) @ll of the data (locks on the current form should (e displayed) 9or this eBample, choose the =M,<8Y== (lock as sho%n (elo% and click on the NeF6 (uttonC

/he neBt step is to choose %hich field in the data (lock should (e used for the 6E@Bis !or category la(els" for the chart) 9or this eBample, choose the <N@M= field as sho%n (elo% and click on the NeF6 (uttonC

/he neBt step is choose %hich field in the data (lock should (e used as the YE@Bis alues) 9or this eBample, choose the S@<@#Y field as sho%n (elo% and click on the NeF6 (uttonC

In the last step for the %i&ard, the ne% 8racle >raphics o(:ect must (e sa ed in a file) >i e a ne% name for the graphics o(:ect such as e!p"o#ee.oC4 as sho%n (elo% and click on the %inish (uttonC

@t this point, the graphics o(:ect %ill (e created and placed on the form) Use the mouse to mo e and reEsi&e the o(:ect as desired) 0hen finished, sa e the form again and run it) /he follo%ing figure sho%s the form as it is running) Notice that %hen the form is -ueried and as ne% department records are retrie ed, the employees and their associated salaries for that department are displayed in the pie chart)

0hen copying forms files that use 8racle >raphics, (e sure to also copy the associated graphics o(:ect files) /hese files typically ha e an .O3D file eBtension)

+'.' /@erciseA Adding a Chart to a Report


9or this eBercise, add a (ar chart depicting the employees salaries to a report sho%ing additional =mployee data) Start (y creating a (asic ta(ular #eport making use of the follo%ing -ueryC
+ELECT %NAME) LNAME) DNO) +ALARY %ROM EMPLOYEE

/he (asic report is sho%n (elo%C

NeBt, add the Chart using the Chart %i&ard) Specify KSalariesK as the chart title, and use a Bar chart style %ith KDepthK as the su(Etype) 9or the 6 @Bis, choose <N@M= and for the Y @Bis choose S@<@#Y) Choose to place the chart at the end of the report and gi e the chart o(:ect the name Krepsal)ogdK) ImportantC Make sure that the chart o(:ect !the )ogd file" and the report file are in teh same directory) By default chart o(:ects may (e stored in another location) If they are not together, you %ill get an error such as K#eports is una(le to find the chart o(:ectK) Belo% is the final output of the report %ith the em(edded 8racle >raphics chart o(:ectC

+5. Oracle 6chema =uilder


/he 8racle Schema Builder pro ides an easy to use graphical user interface for defining and modifying ta(les, ie%s and other schema o(:ects)

/o run the Schema Builder, choose it from the 8racle menu) @s %ith most 8racle de elopment tools, the first step %ill (e to connect to the data(ase) /he Connect dialog (oB %ill appear as (elo%C

,ro ide a alid username, pass%ord and connect string !Host string" and click on the ConneA6 (utton to esta(lish a connection to the data(ase) /he main Schema Builder screen %ill appearC

+5.+ Creating &e! 6chema O1:ects

Creating a ne% ta(le is a straight for%ard process) 9irst, pull do%n the +Ahe!5 menu and choose the Cre56e T57"e menu item) @ small menu %ill appear) Choose T57"e) /he mouse pointer %ill change to an arro% %ith a N sign) Click in the open space of the Schema Builder main screen and the ne% ta(le %ill (e created)

Note that the ne% ta(le is gi en a default name !TA LE1" and it contains se eral eBamples columns) /o change the name of the ta(le, click on the current name and type o er it %ith a ne% name) Do not use spaces in the ta(le name) 0hen finished, press =nter or #eturn to set the ne% name for the ta(le) /o change the name of a column, click on a column name and type o er the eBisting name) /o add more columns to the ta(le, simply click the lo%er right hand corner of the ta(le display and drag it do%n%ards) @dditional columns %ill appear %ith their default names) /o change the data type and other characteristics of columns, dou(le click on the column name) /he Define Column dialog (oB %ill appear) Highlight the column you %ish to modify and change its datatype and other options on the right hand side) In the figure (elo%, the N@M= column has (een changed to F@#CH@#!+5" and a N8/ NU<< constraint has (een added (y checking off the ReOuire4 check(oB)

In the follo%ing figure, the CUS/8M=#ID column has (een designated as the key (y checking off the Pri!5r# 2e# and ,niOue check (oBes)

In the follo%ing figure, each of the columns in the CUS/8M=# ta(le ha e (een definedC

8nce each of the columns has (een renamed and defined, the ta(le must (e sa ed in the data(ase) /o see the SA< statements that %ill (e sent to the data(ase ser er, pull do%n the +Ahe!5 menu and choose the +hoG +>L menu item)

@t this point, the SA< statements that %ill (e used to create the schema can (e sa ed into a teBt file for future use) /o sa e the SA< statements, pull do%n the %i"e menu and choose +5Ee +>L)

@ standard %indo%s file sa e dialog (oB %ill appear) /he default file eBtension for SA< files is
.sO"

/o commit the schema in the data(ase, either click on the Co!!i6 (utton in the +hoG +>L dialog (oB or, from the main Schema Builder screen, pull do%n the +Ahe!5 menu and choose the Co!!i6 +Ahe!5 menu item) @ dialog (oB %ill appear sho%ing the progress)

/o re ie%, a typical Schema Builder session %ould consist of adding ne% ta(les to a schema using the Cre56e T57"e menu item on the +Ahe!5 !enu) Columns in ta(les can (e defined (y dou(le clicking on the ta(le icons) 8nce all of the ta(les ha e (een defined in the Schema Builder main screen, sa e off the SA< to a file and then commit the schema in the data(ase)

+5.' Displa2ing /@isting 6chema O1:ects


If the schema has some ta(les or ie%s already defined, these can (e displayed (y pulling do%n the D565 menu and choosing the +e"eA6 D565 T57"es menu item) @ dialog (oB %ill appear displaying the a aila(le ta(les)

/o include a ta(le in the Schema Builder main screen, highlight a ta(le and click on the *nA"u4e (utton) /he ta(le should appear on the main screen and the name of the ta(le %ill (e grayed out in the dialog (oB) In this eBample, the =M,<8Y== and D=,@#/M=N/ ta(les %ere included in the main screen) 0hen all of the desired ta(les ha e (een displayed, click on the C"ose (utton to close the dialog (oB) Belo% is the resulting main screen after the =M,<8Y== and D=,@#/M=N/ ta(les %ere addedC

+5.5 Adding Relationships 1et!een Ta1les


8nce the ta(les ha e either (een created or displayed in the Schema Builder main screen, relationships (et%een ta(les can (e defined) In this eBample, the DNUMB=# column of the D=,@#/M=N/ ta(le is related to the DN8 columns in the =M,<8Y== ta(le) /he DNUMB=# column in D=,@#/M=N/ must (e defined as a ,rimary Jey) /o create the appropriate constraints for this relationship, pull do%n the +Ahe!5 menu and choose the De8ine Re"56ionship menu item) @ dialog (oB %ill appear %ith spaces for the 9oreign Jey and ,rimary Jey) 9ill these in as appropriate for the relationship) In this eBample, the 9oreign Jey is =M,<8Y==)DN8 and the ,rimary Jey is D=,@#/M=N/)DNUMB=# as sho%n in the figure (elo%C

Click the O2 (utton to confirm the relationship) /he display %ill then change) @ line %ill appear linking the ,rimary Jey and 9oreign Jeys)

8nce again, Schema Builder pro ides a ie% of the SA< that %ill (e used to create the 9oreign key constraints that %ill implement the relationship in the data(ase schema) /o see the SA<, pull do%n the +Ahe!5 menu and choose the +hoG +>L menu item)

@s (efore, the SA< statements to create the foreign key constraints can (e sa ed to a file using the %i"e menu and +5Ee +>L menu item) 9inally, to commit the changes to the data(ase, pull do%n the +Ahe!5 menu and choose the Co!!i6 +Ahe!5 menu item) /he neBt time (oth D=,@#/M=N/ and =M,<8Y== are displayed in Schema Builder, the relationship %ill automatically appear)

,lease feel free to use these tutorials for your o%n personal use, education, ad ancement, training, etc) Ho%e er, I kindly ask that you respect the time and effort I ha e put into this %ork (y not distri(uting copies, either in %hole or in part, for your personal gain) You may not under any circumstances do%nload, cache or host copies of these tutorials on your o%n ser ers) Use of these tutorials for commercial training re-uires a special arrangement %ith the author or authors)
@ll material Copyright *11DE+55* #) Holo%c&ak

You might also like