Contents 1. Introduction 2. Prerequisites 3. Developer Tools o 3.1 Starting Developer tools under Windows 95/9/!T/2""" o 3.2 Starting Developer tools under #!I$ %. T&e 'racle (or)s Designer *ain Screen o %.1 'racle (or)s '+,ect !avigator o %.2 -onnecting to t&e Data+ase 5. (or)s Design .. -reating a (or) wit& a Single /loc0 o ..1 -reating a !ew /loc0 o ..2 T&e 1a2out 3ditor o ..3 Displa2ing Properties o ..% Saving4 5enerating and 6unning (or)s ..%.1 Saving a (or) ..%.2 -o)piling//uilding a (or) ..%.3 6unning a (or) ..%.% 6unning a (or) as a 7ava 8pplication or 8pplet ..%.% 9uer2 /2 3:a)ple o ..5 3:ercise; -reating a Single /loc0 (or) <. -reating a *aster=Detail (or) o <.1 T&e *aster=Detail 6elations&ip o <.2 Steps to -reate a *aster=Detail (or) <.2.1 -reate t&e *aster /loc0 <.2.2 -reate t&e Detail /loc0 o <.3 6elation Properties o> a *aster=Detail (or) o <.% Progra) #nits in a *aster=Detail (or) o <.5 3:tending *aster=Detail (or)s o <.. 3:ercise; -reating a *aster/Detail (or) . 1ist o> ?alues @1'?sA and !on=/ase Ta+le (ields o .1 -reating a 1ist o> ?alues .1.1 -reate a new 1'? '+,ect .1.2 Speci>2 t&e 1'? 9uer2 Te:t .1.3 Speci>2 t&e -olu)n *apping Properties .1.% 8ttac& t&e 1'? to t&e ite) .1.5 Test t&e 1'? o .2 !on=/ase Ta+le >ields .2.1 8dding a !ew Ite) to an 3:isting Data /loc0 .2.2 -reating a Trigger .2.3 -reate a new 1ist o> ?alues o .3 3:ercise; -reating an 1'? and !on=/ase Ta+le >ield 9. 'racle (or)s Progra) #nits and Stored Progra) #nits o 9.1 -reating Procedures in 'racle (or)s 9.1.1 8dd a new ite) to t&e 3*P1'B33 /loc0 9.1.2 -reate a Procedure to -ount 't&er Depart)ent *e)+ers 9.1.3 -reate a Trigger to -all t&e Procedure 9.1.% Save4 -o)pile and 6un t&e (or) o 9.2 -reating Stored Progra) #nits @ProceduresA in S91CPlus o 9.3 8dditional Stored Procedures and Triggers 9.3.1 5enerating unique or consecutive identi>iers using t&e ta+le 9.3.2 5enerating unique or consecutive identi>iers using an 'racle Sequence 9.3.3 -&ec0ing constraints at t&e client 9.3.% 8dding 8lerts @Pop=up *essagesA 9.3.5 Populate ite)s wit& de>ault values 9.3.. 8ttac&ing >unctionalit2 to co))and +uttons 9.3.< Passing para)eters +etween >or)s o 9.% 3:ercise; Procedures and Triggers 1". 'racle 6eports /asics o 1".1 Starting Developer tools under Windows 95/9/!T/2""" o 1".2 T&e 'racle 6eports '+,ect !avigator o 1".3 -reating 6eports in 'racle 6eports o 1".% -reating a Single=Ta+le 6eport 1".%.1 Speci>2 t&e Data *odel and 1a2out 1".%.2 Saving4 5enerating and 6unning t&e 6eport o 1".5 3:ercise; -reating a 6eport o 1".. -reating a *aster=Detail 6eport 1"...1 Speci>2 t&e *aster=Detail Data *odel and 1a2out 1"...2 Saving and 6unning t&e *aster=Detail 6eport o 1".< 3:ercise; -reating a *aster=Detail 6eport o 1". Para)eter >or)s in 'racle 6eports 1"..1 /uilding a -usto) Para)eter (or) 11 -reating *enus in 'racle (or)s o 11.1 T&e 'racle (or)s *enu Dierarc&2 o 11.2 -reating a -usto) *enu 12 5rap&ics and t&e -&art WiEard o 12.1 5rap&ics and t&e -&art WiEard o 12.2 3:ercise; 8dding a -&art to a 6eport 13 'racle Sc&e)a /uilder o 13.1 -reating !ew Sc&e)a '+,ects o 13.2 Displa2ing 3:isting Sc&e)a '+,ects o 13.3 8dding 6elations&ips +etween Ta+les 1. Introduction T&is tutorial introduces t&e 'racle Developer .." and .i suite o> tools w&ic& include 'racle (or)s .."4 'racle 6eports .."4 'racle 5rap&ics .."4 'racle Sc&e)a /uilder .." and 'racle Procedure /uilder ..". T&e )ain o+,ectives are to de)onstrate and provide &ands=on instructions on creating and )odi>2ing data entr2 and quer2 >or)s in various con>igurations4 reports and grap&ics. In addition4 t&e >inal section gives so)e instructions on t&e use o> t&e Sc&e)a /uilder. T&is set o> 'racle tools @as o> 8pril4 2""1A is now +undled along wit& We+D/ and 'racle 7Developer in t&e 'racle Internet Developer Suite -D Pac0. -aveats; Please note t&at 'racle tends to c&ange t&ings li0e )enu ite)s4 pro)pts and ot&er s)all t&ings +etween eac& )a,or @certainl2A and o>ten )inor release. Depending on t&e e:act release o> Developer . or .i 2ou &ave4 2ou )a2 >ind so)e s)all discrepencies +etween w&at is s&own in t&is tutorial and w&at 2ou see on 2our screen. 2. Prereuisites /e>ore >ollowing t&is tutorial4 a student )ust &ave a valid user account in an 'racle server. -ontact 2our D/8 or s2ste)s ad)inistrator to learn t&e details o> &ow 'racle server is set up in 2our organiEation. T&is tutorial relies on t&e e:istence o> a >ew ta+les in t&e studentFs sc&e)a. #se t&e 'racle S91CPlus tool to create t&ree ta+les na)ed EMPLOYEE4 DEPARTMENT and DEPENDENT wit& t&e >ollowing attri+utes. !ote; T&is sc&e)a originall2 appears in t&e +oo0; 6a)eE 3l)asri and S&a)0ant /. !avat&e4 Fundamentals of Database Systems. Second 3dition. 8ddison=Wesle2 Pu+ -o4 199%. D!PART"!#T Ta+le Attri$ute Data T%pe D!8*3 ?86-D86@15A !"P&O'!! Ta+le Attri$ute Data T%pe (!8*3 ?86-D86@A *I!IT ?86-D86@2A 1!8*3 ?86-D86@A SS! !#*/36@12A /D8T3 D8T3 8DD63SS ?86-D86@3"A S3$ ?86-D86@1A S8186B !#*/36@<A S#P36SS! !#*/36@12A D!' !#*/36@2A
D!#*/36 !#*/36@2A *56SS! !#*/36@12A *56ST86TD8T3 D8T3 D!P!#D!#T Ta+le Attri$ute Data T%pe 3SS! !#*/36@12A D3P3!D3!TG!8*3 ?86-D86@1"A S3$ ?86-D86@1A /D8T3 D8T3 6318TI'!SDIP ?86-D86@1"A T&e >ollowing -638T3 T8/13 and I!S36T state)ents can +e used to create t&e a+ove ta+les and insert so)e +aseline data using t&e 'racle S91CPlus tool. !ote t&at di>>erent versions o> 'racle accept eit&er 2 digit or % digit 2ear designations in t&e D8T3 datat2pe. It see)s t&e latest versions @'racle and 'racleiA de>ault to accept % digit 2ears. T&e I!S36T state)ents +elow s&ould +e >or)atted accordingl2. CREATE TABLE employee (FNAME VARCHAR2(15), MINIT VARCHAR2(2), LNAME VARCHAR2(15), SSN NMBER(12) NOT NLL, BDATE DATE, ADDRESS VARCHAR2(!5), SE" VARCHAR2(1), SALARY NMBER(#) NOT NLL, SPERSSN NMBER(12), DNO NMBER(2) NOT NLL) $ ALTER TABLE employee ADD CONSTRAINT p%&employee PRIMARY 'EY ((())$ CREATE TABLE DEPARTMENT (DNAME VARCHAR2(15), DNMBER NMBER(2) NOT NLL, M*RSSN NMBER(12), M*RSTARTDATE DATE) $ ALTER TABLE +ep,-.me). ADD CONSTRAINT p%&+ep,-.me). PRIMARY 'EY (+)/m0e-)$ CREATE TABLE DEPENDENT (ESSN NMBER(12), DEPENDENT&NAME VARCHAR2(15), SE" VARCHAR2(1), BDATE DATE, RELATIONSHIP VARCHAR2(12)) $ ALTER TABLE +epe)+e). ADD CONSTRAINT p%&+epe)+e). PRIMARY 'EY (e((), +epe)+e).&),me)$ ALTER TABLE +epe)+e). ADD CONSTRAINT 1%&employee FOREI*N 'EY (e(()) REFERENCES employee ((())$ ALTER TABLE employee ADD CONSTRAINT 1%&+ep,-.me). FOREI*N 'EY (+)o) REFERENCES +ep,-.me). (+)/m0e-)$ INSERT INTO DEPARTMENT VALES (2RESEARCH2, 5, !!!335555, 2224MAY4 15#62) $ INSERT INTO DEPARTMENT VALES (2ADMINISTRATION2, 3, 56#753!21, 28149AN4 15652) $ INSERT INTO DEPARTMENT VALES (2HEAD:ARTERS2, 1, 666775555, 21549N4 15#12) $ INSERT INTO EMPLOYEE VALES (29OHN2,2B2,2SMITH2,12!357#65,28549AN415552,2#!1 FONDREN, HOSTON, T"2, 2M2,!8888,!!!335555,5) $ INSERT INTO EMPLOYEE VALES (2FRAN'LIN2,2T2,2;ON*2,!!!335555,2864DEC415352,27!6 VOSS,HOSTON T"2, 2M2,38888,666775555,5) $ INSERT INTO EMPLOYEE VALES (2ALICIA2,292,2<ELAYA2,55566####,21549L415562,2!!21 CASTLE, SPRIN*, T"2, 2F2,25888,56#753!21,3) $ INSERT INTO EMPLOYEE VALES (29ENNIFER2,2S2,2;ALLACE2,56#753!21,22849N415!12,2251 BERRY, BELLAIRE, T"2, 2F2,3!888,666775555,3) $ INSERT INTO EMPLOYEE VALES (2RAMESH2,2'2,2NARAYAN2,777663333,2154SEP415522,25#5 FIRE OA', HMBLE, T"2, 2M2,!6888,!!!335555,5) $ INSERT INTO EMPLOYEE VALES (29OYCE2,2A2,2EN*LISH2,35!35!35!,2!149L415722,257!1 RICE, HOSTON, T"2, 2F2,25888,!!!335555,5)$ INSERT INTO EMPLOYEE VALES (2AHMAD2,2V2,29ABBAR2,56#56#56#,2254MAR415552,2568 DALLAS, HOSTON, T"2, 2M2,25888,56#753!21,3) $ INSERT INTO EMPLOYEE VALES (29AMES2,2E2,2BOR*2,666775555,2184NOV4152#2, 2358 STONE, HOSTON, T"2, 2M2,55888,NLL,1) $ INSERT INTO DEPENDENT VALES (!!!335555,2ALICE2,2F2,2854APR4 15#72,2DA*HTER2) $ INSERT INTO DEPENDENT VALES (!!!335555,2THEODORE2,2M2,2254OCT4 15#!2,2SON2) $ INSERT INTO DEPENDENT VALES (!!!335555,29OY2,2F2,28!4MAY4 15362,2SPOSE2)$ INSERT INTO DEPENDENT VALES (12!357#65,2MICHAEL2,2M2,28149AN4 15#62,2SON2)$ INSERT INTO DEPENDENT VALES (12!357#65,2ALICE2,2F2,2!14DEC4 15#62,2DA*HTER2)$ INSERT INTO DEPENDENT VALES (12!357#65,2ELI<ABETH2,2F2,2854MAY4 155#2,2SPOSE2)$ INSERT INTO DEPENDENT VALES (56#753!21,2ABNER2,2M2,2274FEB4 15!22,2SPOSE2)$
(. Developer Tools 'racle Developer contains 3 )ain co)ponents; 1. 'racle (or)s = (or designing data entr2 >or)s. 2. 'racle 6eports = (or designing reports. 3. 'racle 5rap&ics = (or designing grap&ics suc& as c&arts t&at can +e added to >or)s or reports. 8dditional co)ponents include; 1. Procedure /uilder = 8n integrated develop)ent environ)ent to write and de+ug stored procedures @progra) unitsA >or use in t&e 'racle data+ase or in an2 o> t&e Developer tools. 2. 9uer2 /uilder = 8 5#I +ased quer2 +uilder tool. 9ueries can +e stored in t&e data dictionar2 or in a >ile s2ste) >or later use and så. 3. Sc&e)a /uilder = 8 5#I tool >or creating and )odi>2ing ta+les4 views and constraints. %. Translation /uilder = 8 tool >or creating >oreign language versions o> applications written in Developer. 5. Pro,ect /uilder = 8 so>tware develop)ent pro,ect )anage)ent s2ste) t&at )anages source code >or all Developer co)ponents. .. P3-S = T&e 'racle Per>or)ance 3valuation/-ollection S2ste) = (or pro>iling t&e e:ecution and per>or)ance o> applications developed wit& 'racle tools. <. Discoverer = 8 data +rowsing tool t&at can +e custo)iEed >or end=users. T&is tutorial covers t&e Developer (or)s4 6eports and 5rap&ics co)ponents and gives a +rie> introduction to t&e Sc&e)a /uilder and Procedure /uilder tools. In t&e >ollowing section4 t&e procedures to run 'racle (or)s under *S Windows 95/9/!T/2""" will +e given. (.1 )tartin* Developer tools under +indo,s -./-0/#T/2111 8 t2pical installation o> Developer creates several >olders under t&e Start Progra)s )enu. T&e )ain >olders >or t&e Developer progra)s >or 'racle (or)s .i are >ound under t&e )enu ite); O-,=le Fo-m( 7> and include t&e >ollowing ite)s; To run 'racle (or)s .i under Windows 95/9/!T/2"""4 clic0 on t&e S.,-. 4? P-o@-,m( 4? O-,=le Fo-m(7> 4? Fo-m B/>l+e- )enu ite). To run 'racle 6eports under Windows 95/9/!T/2"""4 clic0 on t&e S.,-. 4? P-o@-,m( 4? O-,=le Repo-.( 7> 4? Repo-. B/>l+e- )enu ite). To run 'racle 5rap&ics under Windows 95/9/!T/2"""4 clic0 on t&e S.,-. 4? P-o@-,m( 4? O-,=le Fo-m( A Repo-.( 7> 4? *-,pB>=( B/>l+e- )enu ite). (or older versions o> 'racle Developer t&e start )enu would )ig&t &ave ite)s suc& as; DeCelope- 2888 R2D1 or DeCelope- 2888 R2D8 and so on. !ote; In 2our organiEation4 Developer )a2 +e installed or con>igured slig&tl2 di>>erentl2. In particular4 t&e progra)s )a2 +e grouped under di>>erent )enus. Please contact 2our D/8 or s2ste)s ad)inistrator4 or re>er to an2 local docu)entation to learn &ow to run t&e Developer tools. (.2 )tartin* Developer tools under 2#I3 'racle also )a0es a version o> Developer .i t&at runs under #!I$. T&is version uses $= Windows wit& t&e *oti> $=Windows li+raries as a grap&ical user inter>ace. I> 2our version o> Developer is installed under #!I$4 use t&e >ollowing co))and lines to start t&e di>>erent tools; Developer Tool 2#I3 Command (or)s Developer .." >or $=Windows *oti> >."des) 5rap&ics Developer .." >or $=Windows *oti> g."des) Procedure /uilder .." >or $=Windows *oti> pl+ild.") 6eports Developer .." >or $=Windows *oti> rw+ld." #nder #!I$4 it )a2 +e necessar2 to set certain environ)ent varia+les suc& as TH."GI-'!4 #IGI-'!4 ('6*S."GP8TD and so on. #pon installation4 e:a)ple s&ell scripts to set t&ese environ)ent varia+les are installed in t&e 'racle Do)e director2. 4. The Oracle Forms Desi*ner "ain )creen 'nce t&e appropriate )enu ite) &as +een clic0ed on @>or Windows 95/9/!T/2"""A4 t&e 'racle (or)s /uilder Welco)e Screen will appear; (or)s .." displa2s t&is welco)e screen as a quic0 wa2 to start wor0ing and designing >or)s. (or t&is tutorial4 we will wor0 directl2 >ro) t&e '+,ect !avigator since t&is is t&is )ost general wa2 to wor0 wit& >or)s. To continue to t&e '+,ect !avigator >ro) t&e Welco)e screen4 clic0 on t&e -ancel +utton or select t&e I/uild a >or) *anuall2I option and clic0 'H. In eit&er case4 t&e '+,ect !avigator will appear. 4.1 Oracle Forms O$5ect #avi*ator 8>ter starting up 'racle (or)s4 t&e )ain screen will +e presented. T&is screen is called t&e Object Navigator and displa2s all o> t&e >or) ele)ents4 data +loc0s4 )enu ite)s4 user de>ined code li+raries4 +uilt in procedures and >unctions4 and data+ase o+,ects @ta+les4 viewsA. T&e displa2 is in t&e >or) o> a collapsi+le tree. In general4 clic0ing on a 6 will e:pand t&e current ite) to s&ow its details. -lic0ing on a 7 will collapse t&e current list details. T&e )enu +ar across t&e top provides access to al)ost all o> t&e >eatures o> 'racle (or)s. T&e F>le )enu &as options to create4 open4 save and print >or)s. T&is )enu also includes an option to connect to t&e data+ase and t&e 8d)inistration option t&at is used to co)pile >or)s and )enu code. T&e last option on t&e F>le )enu is t&e EE>. option t&at will e:it 'racle (or)s /uilder. T&e E+>. )enu &as options to cut4 cop2 and paste o+,ects4 to invo0e an editor and to undo an operation. T&e V>eF )enu toggles t&e o+,ect navigator displa2 +etween visual ele)ents and owners&ip ele)ents. T&e N,C>@,.o- )enu &as ite)s t&at control t&e displa2 o> t&e o+,ect navigator including e:panding and collapsing tree +ranc&es. T&e N,C>@,.o- )enu can also +e used to create and delete o+,ects using t&e C-e,.e and Dele.e )enu options respectivel2. T&e P-o@-,m )enu &as ite)s t&at control >or) co)pilation4 generation and e:ecution @6unA. Triggers4 Procedures and ot&er P1/S91 code can also +e created >ro) t&is )enu. T&e Sm,-. T->@@e-( )enu option displa2s t&e )ost co))onl2 used triggers according to t&e t2pe o> o+,ect currentl2 selected in t&e o+,ect navigator. T&e Tool( )enu &as options to switc& +etween several di>>erent screens including t&e 1a2out editor4 *enu editor and '+,ect !avigator. T&ere are also several wiEards t&at can +e launc&ed >ro) t&is )enu including t&e Data /loc0 wiEard4 t&e 1a2out wiEard4 t&e -&art wiEard and t&e 1'? @1ist o> ?aluesA wiEard. T&e ;>)+oF( )enu displa2s )enu ite)s >or eac& o> t&e windows 2ou &ave open. /2 de>ault4 onl2 one ite) = t&e '+,ect !avigator = is displa2ed. (inall24 t&e Help )enu can +e used to displa2 &elp topics. /2 de>ault4 a +utton +ar is provided on t&e le>t &and side o> t&e '+,ect !avigator window. 3ac& +utton duplicates so)e >unctionalit2 on t&e )enus. (or e:a)ple4 clic0ing on t&e top icon @an opened >olderA is t&e sa)e as pulling down t&e F>le )enu and c&oosing t&e Ope) option. To see w&at a +utton )ig&t do i> pressed4 place t&e )ouse cursor over t&e +utton and a s&ort )essage will appear descri+ing t&e +uttonFs >unction. In Developer .."4 a >or)4 report or grap&ic is generall2 re>erred to as a Module. W&en >irst starting t&e (or)s /uilder4 a de>ault )odule is created called; MODLE1 T&e content o> t&e '+,ect !avigator is +ro0en down into . )a,or sections; 1. Forms = -ontains >or) o+,ects and all o> t&eir su+=o+,ects suc& as data +loc0s4 triggers4 alerts4 canvases4 progra) units @procedures and >unctionsA4 para)eters and windows. *ore t&an one >or) can +e open at a ti)e. 2. Menus = -ontains )enu o+,ects and all o> t&eir su+=o+,ects suc& as )enu ite)s4 para)eters and progra) units. *ore t&an one )enu can +e open at a ti)e. 3. PL/SQL Libraries = T&ese are li+raries o> P1/S91 code @stored eit&er in t&e data+ase or in Dpl0 >ilesA. 1i+raries can +e s&ared a)ong di>>erent >or)s and a)ong di>>erent developers. %. Object Libraries = T&ese are li+raries containing a collection o> o+,ects @an2t&ing t&at can appear on a >or)A. 5. Built-in Packages = 1ists all o> t&e pac0ages @P1/S91 proceduresA availa+le +2 de>ault to all >or)s4 reports4 etc. .. Database Objects = 1ists all o> t&e data+ase o+,ects @Ta+les4 ?iews4 P1/S91 1i+raries4 and Stored Progra) #nitsA in t&e userFs 'racle data+ase sc&e)a. 8s o+,ects are created4 t&e2 are displa2ed under t&e appropriate section. -onte:t sensitive )enus can +e displa2ed >or eac& o+,ect +2 clic0ing on an o+,ect wit& t&e rig&t )ouse +utton. 4.2 Connectin* to the Data$ase T&e >irst step in wor0ing wit& an2 o> t&e Developer tools is to esta+lis& a connection to an 'racle data+ase. T&is is acco)plis&ed +2 pulling down t&e F>le )enu and selecting t&e Co))e=. )enu ite). (ill in 2our 'racle #serna)e and 'racle Password @press t&e ta+ 0e2 to )ove +etween t&e >ieldsA. (or t&e D,.,0,(e >ield4 t2pe in t&e service na)e >or 2our 'racle data+ase. (or e:a)ple4 i> 2ou are using Personal 'racle 1ite4 t&e D,.,0,(eG would +e ODBCGPOLITE. I> 2ou &ave a local data+ase running on t&e sa)e )ac&ine4 2ou )a2 +e a+le to connect directl2 to it +2 leaving t&is >ield +lan0. I> 2ou are wor0ing in a client/server environ)ent w&ere t&e 'ralce server resides on anot&er )ac&ine4 2ou will &ave to con>igure t&e 'racle !et )iddleware to esta+lis& a connection wit& t&at server. Bou would t&en suppl2 t&e !et service na)e in t&e Data+ase >ield. 8lternativel24 contact 2our s2ste) ad)inistrator to learn t&e service na)e >or 2our 'racle data+ase and provide t&at in>or)ation in t&e D,.,0,(eG >ield. -lic0 on t&e Co))e=. +utton to co)plete t&e connection @#nder so)e versions o> #!I$4 t&e +utton is la+eled O'A. I> t&e user na)e or password is )ist2ped or incorrect4 t&e dialog +o: will +e re=displa2ed. /e sure to provide 2our 'racle userna)e and password @not 2our #!I$ &ost or 1ocal 8rea !etwor0 passwordA. 3ac& ti)e an2 o> t&e Developer /uilder tools are e:ecuted4 t&e >irst step will +e to connect to an 'racle data+ase in t&is >as&ion. .. Forms Desi*n 8 t2pical data+ase sc&e)a contains doEens o> ta+les4 eac& wit& several colu)ns o> various data t2pes. We develop applications @>or)s4 reports4 )enus4 etc.A to )a0e t&e ,o+ o> )anipulating data in t&ose ta+les easier >or users. In 'racle (or)s4 a >or) @or data entr2 >or)A acts li0e a window into t&e data+ase sc&e)a. 8n individual >ocuses t&e attention o> t&e user to one or a >ew o> t&e ta+les at a ti)e. In addition4 a >or) can give pro)pts so t&e user 0nows w&at 0ind o> input is e:pected and &ow data is to +e entered and )anipulated. /2 de>ault4 ever2 >or) in 'racle (or)s &as t&e capa+ilit2 to quer2 e:isting data in a ta+le4 )odi>2 e:isting data and add new data @recordsA to t&e ta+le. 8 >or) is +uilt up using one or )ore data blocks t&at correspond to ta+les in t&e data+ase. (ields wit&in t&e data +loc0 correspond to colu)ns in t&e data+ase ta+le. 8 data +loc0 is si)ilar to a DataWindow o+,ect in Power/uilder. In t&e >ollowing >igure4 a t2pical >or) is s&own. T&is >or) &as two data +loc0s4 one >or t&e EMPLOYEE ta+le4 and one >or t&e DEPENDENT ta+le. T&ese data +loc0s are arranged in a Master/Detail setup w&ere a single 3)plo2ee record @t&e )asterA is associated wit& one or )ore Dependents records @t&e detailsA. /2 de>ault4 >or)s also gives a +utton +ar and a )enu. T&ese can +e used to scroll t&roug& t&e records in a +loc04 navigate +etween +loc0s4 set up and per>or) queries against t&e ta+les4 insert4 update and delete records4 clear t&e >or) and e:it t&e >or). (inall24 at t&e +otto) o> eac& >or) is a status +ar t&at displa2s an2 relevant pro)pts or error )essages and an indication o> t&e records in t&e current data +loc0. T&ere are >our )ain t2pes o> >or)s t&at can +e designed. Single /loc0 (or). T&is >or) contains a single data +loc0 corresponding to a single data+ase ta+le. Single +loc0 (or) wit& loo0up >ield. T&is >or) contains a single data +loc0 corresponding to a single data+ase ta+le wit& t&e addition o> one or )ore >ields t&at displa2 data >ro) so)e ot&er ta+les. Suc& data is Iloo0ed upI w&en t&e >or) runs. *aster/Detail (or). T&is >or) contains two data +loc0s t&at are arranged in a )aster/detail @one to )an2A relations&ip. *aster/Detail (or) wit& loo0up >ields. T&is >or) is si)ilar to t&e *aster/Detail +ut &as t&e additional loo0up >ields in t&e )aster and/or detail +loc0s. T&ere are additional variations suc& as a *aster/Detail/Detail >or) wit& 3 +loc0s and so on. Dowever4 t&e >our t2pes illustrated a+ove are t&e )ost co))on ones. In t&is tutorial4 all >our t2pes will +e de)onstrated. 8. Creatin* and Runnin* a Form ,ith a )in*le 9loc: In t&is section4 t&e +asic steps >or creating a +asic data entr2 and quer2 >or) >or a single data+ase ta+le will +e covered. In general4 a Data Block on a ;orm corresponds to a ta$le in the data$ase. This is called the Base Table ;or the data $loc:. For each ta$le displa%ed on the ;orm, a ne, data $loc: ,ill $e created. For this e<ample, onl% one data $loc: ,ill $e created ;or the EMPLOYEE ta$le. 8 +loc0 appears on a Canvas w&ic& is contained in a Window. T&ere are )an2 options to control )ultiple canvas views and )ultiple windows per >or). In t&ese e:a)ples4 we concentrate on a si)ple arrange)ent using a single canvas and a single window. T&ere are a nu)+er o> wa2s to create a data +loc0. 'ne wa2 is to )anuall2 de>ine t&e +ase ta+le and colu)ns4 and t&eir positions on t&e >or). W&ile t&is is possi+le4 it can +e ver2 tedious. 'racle (or)s .." provides two wiEards @progra)s t&at guide t&e developer in per>or)ing co))on tas0sA to create data +loc0s; 1. The Data Block wizard *uides the developer throu*h the steps o; choosin* a $ase ta$le and columns. 2. The Layout wizard *uides the developer throu*h arran*in* the $ase ta$le and columns on the ;orm. 8.1 Creatin* a #e, 9loc: To create a new +loc04 pull down t&e Tool( )enu and select t&e D,., Blo=% F>H,-+ )enu ite). T&e >ollowing dialog +o: will appear; -lic0 on t&e !e:t +utton. T&e >ollowing dialog +o: will appear; T&ere are two t2pes o> data +loc0s t&at can +e created. Ta$le/=ie, and Procedures. (or t&is e:a)ple4 c&oose Ta+le/?iew and clic0 on t&e !e:t +utton. T&e ne:t step is to c&oose a +ase ta+le and colu)ns t&at will +elong to t&e data +loc0. T&e >ollowing dialog +o: s&ould appear; To associate a data+ase ta+le wit& t&e +loc04 clic0 on t&e B-oF(eDDD +utton to t&e rig&t o> t&e Ta+le or ?iew >ield. T&e >ollowing dialog +o: will pop up. *a0e sure t&e C/--e). (e- and T,0le( +uttons are selected 8 list o> 2our ta+les will appear. Dig&lig&t t&e na)e o> t&e data+ase ta+le @3*P1'B33 in t&is e:a)pleA and clic0 on t&e O' +utton. T&e wiEard s&ould reappear wit& t&e na)e o> t&e ta+le and a list o> availa+le colu)ns displa2ed. To include a colu)n in t&e data +loc04 &ig&lig&t t&e colu)n na)e and clic0 on t&e rig&t arrow. T&e na)e o> t&e colu)n s&ould )ove over to t&e rig&t &and side. (or t&is e:a)ple4 select t&e (!8*34 1!8*34 SS!4 /D8T34 S8186B and D!' as in t&e >ollowing >igure; -lic0 on t&e !e:t +utton4 and t&e >inal dialog +o: >or t&e Data /loc0 wiEard will appear; In t&is e:a)ple4 we want to continue on to t&e &a%out ,i>ard in order to speci;% ho, the ne, ;orm ,ill appear. "a:e sure the Create te block! ten call te La"out #i$ar% option is selected and clic: on the Finish $utton. T&e data +loc0 will +e created @as can +e seen in t&e '+,ect !avigator in t&e +ac0groundA. T&e o+,ects created include t&e 3*P1'B33 data +loc0 containing ite)s >or eac& o> t&e colu)ns t&at were selected in t&e t&ird step o> t&e wiEard. Once the ne, data $loc: and items are created, the ;irst dialo* $o< in the &a%out ,i>ard ,ill appear? -lic0 on t&e !e:t +utton and t&e >ollowing dialog +o: will appear; T&e la2out >or a data +loc0 )a2 +e placed on an2 e:isting canvas. In t&is case4 t&ere are no canvases so t&e onl2 option availa+le is to create a new canvas. -lic0 on t&e !e:t +utton to displa2 t&e >ollowing dialog +o:; In t&is dialog +o:4 the columns ;rom a *iven $ase ta$le on a data $loc: can $e added to the la%out. )ince ,e are la%in* out the !"P&O'!! data $loc:, it is hi*hli*hted automaticall%. "ove all o; the Availa$le Columns over to the Displa%ed Items side $% clic:in* on the dou$le ri*ht arro, and clic: on the #e<t $utton. In this dialo* $o<, the ;ield la$els, ;ield si>es and ;ield hei*hts can $e altered. Chan*e the ;ield la$els as $elo, and clic: on the #e<t $utton? T&e >ollowing dialog +o: will appear; T&ere are two )ain st2les >or >or)s. 8 Ta+ular la2out arranges t&e >ield la+els across t&e top o> t&e >or) wit& a nu)+er o> records +elow as in a spreads&eet. 8 Form la2out places t&e >ield la+els to t&e le>t o> t&e >ields. 5enerall2 onl2 one record is displa2ed at a ti)e. (or t&is e:a)ple4 c&oose a (or) la2out and clic0 on t&e !e:t +utton. In t&e >ollowing dialog +o:4 t%pe a title >or t&e >ra)e @around t&e data +loc0A and c&ec0 t&e option to include a scroll +ar. #OT!)? The num$er o; records displa%ed ;or a Form la%out should $e 1. The num$er o; records displa%ed in a Tabular la%out can $e more than 1. -lic0 on t&e !e:t +utton and t&e >inal dialog +o: >or t&e 1a2out wiEard will appear. Clic: on the Finish $utton to create the la%out. A ne, Canvas ,ill $e created. 8t t&is point t&e 1a2out 3ditor s&ould appear and t&e new >or) wit& t&e data +loc0 will appear. 8.2 The &a%out !ditor To vie, the actual ;orm and its $loc:s and ;ields, pull do,n the &ools menu and select the La"out E%itor "enu item @i; it not alread% displa%edA. In t&e 1a2out 3ditor4 >ields and la+els can +e )oved around +2 clic0ing and dragging. 't&er te:t4 lines and +o:es4 etc. can +e added using t&e tool palette on t&e le>t side o> t&e window. So)e co))on operations on t&e 1a2out 3ditor include; *ove a >ield or a >ield la+el +2 clic0ing and dragging t&e ite) wit& t&e le>t )ouse +utton. -&ange t&e te:t o> a la+el +2 c&oosing t&e te:t tool +utton >ro) t&e tool +ar and t&en clic0ing on a la+el. To stop editing t&e la+el4 clic0 an2w&ere outside o> t&e la+el te:t. 8dd te:t to t&e +loc0 +2 c&oosing t&e te:t tool +utton >ro) t&e tool +ar and t&en clic0ing on a open area. T2pe t&e new te:t. To c&ange t&e >ont4 &ig&lig&t t&e te:t4 pull down t&e Fo-m,. )enu and clic0 on t&e Fo). )enu ite). To c&ange t&e te:t color o> a la+el4 use t&e pointer tool to &ig&lig&t a la+el and t&en clic0 on t&e TeE. Colo- palette +utton to c&oose t&e color. -&ange t&e widt& o> a >ield +2 clic0ing on t&e >ield. T&en drag one o> t&e &andles @s)all +lac0 +o:es around t&e >ieldA to re=siEe t&e >ield. (or e:a)pe4 on t&e e)plo2ee >or)4 2ou )a2 wis& to )a0e t&e S3$ >ield wider to acco)odate t&e capital letter F*F. #se t&e Joo) In tool to Eoo) in to t&e >or) @e.g.4 )a0e ever2t&ing appear largerA. 'r use t&e Joo) 'ut tool to Eoo) out o> t&e >or). 8.( Displa%in* Properties W&ile in t&e 1a2out 3ditor4 dou+le clic0ing on an o+,ect will +ring up t&at o+,ectFs roerties. 'ptionall24 clic0ing on an o+,ect wit& t&e rig&t )ouse +utton will +ring up a s)all )enu w&ic& &as t&e Properties )enu ite) on it. T&e >ollowing >igure s&ows t&e properties >or t&e FNAME ite). 3ac& t2pe o> o+,ect &as a slig&tl2 di>>erent set o> properties. (or e:a)ple4 dou+le clic0ing on t&e 3*P1'B33 data +loc0 in t&e '+,ect !avigator will displa2 t&at data +loc0Fs properties. I"PORTA#T #OT! ? So)e properties o> interest >or a data +loc0 include; +B!R! Clause = speci>2 a WD363 clause to >ilter t&e selection o> rows >ro) t&e +ase ta+le. ORD!R 9' Clause = speci>2 an '6D36 /B clause to alter t&e displa2ed order o> t&e records. Delete Allo,ed, Insert Allo,ed, Cuer% Allo,ed and 2pdate Allo,ed = toggle t&ese properties to allow or prevent t&e action. (or e:a)ple4 setting Delete Allo,ed to FALSE prevents users >ro) deleting records >ro) t&e corresponding +ase ta+le using t&is >or). T&ere are nu)erous ot&er properties t&at a>>ect t&e >onts4 colors4 siEe and position o> o+,ects in t&e +loc0. 8.4 )avin*, Compilin* and Runnin* Forms (or)s can +e saved in >iles in a director2 o> 2our c&oosing. The Dsource codeD ;or a ;orm is stored in a ;ile ,ith a '(mb e<tension. Compiled ;orms have a '(m) e<tension. #nder *S Windows 95/9/!T/2"""4 >or)s can +e saved in a >older @su+director2A on t&e local &ard dis04 on a >ile server or on a >lopp2 dis0. It is desira+le to )aintain separate su+directories @>oldersA >or >or)s associated wit& di>>erent pro,ects. 8.4.1 )avin* a Form To save a >or)4 pull down t&e F>le )enu and select t&e S,Ce )enu ite). #nder *S Windows 95/9/!T/2"""4 t&is dialog +o: loo0s li0e; !ote t&at in 2our co)pan2 or organiEation4 >or)s and ot&er >iles )a2 &ave to +e saved on >lopp2 dis0 or in a special director2. T&e a+ove >igure is si)pl2 an e:a)ple. (ill in a >ile na)e in t&e F>le N,meG >ield. /e sure it ends wit& D1m0 -lic0 on t&e S,Ce +utton to save t&e >ile. (or t&is e:a)ple4 use t&e >ile na)e employeeD1m0 To save t&is >or) on a >lopp2 dis0 in t&e AG drive4 use t&e >ile na)e; AGIemployeeD1m0 To en&ance porta+ilit2 o> >or)s across di>>erent operating s2ste)s4 use >ile na)es t&at +egin wit& a letter4 contain no spaces or punctuation @e:cept >or t&e underscore c&aracterA4 &ave all lower case letters and are relativel2 s&ort. I> 2ou are wor0ing on a >or) and wis& to save it under a different >ile na)e4 >ollow t&e sa)e steps as a+ove4 onl2 select t&e S,Ce A( )enu ite) in place o> t&e S,Ce )enu ite). (or e:a)ple4 i> 2ou &ave >inis&ed wor0ing on t&e 3)plo2ee >or) and wis& to save o>> a cop2 +e>ore adding so)e code or progra))ing so)e progra) units4 t&e S,Ce A( )enu ite) can +e used to save o>> a cop2 +e>ore proceeding. 8.4.2 Compilin*/9uildin* a Form /e>ore a >or) can +e e:ecuted @runA4 it )ust +e Comiled and !uilt. -o)piling runs a P1/S91 co)piler on all o> t&e procedures and triggers in t&e >or). 9uildin* @or compilin* the ;ileA creates the '(m) ;ile that is then used to run the ;orm. To compile a ;orm, ;irst ma:e sure the ;orm is saved. Pull do,n the Program menu and select the Com*ile menu item. Then choose +ll in the ;l%out menu. I; a ;orm has errors @e.g.4 in t&e P1/S91 code4 or i> t&e data+ase sc&e)a c&angesA t&e2 will +e displa2ed in a window as t&e2 are encountered. 8 record o> t&e co)pilation process4 including error messa*es4 is 0ept in a >ile wit& a 'err e:tension. (or e:a)ple4 i> t&e >or) is na)ed employee t&en t&e record o> t&e co)pilation will +e stored in em*lo"ee'err To Build the '(m) ;ile ;or a ;orm, pull do,n the File menu, clic: on the +%ministration menu item and then choose Com*ile File ;rom the ;l%7out menu. I; the ;orms *eneration is success;ul, the phrase Module built successfully ,ill appear on the status $ar at the $ottom o; the screen. 8lternativel24 'racle (or)s de>aults to auto)aticall2 +uilding t&e >or) eac& ti)e it is e:ecuted @runA >ro) t&e >or)s designer as will +e de)onstrated in t&e ne:t step. For more details on the de;ault $ehavior, pull do,n the &ools menu and chec: the Pre(erences menu item. 8.4.( Runnin* a Form 8>ter a >or) &as +een saved and +uilt4 it can +e e:ecuted. To run the ;orm, pull do,n the Program menu and select the ,un Form -- Client/Ser.er menu item. The ;orm ,ill displa% in a ne, ,indo,. The Oracle Run;orm pro*ram is e<ecuted $% passin* in the name o; the ;orm @em*lo"ee'(m) in this caseA as a parameter. #se t&e various )enus and ite)s to quer2 t&e >or)4 enter new data and save new and c&anged data. Please read t&e section +elow on 9uer2 /2 3:a)ple to see &ow to quer2 data >ro) t&e underl2ing ta+les and populate t&e >ields in t&e >or). 8.4.4 Runnin* a Form as a Eava Application or Applet I> 2ou &ave also installed t&e (or)s Server @Windows !T/2""" onl2A 2ou )a2 also run t&e >or) in IWe+I )ode +2 selecting t&e Progra) )enu and t&en IWe+I. In 'racle Forms 8 and 8i, the '(m) ;ile is loaded and e<ecuted in a Eava Application. In t&is )ode t&e (or)s server &andles t&e processing o> t&e +usiness logic and interacts wit& t&e user inter>ace ele)ents t&at run in t&e 7ava 8pplication. 8n e:a)ple o> a si)ple 3)plo2ee data entr2 >or) running in a 7ava 8pplication is s&own +elow; 8not&er option >or running 'racle >or)s is to run t&e) wit&in a we+ +rowser as a 7ava 8pplet. T&e +asic steps >or t&is involve setting up a we+ server @suc& as 'racle 8pplication Server or 'racle We+D/A to serve t&e D1mE >ile and a series o> 7ava application class >iles to t&e we+ +rowser client. 'racle provides t&eir own 7ava runti)e environ)ent @763A called t&e 7=Initiator t&at )ust +e installed on eac& client. 7=Initiator &oo0s into t&e clientFs we+ +rowser using a special *I*3 data t2pe t&at launc&es 'racle 763 w&en an 'racle >or) is loaded into t&e +rowser. /elow is an e:a)ple o> t&e sa)e data entr2 >or) running as a 7ava 8pplet inside o> t&e !etscape !avigator we+ +roswer. (or)s .i provides a si)ple test we+ page located under t&e 'racle (or)s .i progra) group called DRun a Form on the +e$D. 'ne can )a0e use o> t&at to test i> t&e (or)s server4 load +alancer4 and we+ server on t&e )iddle tier are running correctl2. Please note t&at getting 'racle (or)s and 6eports to run in t&is >as&ion is not a trivial underta0ing. It requires e:tensive 0nowledge o> we+ servers4 Windows !T/2""" services and t&e wa2 in w&ic& t&e >or)s applications are processed across t&e three tier architecture. T&e a+ove discussion is )eant as a +asic introduction to t&e 7ava 8pplication and 8pplet >eatures o> 'racle (or)s. It is +e2ond t&e scope o> t&is tutorial to present t&e details >or con>iguring servers and services to provide t&is capa+ilit2. Please re>er to t&e on=line docu)entation t&at co)es wit& ('r)s .i >or )ore detailed descriptions and con>iguration instructions. 8.4.4 Cuer% 9% !<ample W&en a Developer (or) is >irst e:ecuted4 no records will appear. T&at is4 t&e +lan0 >or) will appear wit& no data in t&e >ields. T&is is si)ilar to running a word processor w&ere t&e opening screen is +lan0. (ro) t&is +lan0 or e)pt2 >or)4 t&e user can i))ediatel2 +egin to enter new data records +2 si)pl2 t2ping t&e) in. Dowever4 in )a2 cases4 t&e user would >irst li0e to see i> t&ere are an2 records in t&e data+ase. To do t&is4 t&e user )ust "uery t&e data+ase using t&e quer2 capa+ilities t&at are +uilt into ever2 'racle >or). T&is will +ring a cop2 o> t&e records >ro) t&e data+ase into t&e >or). W&en a tool suc& as S91CPlus is used4 t&e user )ust >or) t&e S91 quer2 +2 t2ping it directl2 in. In t&e case o> e)+edded S914 t&e S91 state)ents are progra))ed into t&e &ost language @suc& as I-I or 7avaA and auto)aticall2 e:ecuted >or t&e user. In t&e case o> 'racle (or)s4 co)ple: queries can +e >or)ulated and su+)itted to t&e data+ase using a tec&nique called Cuer% 9% !<ample or C9!. In 9/34 t&e na)e o> t&e ta+le or ta+les is >i:ed as are t&e na)es o> t&e colu)ns t&at will +e returned >ro) t&e ta+les. T&e user can suppl2 t&eir own criteria +2 suppl2ing values >or t&e >ields. T&ese values +eco)e part o> t&e quer2 t&at is su+)itted to t&e data+ase on +e&al> o> t&e user. 9uer2ing a >or) in 'racle (or)s is a two step process. -lic0ing on t&e 9uer2 +utton or c&oosing E).e- :/e-y >ro) t&e :/e-y )enu places t&e >or) in #nter $uery )ode. In enter quer2 )ode4 t&e >or) is cleared and t&e user can navigate in t&e various >ields. 3:a)ple values can +e supplied as criteria >or t&e quer2. (or e:a)ple4 a user loo0ing >or all e)plo2ees in t&e 63S386-D depart)ent )ig&t t2pe a I5I in t&e D!' >ield w&ile in enter quer2 )ode. -lic0ing on t&e 9uer2 +utton a second ti)e e:ecutes t&e current quer2 using an2 supplied data as criteria in a WD363 clause. I> no criteria are supplied4 t&en all records in t&e ta+le will +e displa2ed. -ontinuing t&e a+ove e:a)ple4 suppl2ing a I5I >or t&e D!' >ield w&ile in enter quer2 )ode would cause t&e >ollowing S91 quer2 to +e su+)itted to t&e data+ase; SELECT 1),me, l),me, ((), 0+,.e, (,l,-y, +)o FROM employee ;HERE +)o J 5$ *ost o> t&e co))ands on t&e )enus and on t&e +utton +ar can also +e activated using special 0e2 co)+inations or >unction 0e2s. (or e:a)ple4 under *S Windows 95/9/!T/2"""4 pressin* the F/ ;unction :e% places the ;orm in !nter Cuer% mode. Pressin* the F0 ;unction :e% e<ecutes a uer%. To see a list o; :e%s and their ;unctions, pull do,n the 1el* menu and choose the 2e"s option. Once data has $een ueried, it is retrieved ;rom the data$ase and stored in a $u;;er in the associated data $loc: on the ;orm. This means that a local cop% o; the data no, e<ists in the clientFs memor%. Appropriate loc:s are placed on the data so that the client maintains a consistent vie, o; the data in the associated ta$les. T&e user can navigate t&roug& t&e data in a +loc0 +2 pressing t&e up and down arrow 0e2s to scroll +etween records. To c&ange data in a >or)4 t&e user can T8/ to t&e >ield o> interest4 and t2pe over t&e e:isting data. To enter new data into t&e >or)4 t&e user can scroll to t&e last record and t&en down once )ore to )ove to a +lan0 record. Data can t&en +e t2ped into t&e >ields and t&e T8/ 0e2 can +e pressed to )ove +etween >ields on t&e >or). To save $oth chan*ed and ne, records on a ;orm, pull do,n the +ction menu and choose the Sa.e menu item. 8n2 records t&at &ave +een c&anged are collected and su+)itted to t&e data+ase as )C& 2PDAT! statements. 8n2 new records are collected and su+)itted to t&e data+ase as I#)!RT statements. T&ese state)ents are su+)itted as a single logical unit o> wor0. T&us i> a >ailure occurs during an2 o> t&e state)ents4 t&e entire transaction will +e rolled $ac:. I> t&e user atte)pts to clear t&e +loc0 or e:it t&e >or) and t&ere are so)e c&anges t&at &ave not 2et +een applied to t&e data+ase4 t&e2 will +e pro)pted to co))it t&e c&anges +e>ore e:iting or clearing t&e >or). T&e +loc0 is cleared w&en t&e 3nter 9uer2 )ode is invo0ed. A $loc: can also $e cleared usin* the Clear Block and Clear Form menu items. To e:it >ro) a running >or)4 pull down t&e A=.>o) )enu and select t&e EE>. )enu ite). 8s a review4 &ere are a >ew +asic >unctions t&at can +e per>or)ed +2 de>ault in an2 (or); Forms ;unction #otes 9uer2ing a >or) To see all records in t&e ta+le4 si)pl2 I3:ecute 9uer2I @via 9uer2 )enu or +2 pressing ( in WindowsA. To >ilter t&e record4 Ienter quer2I )ode4 speci>2 t&e quer2 para)eters in t&e >ields and t&en I3:ecute 9uer2I. Inserting new records Scroll to t&e last record and t&en scroll once )ore to get a +lan0 record. T2pe in data >or eac& >ield and t&en co))it t&ese c&anges +2 pulling down t&e A=.>o) )enu and c&oose t&e S,Ce )enu ite). (or )aster/detail >or)s @discussed +elowA >irst eit&er quer2 a )aster record or insert and save a )aster record @in t&e )aster data +loc0A4 t&en navigate to t&e detail +loc0 and insert new records t&ere. #pdating 9uer2 t&e data+ase and scroll to t&e record o> interest. -&ange t&e values in e:isting records t&e >ields and t&en save t&e c&anges. (or )aster/detail >or)s4 c&anges to t&e 0e2 in t&e )aster +loc0 )a2 +e prevented i> detail records e:ist @t&us insuring relational integrit2A. Deleting records 9uer2 t&e data+ase and scroll to t&e record o> interest. Pull down t&e 6ecords )enu and c&oose Delete record. T&en save t&e c&anges. (or )aster/detail >or)s4 atte)pting to delete a )aster record w&en detail records e:ist t2picall2 results in an error. In suc& cases4 all o> t&e detail records s&ould +e deleted >irst and t&en t&e )aster record s&ould +e a+le to +e deleted. 8.. !<ercise? Creatin* a a )in*le 9loc: Form (or t&is e:ercise4 create a si)ple data entr2 >or) >or t&e D3P86T*3!T ta+le wit& t&e >ollowing c&aracteristics; Select and displa2 all o> t&e colu)ns in t&e D3P86T*3!T ta+le. In t&e la2out wiEard4 use t&e Ta+ular la2out and displa2 5 6ecords in t&e >or). 8dd a scroll+ar. In t&e 1a2out 3ditor4 )a0e t&e D!8*3 >ield a +it wider to acco))odate longer depart)ent na)es. -&ange t&e Properties o> t&e D3P86T*3!T +loc0 so t&at t&at data is '6D36 /B D!#*/36. Save t&e >or) under t&e >ile na)e; +ep,-.D1m0 T&e resulting >or) s&ould loo0 li0e t&e >ollowing; #se t&e enter quer2 )ode and e:ecute quer2 >unctions to quer2 t&e depart)ent ta+le >or a speci>ic depart)ent na)e and/or nu)+er. G. Creatin* a "aster7Detail Form In t&is section4 t&e +asic steps >or creating a *aster/Detail >or) are introduced. 8 *aster/Detail >or) is a >or) t&at &as two +loc0s arranged in a )aster=detail relations&ip. G.1 The "aster7Detail Relationship T&e *aster=Detail relations&ip is a co))on relations&ip +etween entities in a +usiness. In an 3ntit2=6elations&ip diagra)4 t&ese are s&own as DOne to "an%D relationships. In a p&2sical data+ase design4 a single Master record re>erences one or )ore detail records in anot&er ta+le. 8 record in t&e detail ta+le will relate to e:actl2 one )aster record in t&e )aster ta+le. 8not&er na)e >or t&is relations&ip is called parent7child. 3:a)ples o> t&is relations&ip include; 8 -usto)er 'rder wit& )an2 'rderIte)s. 8 Depart)ent wit& )an2 3)plo2ees. 8n 3)plo2ee wit& )an2 Dependents. 8 -o)pan2 wit& )an2 /ranc& '>>ices. 8 6ecipe wit& )an2 6ecipeSteps. 8n Inventor2 location wit& )an2 Inventor2 Ite)s. 'racle (or)s i)ple)ents t&e )aster=detail relations&ip using two data +loc0s. T&e >irst +loc0 corresponds to t&e )aster ta+le and t&e second +loc0 corresponds to t&e detail ta+le. T&ere are two )a,or >unctions in a *aster=Detail >or); Oracle Forms coordinates values $et,een the t,o $loc:s throu*h a series o; ;orm and $loc: level triggers. Oracle Forms *uarantees that the detail $loc: ,ill displa% onl% records that are associated ,ith the current record in the master $loc:. !ote t&at a *aster=Detail >or) is si)pl2 one wa2 o> viewing t&e data in two related ta+les. (or)s do not a>>ect t&e sc&e)a in ter)s o> creating4 dropping or en>orcing data+ase level re>erential integrit2 constraints. G.2 )teps to Create a "aster7Detail Form In t&is section4 a set o> step +2 step instructions >or creating a *aster=detail >or) are given. T&e >or) will allow a user to quer2 a given depart)ent in t&e co)pan2 and t&en will displa2 all o> t&e e)plo2ees in t&at co)pan2. T&e sc&e)a used is t&e sa)e one suggested in t&e Prerequisites section at t&e +eginning o> t&is tutorial. !otice t&at t&e D!' colu)n in t&e EMPLOYEE ta+le gets its values >ro) t&e D!#*/36 colu)n in t&e DEPARTMENT ta+le. In ot&er words4 to ,oin t&e two ta+les in a quer24 one )ig&t speci>2 a WD363 clause suc& t&at; EMPLOYEEDDNO J DEPARTMENTDDNMBER. G.2.1 Create the "aster 9loc: In t&e '+,ect !avigator4 clic0 on t&e Fo-m( +ranc& at t&e ver2 top. -reate a new >or) +2 pulling down t&e F>le )enu and c&oosing t&e NeF )enu ite). T&en c&oose Fo-m >ro) t&e >l2out )enu. #sing t&e sa)e steps given in t&e prior section on -reating a (or) wit& a Single /loc04 create a new +loc0 na)ed DEPARTMENT t&at contains all o> t&e colu)ns in t&e DEPARTMENT ta+le. /rie>l2; 1. Pull down t&e Tool( )enu and c&oose t&e Data /loc0 wiEard. 2. -reate a data +loc0 >or a ta+le/view. 3. Speci>2 t&e D3P86T*3!T ta+le and select all o> t&e colu)ns @D!8*34 D!#*/364 *56SS! and *56S86TD8T3A. %. -reate t&e data +loc0 and t&en go on to t&e 1a2out wiEard. 5. 8ppl2 t&e Depart)ent data +loc0 to a new canvas. .. 8dd all o> t&e colu)ns as Displa2ed Ite)s. <. -&ange t&e la+els to; Dept. !a)e Dept. !u)+er *gr. Ssn *gr. Start Date . -&oose a Form la2out. 9. Speci>2 a >ra)e title o> IDepart)entsI and select onl2 1 record to +e displa2ed. 1". Save t&e >or) as +ep.empD1m0 and t&en co)pile and run it to )a0e sure it is wor0ing properl2. 11. #se t&e 9/3 >eatures to retrieve onl2 t&ose depart)ents wit& D!#*/36 greater t&an 2. T&en4 do anot&er 9/3 quer2 to retrieve onl2 t&ose depart)ents wit& t&e letter H in t&eir na)e @tr2 KHKA. 8>ter t&is >irst step4 t&e +ep.emp >or) s&ould loo0 li0e t&e >ollowing; G.2.2 Create the Detail 9loc: !ow t&at we &ave t&e )aster +loc0 D3P86T*3!T created4 we can now create t&e detail +loc0 3*P1'B33 and associate it wit& t&e )aster +loc0. Per>or) t&e >ollowing steps; 1. 6eturn to t&e '+,ect !avigator @pull down t&e Tool( )enu and c&oose O0Le=. N,C>@,.o-A. 2. In t&e '+,ect !avigator4 clic0 on t&e Data /loc0s +ranc& o> t&e D3PT3*P >or) @do not clic0 on t&e depart)ent data +loc04 &oweverA. 3. Pull down t&e Tools )enu and c&oose t&e Data /loc0 wiEard. Note% I> t&e D3P86T*3!T data +loc0 @or an2 o> its ite)sA is still selected4 activating t&e Data /loc0 wiEard will cause t&e e:isting +loc0 to +e edited instead o> creating a new +loc0 @w&ic& is w&at is required in t&is part o> t&e tutorialA. %. Select t&e 3*P1'B33 ta+le and include t&e (!8*34 1!8*34 SS!4 /D8T34 S8186B and D!' colu)ns. 5. /ecause at least one data +loc0 alread2 e:ists in t&e >or)4 t&e ne:t step in t&e wiEard will +e to create a relations&ip +etween t&e e:isting data +loc0 @D3P86T*3!T in t&is caseA and t&e new +loc0 +eing created. T&e wiEard can construct t&e relations&ip +ased on ta+le level constraints it learns >ro) t&e data+ase sc&e)a. (or e:a)ple4 in t&e -638T3 T8/13 and 81T36 T8/13 state)ents given at t&e start o> t&is tutorial4 >oreign 0e2 constraints were speci>ied +etween D3P86T*3!T and 3*P1'B334 and +etween 3*P1'B33 and D3P3!D3!T. Dowever4 suc& relations&ips are not alwa2s i)ple)ented in ta+le level constraints. T&e developer can also speci>2 t&e relations&ip )anuall2. In t&is case4 t&e relations&ip will +e speci>ied )anuall2. De=select t&e A/.o4Lo>) +,., 0lo=%( option. -lic0 on t&e C-e,.e Rel,.>o)(B>p +utton to list t&e availa+le data +loc0s. In t&e ne:t dialog +o: 6elation T2pe4 c&oose B,(e+ o) , Lo>) =o)+>.>o) and clic0 t&e O' +utton. W&en t&e list o> +loc0s appears4 c&oose t&e D3P86T*3!T data +loc0. 8rrange t&e Detail Ite) @DNOA and *aster Ite) @DNMBERA suc& as t&at t&e ,oin condition +eco)es; EMPLOYEEDDNO J DEPARTMENTDDNMBER .. -reate t&e data +loc0 and t&en call t&e 1a2out wiEard. <. /e sure to c&oose t&e e:isting canvas @-8!?8S2 in t&is e:a)pleA and include all o> t&e ite)s e&cet t'e DNO as displa2ed. T&e D!' colu)n @ite)A will still +e a part o> t&e 3*P1'B33 data +loc04 &owever4 it will not +e displa2ed to t&e user. . Touc& up t&e la+els >or t&e >ields and c&oose t&e (abular la2out. 9. 5ive t&e (ra)e Title as I3)plo2eesI and select 5 6ecords displa2ed wit& " distance +etween records. 1". Save t&e >or) @it s&ould alread2 &ave t&e na)e +ep.empD1m0A and t&en co)pile and run it. !ote t&at a>ter co)pilation4 an2 errors encountered will +e displa2ed. T&e >ollowing >igure s&ows t&e )aster=detail >or) running; !otice t&at +2 scrolling t&e )aster +loc0 D3P86T*3!T to a new depart)ent nu)+er @using t&e up and down arrow 0e2sA4 t&e e)plo2ees >or t&at depart)ent are auto)aticall2 queried and displa2ed. To navigate +etween t&e *aster and Detail +loc0s4 use; To *o to the ne<t $loc:? Press C&,L-PageDo#n or pull do,n the Block menu and choose 3e)t To *o to the previous $loc:? Press C&,L-Page4* or pull do,n the Block menu and choose Pre.ious G.( Relation Properties o; a "aster7Detail Form T&ere are a nu)+er o> properties in a )aster=detail >or) t&at can +e c&anged to suit particular +e&avior o> t&e >or). In t&e >igure +elow4 t&e '+,ect !avigator &as several new o+,ects on it including )elations. To view t&e properties >or t&e D3P86T*3!TG3*P1'B33 relation4 open up t&e D3P86T*3!T +loc0 and t&en open t&e 6elations +loc0 +2 clic0ing on t&e M s2)+ols. T&en clic0 on t&e D3P86T*3!TG3*P1'B33 relation wit& t&e rig&t )ouse +utton and select Properties. T&ere are several interesting properties in t&e relations propert2 s&eet; #ame = T&e na)e o> t&e 6elation. T&is is t2picall2 )ade up o> t&e na)es o> t&e +loc0s. Relation T%pe = T&e t2pe o> t&e relation; Eoin or Re;. 8 7oin relation uses t&e t2pical S91 ,oin @in t&e W&ere clauseA to +ring t&e two ta+les @data +loc0sA toget&er. T&e )ef relation t2pe is used >or a+stract data t2pes and o+,ect re>erences. Detail Data 9loc: = T&e na)e o> t&e detail data +loc0 speci>ied w&en t&e detail data +loc0 was created. Eoin Condition = T&is is t&e ,oin condition in e>>ect >or queries to t&e data+ase. T&is was speci>ied w&en t&e detail data +loc0 was created. Delete Record 9ehavior = #sed to speci>2 &ow t&e deletion o> a record in t&e )aster +loc0 a>>ects records in t&e detail +loc0. It supports t&e >ollowing settings; o !on=isolated; Prevents t&e deletion o> a )aster record i> associated detail records e:ist in t&e data+ase. o Isolated; Deleting t&e )aster record will not a>>ect t&e associated detail records in t&e data+ase. o -ascading; Deletes t&e )aster record and auto)aticall2 deletes an2 associated detail records. Coordination 7 De;erred = Indicates w&en detail records s&ould +e queried w&en a )aster record is queried. o Bes; (or) does not quer2 t&e detail records until t&e user navigates to t&e detail +loc0. o !o; Detail records are >etc&ed i))ediatel2 w&en a user queries t&e )aster record. De>erred is so)eti)es set to Bes in cases w&ere t&ere are a lot o> detail records >or eac& )aster record. In suc& cases4 a lot o> data )ust +e queried and delivered to t&e client eac& ti)e a new record is displa2ed in t&e )aster +loc0. W&en De>erred is set to Bes4 t&e user can scroll down to t&e )aster record o> interest and t&en navigate to t&e detail +loc0 @-T61=PageDownA to quer2 t&e related detail records. Coordination 7 Auto7uer% = 8pplied to de>erred queries onl2 o Bes; t&e quer2 is auto)aticall2 e:ecuted w&en t&e user navigates to t&e detail +loc0. o !o; t&e quer2 )ust +e e:ecuted )anuall2 +2 t&e user a>ter t&e2 navigate to t&e detail +loc0. Prevent "asterless operation = Speci>ies w&et&er users are allowed to quer2 or insert records in a detail +loc0 w&en no )aster record is in place. o Bes; #sers )a2 not quer2 or insert w&en no )aster record is in place. o !o; #sers )a2 quer2 or insert w&en no )aster record is in place. T&ese settings are used to ItuneI t&e overall per>or)ance o> a )aster=detail >or). 8s )entioned a+ove4 in cases w&ere a large nu)+er o> detail records are associated wit& eac& )aster record4 it is a good idea to set coordination=De>erred to Bes to avoid unnecessar2 trans>ers o> data +etween t&e server and client. T&is will also speed up t&e displa2 o> )aster records as t&e user can >reel2 scroll t&roug& t&e) wit&out a pause to quer2 and deliver t&e detail records. G.4 Pro*ram 2nits in a "aster7Detail Form W&en a *aster=detail >or) is created4 t&ree +asic *rogram +nits @P1/S91 ProceduresA are created +2 de>ault. T&ese procedures are used to coordinate t&e quer2 and navigation o> t&e detail records w&en t&e )aster record is c&anged @e.g.4 w&en t&e user scrolls to a di>>erent )aster recordA4 updated or deleted. T&e procedures can +e seen listed in t&e '+,ect !avigator; P1/S91 is 'racleFs procedural language e:tensions to S91. To view t&e P1/S91 code >or a Progra) #nit4 clic0 on t&e na)e o> t&e progra) unit wit& t&e rig&t )ouse +utton and t&en c&oose PLNS:L E+>.o- >ro) t&e pop=up )enu. T&e code >or t&e -D3-HGP8-H853G(8I1#63 procedure is s&ow &ere; T&e -D3-HGP8-H853G(8I1#63 procedure c&ec0s to see i> a prior >or) co))and or S91 state)ent was success>ul or i> it >ailed. /elow is t&e P1/S91 code >or t&e 9#36BG*8ST36GD3T8I1S procedure. T&e te:t a>ter t&e 44 @two )inus signsA are co))ents. PROCEDRE :/e-y&M,(.e-&De.,>l((-el&>+ Rel,.>o),+e.,>l CHAR) IS ol+m(@ CHAR(2)$ 44 Ol+ Me((,@e LeCel Se..>)@ -el+e1 CHAR(5)$ 44 Rel,.>o) De1e--e+ Se..>)@ BE*IN 44 44 I)>.>,l>He Lo=,l V,->,0le(() 44 -el+e1 GJ *e.&Rel,.>o)&P-ope-.y(-el&>+, DEFERRED&COORDINATION)$ ol+m(@ GJ GSy(.emDMe((,@e&LeCel$ 44 44 I1 NOT De1e--e+, *o.o +e.,>l ,)+ eEe=/.e .Be O/e-yD 44 IF -el+e1 J 2FALSE2 THEN *o&Blo=%(+e.,>l)$ CBe=%&P,=%,@e&F,>l/-e$ GSy(.emDMe((,@e&LeCel GJ 2182$ EEe=/.e&:/e-y$ GSy(.emDMe((,@e&LeCel GJ ol+m(@$ ELSE 44 44 Rel,.>o) >( +e1e--e+, m,-% .Be +e.,>l 0lo=% ,( /)4=oo-+>),.e+ 44 Se.&Blo=%&P-ope-.y(+e.,>l, COORDINATION&STATS, NON&COORDINATED)$ END IF$ E"CEPTION ;HEN Fo-m&T->@@e-&F,>l/-e THEN GSy(.emDMe((,@e&LeCel GJ ol+m(@$ RAISE$ END :/e-y&M,(.e-&De.,>l($
T&e 9#36BG*8ST36GD3T8I1S procedure is e:ecuted w&enever t&e user navigates to t&e detail +loc0 in a )aster detail >or). I> t&e De>erred -oordination propert2 is set to >alse4 t&en t&e detail +loc0 is auto)aticall2 queried. (inall24 t&e -1386G*8ST36GD3T8I1S procedure is called eac& ti)e a new )aster record is retrieved @e.g.4 w&en t&e user scrolls to a di>>erent )aster recordA or deleted. In t&is case4 i> an2 o> t&e detail records &ave +een inserted4 updated or deleted4 t&e c&anges )ust +e saved into t&e data+ase +e>ore t&e detail +loc0 can +e cleared. I> t&ere are an2 outstanding c&anges to +e saved4 t&e user will +e pro)pted to save t&ose c&anges +e>ore t&e detail +oc0 is cleared. G.. !<tendin* "aster7Detail Forms *aster=Detail >or)s can +e e:tended to include additional levels o> details. (or e:a)ple4 consider a -usto)er listing wit& detail on 'rders a custo)er &as placed. (or eac& 'rder4 t&ere are t&en )an2 Ite)s. 8n e:tension to t&e a+ove e:a)ple would +e to include t&e D3P3!D3!TS o> t&e e)plo2ees as a details o> t&e 3*P1'B33S +loc0. T&e steps outlined a+ove can +e repeated allowing several levels o> detail to +e added. 3ac& additional level o> detail will add a new +loc0 t&at is related to t&e level a+ove it. G.8 !<ercise? Creatin* a "aster/Detail Form (or t&is e:ercise4 create a *aster/Detail >or) using t&e 3*P1'B33 and D3P3!D3!T ta+les. 3)plo2ee will +e t&e *aster +loc0 and Dependents will +e t&e Detail +loc0. T&e ,oin condition +etween t&e two ta+les is w&ere t&e SS! colu)n o> 3*P1'B33 is equal to t&e 3SS! colu)n o> D3P3!D3!T. T&e >ollowing is an outline o> t&e steps; 1. -reate t&e 3)plo2ee data +loc0 and include t&e (!8*34 1!8*34 SS!4 8DD63SS and S3$ >ields on t&e >or). #se t&e (or) la2out and onl2 displa2 one record at a ti)e. 2. 5o +ac0 to t&e '+,ect !avigator and select t&e IData /loc0sI tree. *a0e sure t&e 3*P1'B33 +loc0 is not selected and run t&e Data /loc0 WiEard again. 3. -reate t&e Dependents data +loc0 and include all o> t&e colu)ns. (or t&e )aster/Detail relations&ip4 de=select t&e IautoI option4 use a 7oin relations&ip4 c&oose t&e 3*P1'B33 data +loc0 as t&e *aster and set DEPENDENTDESSN J EMPLOYEEDSSN >or t&e ,oin relations&ip. %. In t&e 1a2out WiEard >or t&e Dependents data +loc04 displa2 all o> t&e >ields e&cet t'e #SSN field. T&e 3SS! >ield will re)ain part o> t&e data +loc0 +ut it will not +e visi+le on t&e >or). -&oose a Ta+ular st2le and displa2 % up to records at once wit& " space +etween eac& record. 5. Save t&e >or) using t&e na)e; emp+ep)D1m0 T&e co)pleted >or) s&ould loo0 li0e t&e >ollowing; 9uer2 t&e )aster +loc0 and practice navigating +etween t&e two +loc0s using t&e -T61= PageDown and -T61=Page#p 0e2s. W&ile in t&e 3)plo2ee +loc04 scroll to t&e 3)plo2ee na)ed 73!!I(36 W8118-34 navigate to t&e Dependents +loc0 and add a new record >or a S'! na)ed 8!D63W +orn on 2"='-T=19.2. !avigate +ac0 to t&e 3)plo2ee +loc0 and atte)pt to scroll to anot&er e)plo2ee record. 8 pro)pt s&ould +e displa2ed to save t&e new Dependent record. W&ile in t&e *aster +loc0 >or 3)plo2ees4 scroll to an e)plo2ee w&o &as so)e dependents. Tr2 to delete t&e 3)plo2ee record and see i> an error )essage appears. (inall24 alter t&e 3*P1'B33GD3P3!D3!T relation properties and set t&e -oordination=De>erred to Bes and t&en run t&e >or). !otice now t&at t&e detail records will not +e displa2ed auto)aticall2. !avigate to t&e Dependents +loc0 and &it t&e 3:ecute quer2 +utton @or pull down t&e :/e-y )enu and c&oose EEe=/.eA. !otice t&at onl2 t&ose Dependent records )atc&ing t&e 3)plo2ee are displa2ed. 0. &ist o; =alues @&O=sA and #on79ase Ta$le Fields It is cu)+erso)e >or a user to &ave to re)e)+er various codes and nu)+ers w&ile entering data into a data entr2 >or). (or e:a)ple4 in t&e 3)plo2ee >or)4 it )ig&t +e di>>icult to &ave all o> t&e depart)ent nu)+ers )e)oriEed w&en inserting new e)plo2ee data. 'ne solution to t&is pro+le) is to )a0e a list o> appropriate values availa+le w&en t&e user navigates to Depart)ent !u)+er >ield @D!'A. In 'racle (or)s4 t&ese are called 1ist o> ?alues @1'?sA. T&e ne:t section will illustrate creating 1'?s >or >ields. T&ese e:a)ples are +ased on t&e single +loc0 3)plo2ee >or) created at t&e +eginning o> t&is tutorial. To prepare >or t&is part o> t&e tutorial4 close an2 >or)s 2ou currentl2 &ave open +2 pulling down t&e F>le )enu and selecting t&e Clo(e )enu ite). 'nce all o> t&e >or)s are closed4 pull down t&e F>le )enu and c&oose t&e Ope) )enu ite) to open up t&e employeeD1m0 >or) t&at was created previousl2. 8 1ist o> ?alues is +ased on a )ecord ,rou. In 'racle (or)s4 a record group is a quer2 t&at returns so)e collection o> records. 6ecord groups can +e used to populate +loc0s or 1'?s and t&e2 can +e used in procedures. W&en t&e user navigates to an ite) wit& an 1'? attac&ed to it4 t&e 1'? 0e2 @(9 in *S WindowsA can +e pressed to call up t&e 1'?. 8t t&at ti)e4 t&e quer2 associated wit& t&e record group is e:ecuted and t&e results are displa2ed in a pop up window. 'nce t&e user )a0es a selection >ro) t&e list4 t&e value or values are returned to t&e >or) and placed in t&e appropriate >ields. In t&e e:a)ple +elow4 a record group and 1'? >or t&e D!' @depart)ent nu)+erA >ield in t&e 3)plo2ee ta+le will +e created. 0.1 Creatin* a &ist o; =alues -reating a 1ist o> ?alues requires % +asic steps. 0.1.1 Create a ne, &O= O$5ect To create an 1'?4 clic0 on t&e 1'?s node in t&e '+,ect !avigator. T&en pull down t&e N,C>@,.o- )enu and c&oose t&e C-e,.e )enu ite). 8 dialog +o: will appear as0ing i> 2ou would li0e to create t&e 1'? )anuall2 or i> 2ou would li0e to use t&e 1'? WiEard. -&oose I#se t&e 1'? WiEardI and clic0 t&e 'H +utton. T&e >irst step o> t&e 1'? WiEard will appear as +elow; T&e de>ault is set to create a new 6ecord 5roup. *a0e sure t&is selection is &ig&lig&ted and t&en clic0 t&e !e:t +utton. In )ost cases4 2ou will not &ave a record group created previousl2. Dowever4 one can +e created on t&e >l2 at t&is point +2 speci>2ing a quer2. In t&is e:a)ple4 enter t&e 1'? quer2 as >ollows; SELECT DNMBER FROM DEPARTMENT T&en clic0 on t&e !e:t +utton. T&e ne:t step is to speci>2 w&ic& colu)ns in t&e record group will +e returned to >or use +2 t&e 1'?. In t&is e:a)ple4 we onl2 return D!#*/36 so select t&at colu)n as s&own +elow and clic0 !e:t. T&e ne:t step is to speci>2 t&e displa2 properties o> t&e 1'? colu)ns and also to )ap t&e 1'? ite) to t&e >ield on t&e >or). To )ap t&e 1'? colu)n to a >ield4 clic0 on t&e D!#*/36 entr2 and t&en clic0 on t&e I1oo0 up return Ite)I +utton. Dig&lig&t t&e 3*P1'B33.D!' >ield and clic0 on t&e 'H +utton. !ote t&at i> 2our 1'? contains )ore t&an one ite)4 at t&is ti)e 2ou would also )ap t&e) as well @t&is is not t&e case wit& t&is e:a)ple4 +ut in t&e ne:t e:a)ple we will need to )ap two 1'? colu)nsA. -lic0 on t&e !e:t +utton. Speci>2 a title >or 1'? window. 8t t&is point 2ou )a2 also speci>2 t&e siEe and positioning o> t&e 1'?. (or t&is e:a)ple4 leave t&e) as t&e de>aults and clic0 t&e !e:t +utton. T&e advanced properties relate to &ow t&e records s&ould +e >etc&ed >or t&e 1'?. I> t&ere are )an2 &undreds or t&ousands o> possi+le records returned +2 t&e 1'?4 2ou )a2 consider c&anging t&ese options. 't&erwise4 >or t&is e:a)ple4 si)pl2 clic0 !e:t. In t&is >inal step4 t&e 1'? is returning so)e colu)ns and t&e2 were assigned to >ields on t&e >or) in a previous step. 8t t&is point4 we need to associate t&e 1'? wit& a particular ite) on t&e >or). (or e:a)ple4 +2 assigning t&e 1'? to t&e 3*P1'B33.D!' >ield4 t&e user will +e a+le to call up t&e 1'? onl2 w&en t&e cursor is positioned in t&e 3*P1'B33.D!' >ield. -&oose 3*P1'B33.D!' and clic0 t&e !e:t +utton. (inall24 clic0 (inis& to create t&e 6ecord 5roup and t&e 1'?. In t&e >igure +elow4 t&e 1'? &as +een created. 8 de>ault na)e o> 1'?% was given to +ot& t&e 1'? and to its associated record group. Depending on w&at ot&er parts o> t&is tutorial 2ou &ave co)pleted4 t&e de>ault na)e )a2 +e slig&tl2 di>>erent. Save4 -o)pile and 6un t&e >or). W&en entering new data4 navigate to t&e D!' @Depart)ent nu)+erA >ield. !otice at t&e +otto) o> t&e >or)4 a )essage appears; L>(. o1 V,l/e( indicating a list o> values is availa+le >or t&is >ield. #nder #!I$4 t&e 0e2 to displa2 t&e list o> values is -ontrol=l. #nder *S Windows 95/9/!T/2""" t&e 0e2 to displa2 t&e list o> values is (9. To see t&e appropriate 0e2s to press4 pull down t&e Help )enu and c&oose t&e 'ey( ite). 0.2 #on79ase Ta$le ;ields In t&e previous e:a)ple o> adding a 1ist o> ?alues4 t&e supplied list o> appropriate values can +e use>ul in cases w&ere t&e values t&e)selves are sel>=e:planator2. Dowever4 in t&e prior e:a)ple4 t&e depart)ent nu)+ers )a2 not &ave )eaning to t&e user. It would +e )ore &elp>ul to include t&e na)e o> t&e depart)ent +ot& in t&e pop=up list o> values and on t&e >or). Dowever4 t&e depart)ent na)e is not part o> t&e 3*P1'B33 ta+le or data +loc0. T&us we need a wa2 to displa2 t&is in>or)ation on t&e 3*P1'B33 data +loc0 in a non base table field. 8dding t&is ite) and )a0ing it >unctional will ta0e several steps; 1. (irst t&e new ite) will &ave to +e added to t&e 3*P1'B33 data +loc0. WeFll call t&is new ite) D3PT!8*3. 2. !e:t4 t&e D3PT!8*3 >ield s&ould +e populated wit& t&e depart)ent na)e eac& ti)e t&e value o> t&e D!' >ield c&anges. 8 .->@@e- will +e created to &andle t&is >unctionalit2. 3. (inall24 t&e list o> values will +e c&anged to include t&e Depart)ent na)e in t&e 1'?. 0.2.1 Addin* a #e, Item to an !<istin* Data 9loc: Switc& to t&e 1a2out 3ditor +2 clic0ing on t&e Tool( )enu and selecting t&e L,yo/. E+>.o- )enu ite). -lic0 on t&e Te:t Ite) tool and create a new >ield on t&e 3*P1'B33 +loc0 +2 clic0ing and dragging t&e )ouse ne:t to t&e D!' ite). Displa2 t&e properties >or t&e new Te:t Ite) +2 dou+le clic0ing on it. -&ange its na)e to D3PT!8*3. -&ange t&e >ollowing properties >or D3PT!8*3; !na$led? Bes He%$oard #avi*a$le? !o Data$ase Item? !o Cuer% Onl%? !o Primar% He%? !o Insert Allo,ed? !o Cuer% Allo,ed? !o 2pdate Allo,ed? !o /2 setting He2+oard !aviga+le to No4 we prevent t&e user >ro) ta++ing into t&is >ield. Since t&is >ield is not used >or data entr2 or quer2ing4 t&is prevents t&e potential con>usion. T&e Data+ase Ite) propert2 is set to No w&ic& indicates t&at t&is >iled does not )ap to an actual colu)n in t&e 3*P1'B33 ta+le. T&e re)aining properties are all set to No to 0eep t&e >ield >ro) participating in an2 o> t&ese activities; Delete4 Insert4 #pdate and 9uer2. 8t t&is point4 t&e new ite) D3PT!8*3 &as +een added to t&e 3*P1'B33 data +loc0 as a non=+ase ta+le >ield. Save t&e >or) at t&is point +2 pulling down t&e F>le )enu and c&oosing t&e S,Ce option. 0.2.2 Creatin* a Tri**er !e:t4 we will create a trigger to populate t&e D3PT!8*3 >ield w&enever t&e value o> D!' c&anges. Triggers in 'racle (or)s &ave >our general >or)s; P,E- Tri**er ;ires $e;ore an event is e<ecuted. POS&- Tri**er ;ires a;ter an event is e<ecuted. 51E3- Tri**er ;ires in place o; the e<ecution o; an event. 2EY- Tri**er ;ires ,hen a particular :e% is pressed. In t&is e:a)ple4 we would li0e to populate t&e D3PT!8*3 >ield wit& t&e appropriate depart)ent na)e ,ust a>ter t&e D!' >ield c&anges on t&e 3*P1'B33 +loc0. T&us we will use a POST4CHAN*E trigger on t&e GEMPLOYEEDDNO >ield. Switc& to t&e '+,ect !avigator view +2 clic0ing on t&e Tool( )enu and c&oosing t&e O0Le=. N,C>@,.o- )enu ite). 'pen up t&e 3*P1'B33 data +loc0 and t&e D!' ite). -lic0 on t&e Tri**ers propert2 and create a new trigger +2 pulling down t&e N,C>@,.o- )enu and c&oosing t&e C-e,.e )enu ite). 8 list o> possi+le trigger na)es appears. -&oose t&e POST4CHAN*E trigger and clic0 on t&e 'H +utton. W&en t&e P1/S91 editor appears4 t2pe t&e >ollowing P1/S91 code; 44 Pop/l,.e .Be )o)40,(e .,0le 1>el+ GEMPLOYEEDDEPTNAME 44 /(>)@ , C,l/e 1-om .Be DEPARTMENT .,0leD BE*IN SELECT DNAME INTO GEMPLOYEEDDEPTNAME FROM DEPARTMENT ;HERE DEPARTMENTDDNMBER J GEMPLOYEEDDNO$ END$ Ite)s on a +loc0 are preceded +2 a >ull colon to di>>erentiate t&e) >ro) colu)ns in a ta+le. -o)pile t&e trigger +2 clic0ing on t&e -o)pile +utton. -lose t&e P1/S91 editor +2 clic0ing on t&e -lose +utton. T&en save4 co)pile/+uild and run t&e >or) to test t&e >unctionalit2. !otice t&at w&en t&e 3*P1'B33 +loc0 is queried4 t&e associated depart)ent na)e now appears in t&e new D3PT!8*3 >ield. 0.2.( Create a ne, &ist o; =alues (inall24 a new list o> values s&ould +e created to displa2 +ot& t&e depart)ent nu)+er and na)e w&en t&e user calls up t&e 1'?. (ro) t&e '+,ect !avigator4 clic0 on t&e 1'?s >or t&e 3*P1'B33 >or). Pull down t&e N,C>@,.o- )enu and c&oose t&e C-e,.e )enu ite). -&oose t&e 1'? WiEard. T2pe t&e >ollowing S91 state)ent into t&e Cuer% Te<t >ield; SELECT DEPARTMENTDDNMBER, DEPARTMENTDDNAME FROM DEPARTMENT
T&en clic0 on t&e !e:t +utton. Include +ot& t&e D!#*/36 and D!8*3 colu)ns >ro) t&e 6ecord 5roup in t&e 1'?. *ap t&e D!#*/36 1'? colu)n to t&e ;3*P1'B33.D!' te:t ite) and )ap t&e D!8*3 1'? colu)n to t&e ;3*P1'B33.D3PT!8*3 te:t ite) @created in t&e previous sectionA. 5ive a title >or 2our list o> values and return +ot& D!#*/36 and D!8*3 >ro) t&e 1'?. (inall24 Save4 -o)pile and 6un t&e >or). !ote t&at displa2ing t&e 1'? >or t&e D!' ite) now causes +ot& t&e depart)ent nu)+er and t&e na)e to appear. 0.( !<ercise? Creatin* an &O= and #on79ase ta$le ;ield (or t&is e:ercise4 create a new4 single data +loc0 >or) +ased on all o> t&e colu)ns in t&e D3P86T*3!T ta+le. T&en add a non=+ase ta+le >ield >or t&e last na)e o> t&e depart)ent )anager and create an 1'? to populate it; -reate a new >or) called +ep,-.m@D1m0 t&at includes all o> t&e colu)ns in t&e D3P86T*3!T ta+le. In t&e la2out wiEard4 use t&e Ta+ular la2out and displa2 5 6ecords in t&e >or). 8dd a scroll+ar. In t&e 1a2out 3ditor4 create a new te:t ite) called *56G18STG!8*3 in t&e D3P86T*3!T data +loc0. /e sure t&e D3P86T*3!T +loc0 is selected w&en t&e new ite) is created. -&ange t&e properties o> *56G18STG!8*3 so it is not a Data+ase ite). -reate a list o> values called 1'?G*56 +ased upon t&e quer2; SELECT ((), l),me FROM employee 8ssign 1'?G*56 to t&e *56SS! ite). -reate a P'ST=-D8!53 trigger on t&e *56SS! ite) so t&at w&en it c&anges4 t&e >ollowing code will e:ecute; SELECT l),me INTO GDEPARTMENTDM*R&LAST&NAME FROM employee ;HERE employeeD(() J GDEPARTMENTDM*RSSN$ T&is will auto)aticall2 populate t&e non +ase ta+le >ield *56G18STG!8*3 on t&e >or) w&en t&e >or) is queried. T&e >or) s&ould loo0 li0e t&e >ollowing; -. Oracle Forms Pro*ram 2nits and )tored Pro*ram 2nits 'racle (or)s provides a )ec&anis) to store procedures @called Progra) #nitsA written in t&e P1/S91 language wit&in a >or). Progra) #nits can +e used to add >unctionalit2 t&at is not possi+le t&roug& Structured 9uer2 1anguage @S91A or t&roug& t&e 'racle (or)s inter>ace. So)e e:a)ples o> Progra) #nits were given in t&e discussion on Progra) #nits in a *aster=Detail (or). /2 storing a Progra) #nit wit&in a >or)4 )an2 +loc0s in t&e >or) can ta0e advantage o> t&e sa)e procedure w&ic& reduces code duplication and i)proves t&e )aintaina+ilit2 o> t&e code. Procedures written in P1/S91 )a2 also +e stored wit&in t&e 'racle Data+ase itsel> as an o+,ect in t&e sc&e)a. Suc& Stored Progra) #nits @also called Stored ProceduresA are ideal >or situations w&ere &ig&l2 standardiEed +usiness rules or applications logic )ust +e i)ple)ented across )an2 >or)s or applications. In addition4 procedures t&at require several queries +e )ade to t&e data+ase )a2 +e +est i)ple)ented in t&e data+ase as t&is reduces t&e networ0 tra>>ic and can signi>icantl2 i)prove per>or)ance. 8 user )a2 create stored procedures wit& t&e 'racle S91CPlus co))and line tool. 'racle (or)s can )a0e calls to +ot& internal Progra) #nits as well as to Stored Progra) #nits. T&is >le:i+ilit2 allows application designers e:tensive control over t&e e:ecution o> applications and >acilitates per>or)ance tuning. In t&e >ollowing sections4 e:a)ples o> 'racle (or)s Progra) #nits and Stored Progra) #nits will +e given. -.1 Creatin* Pro*ram 2nits in Oracle Forms In t&is section4 we will aug)ent t&e 3*P1'B33 >or) +2 adding a count o> ot&er )e)+ers o> a given e)plo2eeFs depart)ent. To add t&is >unctionalit24 we will add a new >ield ite) to t&e 3*P1'B33 +loc04 write a Procedure in P1/S91 to gat&er t&e data and t&en write a Trigger t&at will call t&e Procedure eac& ti)e a new 3)plo2ee record is queried. -.1.1 Add a ne, item to the !"P&O'!! 9loc: 8dd a new ite) on t&e 3*P1'B33 +loc0 to store t&e count o> ot&er e)plo2ees in t&e depart)ent. See t&e section on 8dding a !ew Ite) to an 3:isting /loc0 >or details. -all t&is >ield OTB!RI"!"9!R). /e sure it is a non=data+ase >ield and t&at a user will not +e a+le to navigate t&ere4 insert4 update or delete data in t&e >ield. 5o to t&e Properties and c&ec0 eac& o> t&e); !na$led? True #avi*a$le? !o Data$ase Item? !o Cuer% Onl%? !o Primar% He%? !o Insert Allo,ed? !o Cuer% Allo,ed? !o 2pdate Allo,ed? !o 8dd a la+el to t&is >ield +2 switc&ing to t&e 1a2out 3ditor4 c&oosing t&e te:t tool and clic0ing ne:t to t&e 'TD36G*3*/36S >ield. -.1.2 Create a Procedure to Count Other Department "em$ers In t&is step4 create a Progra) #nit @procedureA in 'racle (or)s to count t&e nu)+er o> ot&er )e)+ers in t&e sa)e depart)ent. (or t&is procedure4 we will pass in a para)eter called I!G3*P1'B33GSS! t&at will contain an e)plo2eeFs social securit2 nu)+er. T&e procedure will return a value in t&e para)eter '#TG-'#!TG'TD36G*3*/36S t&at will contain t&e nu)+er o> ot&er e)plo2ees w&o are in t&e sa)e depart)ent. To create t&is procedure4 switc& to t&e '+,ect !avigator and scroll down to t&e Pro*ram 2nits +ranc&. Pull down t&e N,C>@,.o- )enu and c&oose t&e C-e,.e )enu ite). 8 dialog +o: will appear as0ing 2ou to na)e t&e new procedure. T2pe in t&e na)e OTHER&DEPARTMENT&MEMBERS and clic0 on t&e 'H +utton. 8t t&is point4 t&e P1/S91 editor will appear. T2pe in t&e >ollowing procedure +od2. 8n e:planation o> eac& part o> t&e procedure is given a>terwards; 44 *>Ce) ,) Employee2( SSN, -e./-) .Be )/m0e- o1 o.Be- employee( 44 >) .Be (,me +ep,-.me).D PROCEDRE OTHER&DEPARTMENT&MEMBERS (IN&EMPLOYEE&SSN IN NMBER, OT&CONT&OTHER&MEMBERS OT NMBER) IS TEMP&CONT NMBER$ 44 Pl,=eBol+e- 1o- =o/). BE*IN TEMP&CONT GJ 8$ 44 I)>.>,l>He .o 8 44 T-y ,)+ 1>ll TEMP&CONT F>.B .Be =o/). o1 o.Be- 44 Employee( >) .Be +ep,-.me). SELECT CONT(P) INTO TEMP&CONT FROM EMPLOYEE ;HERE EMPLOYEEDDNO J (SELECT EMPLOYEEDDNO FROM EMPLOYEE ;HERE EMPLOYEEDSSN J IN&EMPLOYEE&SSN)$ 44 See >1 Fe @o. , me,)>)@1/l -e(/l. IF (NVL(TEMP&CONT, 8) Q? 8) THEN OT&CONT&OTHER&MEMBERS GJ (TEMP&CONT 4 1 )$ ELSE OT&CONT&OTHER&MEMBERS GJ 8$ END IF$ END$ T&e procedure is written in t&ree )ain sections. 8n2 lines starting wit& 44 are co))ents and are ignored +2 'racle >or)s. T&e &eading >or t&e procedure de>inition indicates t&at one para)eter4 I!G3*P1'B33GSS!4 is a !#*/36 data t2pe and t&e procedure s&ould e:pect a value to +e passed in. T&e ot&er para)eter4 '#TG-'#!TG'TD36G*3*/36S4 is also a !#*/36 data t2pe and a value will +e passed +ac0 to t&e calling progra) t&roug& it. To >inis& o>> t&e procedure &eader4 t&e T3*PG-'#!T varia+le is declared >or use wit&in t&is procedure onl2. T&e /35I! state)ent starts t&e +od2 o> t&e procedure. T3*PG-'#!T is initialiEed to " and t&en a quer2 is per>or)ed on t&e data+ase to >ind t&e total nu)+er o> e)plo2ees in t&e sa)e depart)ent as t&e e)plo2ee w&ose SS! was supplied to t&e procedure. T&e result in T3*PG-'#!T is c&ec0ed to see i> it is a !#11 value. I> T3*PG-'#!T is not !#11 and it is not "4 t&en '#TG-'#!TG'TD36G*3*/36S is set to equal T3*PG-'#!T=1. 't&erwise '#TG-'#!TG'TD36G*3*/36S is set to ". T&e last 3!D state)ent ends t&e +od2 o> t&e procedure. /e sure to c&ec0 to see t&at t&e procedure co)piles +2 clic0ing on t&e Comp>le +utton. 8n2 errors in t&e procedure will +e &ig&lig&ted. So)e co))on pro+le)s include >orgetting to use GJ in an assign)ent state)ent @li0e t&e Pascal languageA and leaving o>> t&e END IF to >inis& up IF DDD THEN state)ents. W&en done4 clic0 on t&e Clo(e +utton to close t&e P1/S91 editor. -.1.( Create a Tri**er to Call the Procedure -reate a trigger to call t&e 'TD36GD3P86T*3!TG*3*/36S procedure. In t&e '+,ect !avigator4 open up t&e 3*P1'B33 +loc0 and t&e SS! ite). Dig&lig&t t&e Tri**er +ranc& >or t&e SS! ite)4 pull down t&e N,C>@,.o- )enu and c&oose t&e C-e,.e )enu ite). 8 pop up list o> trigger na)es will appear. -&oose P'ST=-D8!53 and clic0 on t&e 'H +utton to open t&e P1/S91 editor >or t&is new trigger. T2pe in t&e >ollowing code >or t&e P'ST=-D8!53 trigger on t&e SS! ite); DECLARE -e./-)&=o/). NMBER$ BE*IN 44 C,ll .Be Fo-m( P-o=e+/-e .o @e. .Be 44 =o/). o1 o.Be-( >) .Be +ep,-.me).D OTHER&DEPARTMENT&MEMBERS(GEMPLOYEEDSSN, -e./-)&=o/).)$ 44 A((>@) .Be -e./-) =o/). .o .Be 1>el+ o) 44 .Be EMPLOYEE 0lo=%D GEMPLOYEEDOTHER&MEMBERS GJ -e./-)&=o/).$ END$ 8gain4 clic0 on t&e Comp>le +utton to +e sure t&e trigger co)piles correctl2 and t&en clic0 on t&e Clo(e +utton to return to t&e '+,ect !avigator. -.1.4 )ave, Compile/9uild and Run the Form To t&is point4 we &ave added a new non=+ase ta+le >ield to t&e 3*P1'B33 +loc04 written a procedure @Progra) #nitA to count ot&er e)plo2ees in t&e sa)e depart)ent and added a trigger to call t&e procedure eac& ti)e a new e)plo2ee record is queried. To save 2ou wor04 use t&e S,Ce A( )enu ite) on t&e F>le )enu and save t&is >or) under t&e na)e; emp&mem0D1m0 Save4 -o)pile//uild4 and 6un t&e >or) to c&ec0 its >unctionalit2. !ote t&at w&en scrolling to a new e)plo2eeFs record4 t&e 'TD36G*3*/36S >ield is auto)aticall2 populated wit& values indicating t&e nu)+er o> ot&er e)plo2ees in t&e sa)e depart)ent. -.2 Creatin* )tored Procedures in )C&JPlus In t&e previous e:a)ple4 we added a procedure @Progra) #nitA in 'racle (or)s to per>or) a quer2 on t&e data+ase. T&e procedure is stored as part o> t&e >or)Fs source code and is co)piled w&en t&e >or) is +uilt. #pon e:a)ination4 eac& call o> t&is procedure produces; 1. 8 local call >ro) t&e P'ST=-D8!53 trigger to t&e procedure passing an e)plo2eeFs SS!. 2. 8 re)ote access >ro) t&e procedure to t&e data+ase passing a S91 quer2. 3. 8 re)ote return >ro) t&e data+ase containing a count. %. 8 s)all a)ount o> processing in t&e procedure @I( ... TD3!A. 5. 8 local return >ro) t&e procedure to t&e trigger. In t&is e:c&ange4 t&e &ig&est costs are incurred +2 t&e networ0 tra>>ic required to go +ac0 and >ort& +etween client and server @steps 2 and 3A. T&e lowest costs are incurred +2 t&e local calls +etween trigger and procedure and t&e local processing @steps 14 % and 5A. In t&is e:a)ple4 t&e S91 9uer2 in steps 2 and 3 does not return a signi>icant a)ount o> data. Dowever4 t&ere are situations w&ere4 i> a large a)ount o> data were to +e returned >or eac& quer24 suc& queries would severel2 i)pact per>or)ance. 'ne solution to t&is pro+le) is to )ove t&e queries and as )uc& processing as possi+le IcloserI to t&e data in t&e data+ase. T&us our e:a)ple >or t&is section will +e to i)ple)ent t&e 'TD36GD3P86T*3!TG*3*/36S procedure in t&e 'racle data+ase. To ac&ieve t&is4 we will need to use 'racle S91CPlus @a co))and=line toolA to create a stored procedure. 1og in to S91CPlus and enter t&e >ollowing -638T3 P6'-3D#63 state)ent. 8lternativel24 save t&is state)ent in a te:t >ile and e:ecute it using t&e START co))and in S91CPlus. CREATE PROCEDRE OTHER&DEPARTMENT&MEMBERS (IN&EMPLOYEE&SSN IN NMBER, OT&CONT&OTHER&MEMBERS OT NMBER) AS 44 *>Ce) ,) Employee2( SSN, -e./-) .Be )/m0e- o1 o.Be- employee( 44 >) .Be (,me +ep,-.me).D TEMP&CONT NMBER$ 44 Pl,=eBol+e- 1o- =o/). BE*IN TEMP&CONT GJ 8$ 44 I)>.>,l>He .o 8 44 T-y ,)+ 1>ll TEMP&CONT F>.B .Be =o/). o1 o.Be- 44 Employee( >) .Be +ep,-.me). SELECT CONT(P) INTO TEMP&CONT FROM EMPLOYEE ;HERE EMPLOYEEDDNO J (SELECT EMPLOYEEDDNO FROM EMPLOYEE ;HERE EMPLOYEEDSSN J IN&EMPLOYEE&SSN)$ 44 See >1 Fe @o. , me,)>)@1/l -e(/l. IF (NVL(TEMP&CONT, 8) Q? 8) THEN OT&CONT&OTHER&MEMBERS GJ (TEMP&CONT 4 1 )$ ELSE OT&CONT&OTHER&MEMBERS GJ 8$ END IF$ END$ 8>ter t2ping in t&is state)ent4 +e sure to RN t&e co))and in t&e S91CPlus +u>>er +2 t2ping RN or +2 t2ping t&e >orward slas& N !ote; W&ile creating a stored procedure4 2ou )a2 receive an error si)ilar to t&e >ollowing; ORA4818!1G >)(/11>=>e). p->C>le@e( T&is indicates t&e D/8 &as not granted 2ou t&e aut&oriEation to create stored procedures. Please contact 2our D/8 to o+tain t&is aut&oriEation. To see i> t&e procedure co)piled correctl24 loo0 in view #S36G366'6S as >ollows; S:L? SELECT P FROM /(e-&e--o-($ )o -oF( (ele=.e+ I> t&e )essage )o -oF( (ele=.e+ appears4 t&en no errors were >ound in t&e trigger. 8not&er alternative is to use t&e S91CPlus co))and called (BoF e--o-(. 8>ter su+)itting a trigger or a stored procedure4 an2 errors >ound during co)pilation can +e displa2ed using t&e (BoF e--o-( co))and. In so)e versions o> S91CPlus4 t&e (BoF e--o-( co))and will not wor0 due to a lac0 o> +u>>er )e)or2 on t&e client co)puter. 8n error )essage )a2 appear as in t&e >ollowing e:a)ple; S:L? CREATE PROCEDRE .e(. AS 2 BE*IN ! SELECT SYSDATE INTO G.emp FROM +/,l$ 3 END$ 5 N ;,-)>)@G P-o=e+/-e =-e,.e+ F>.B =omp>l,.>o) e--o-(D S:L? (BoF e--o-( 0/11e- oCe-1loFD (e SET =omm,)+ .o -e+/=e ARRAYSI<E o- >)=-e,(e MA"DATAD No e--o-(D
I> t&e 0/11e- oCe-1loF )essage appears4 set t&e 8668BSIJ3 varia+le to a lower nu)+er suc& as 2 wit& t&e >ollowing co))and; S:L? SET ARRAYSI<E 2
To see w&at stored procedures 2ou &ave created4 quer2 t&e #S36GS'#6-3 view in t&e data dictionar2. T&e onl2 )a,or di>>erence +etween t&e stored procedure created in t&e data+ase sc&e)a t&roug& S91CPlus and t&e procedure created in 'racle (or)s is t&e wa2 t&e &eader is >or)atted. -reating a stored procedure uses t&e >ollowing s2nta:; C,E+&E P,OCED4,E OTHER&DEPARTMENT&MEMBERS (IN&EMPLOYEE&SSN IN NMBER, OT&CONT&OTHER&MEMBERS OT NMBER) +S -ontrast t&is wit& t&e procedure done in 'racle (or)s; P,OCED4,E OTHER&DEPARTMENT&MEMBERS (IN&EMPLOYEE&SSN IN NMBER, OT&CONT&OTHER&MEMBERS OT NMBER) 6S 'nce t&e 'TD36GD3P86T*3!TG*3*/36S procedure @Progra) #nitA &as +een created in S91CPlus4 it is stored as an o+,ect in 2our sc&e)a and will re)ain t&ere until a DROP PROCEDRE OTHER&DEPARTMENT&MEMBERS state)ent is issued. 8n2 'racle (or)4 6eport or ot&er procedure can )a0e calls to 'TD36GD3P86T*3!TG*3*/36S as i> it were a local procedure. To see t&e stored procedure in action4 open t&e emp&mem0D1m0 >or) and re)ove @deleteA t&e Progra) #nit @procedureA 'TD36GD3P86T*3!TG*3*/36S >ro) it. Save t&e >or)4 co)pile4 generate and run it. T&e P'ST=-D8!53 trigger on ;3*P1'B33.SS! will auto)aticall2 )a0e a call to t&e stored procedure version o> 'TD36GD3P86T*3!TG*3*/36S located in t&e sc&e)a. To view t&e availa+le Stored Progra) #nits >ro) wit&in 'racle (or)s4 switc& to t&e '+,ect !avigator and open up t&e Data$ase O$5ects tree. (ro) t&ere4 a list o> sc&e)as @usersA will appear. Scroll down to 2our userna)e and open it up. T&en open up t&e Stored Progra) #nits tree. 8 list o> 2our stored procedure s&ould t&en appear. -.( Additional )tored Procedures and Tri**ers T&ere are countless wa2s in w&ic& stored procedures and triggers can +e used to en>orce +usiness rules and to process data in an application. In t&is section4 a >ew o> t&e )ost co))onl2 used triggers and procedures are descri+ed. -.(.1 Generatin* uniue or consecutive identi;iers usin* the ta$le *an2 o> t&e 0e2s used in ta+les are +ased on a nu)+er sequence. (or e:a)ple4 in our D3P86T*3!T ta+le4 t&e D!#*/36 is an integer t&at s&ould increase >or eac& new depart)ent. To auto)aticall2 generate a new D!#*/364 create a quer2 to capture t&e largest current D!#*/36 value and add 1 to it. T&en assign t&is new value to t&e D!#*/36 ite) in t&e D3P86T*3!T data +loc0. 8 trigger to do t&is could +e created at t&e +loc0 level and s&ould e:ecute +e>ore an2 new record is inserted into t&e data+ase. 8 PRE4INSERT trigger on t&e D3P86T*3!T data +loc0 would +e used >or t&is e:a)ple; BE*IN SELECT MA"( +)/m0e- ) M 1 INTO G+ep,-.me).D+)/m0e- FROM +ep,-.me).$ END$
8 P63=I!S36T trigger e:ecutes ,ust +e>ore t&e I!S36T state)ent >or a new record is sent to t&e data+ase. -.(.2 Generatin* uniue or consecutive identi;iers usin* an Oracle )euence 'ne pro+le) wit& t&e a+ove )et&od is t&at )an2 users wor0ing on t&e sa)e >or) to insert new records will run into concurrenc2 pro+le)s. (or eac& new record to +e inserted4 a >ull ta+le scan )ust +e done to >ind t&e largest identi>ier. 'ne solution to t&is pro+le) is to use an 'racle Sequence. 8n 'racle Sequence is a sc&e)a o+,ect t&at 0eeps trac0 o> a si)ple integer and auto)aticall2 incre)ents t&is counter w&en it is accessed. (or e:a)ple4 in our D3P86T*3!T ta+le4 t&e D!#*/36 is an integer t&at s&ould increase >or eac& new depart)ent. To auto)aticall2 generate a new D!#*/364 create an 'racle Sequence using t&e S91CPlus tool; CREATE SE:ENCE +ep,-.me).&(eO INCREMENT BY 1 START ;ITH 1 MA"VALE 55555 NOCYCLE$
T&e a+ove +ep,-.me).&(eO sequence will +egin counting >ro) 1 and incre)ent +2 1 until it reac&es 99999. 8>ter t&at4 accessing t&e sequence will produce an error. T&is is reasona+le since it is &ig&l2 unli0el2 an organiEation will ever &ave )ore t&an 99999 depart)ents. T&e ne:t step is to assign t&e ne:t value o> t&e sequence to t&e D!#*/36 ite) in t&e D3P86T*3!T data +loc0. 8 trigger to do t&is would +e created at t&e +loc0 level and s&ould e:ecute +e>ore an2 new record is inserted into t&e data+ase. 8 PRE4INSERT trigger on t&e D3P86T*3!T data +loc0 would +e used >or t&is e:a)ple; BE*IN 44 *e. .Be )eE. C,l/e 1o- DNMBER 1-om .Be 44 +ep,-.me).&(eO (eO/e)=eD SELECT +ep,-.me).&(eOD)eE.C,l INTO G+ep,-.me).D+)/m0e- FROM +/,l$ END$
T&e +/,l ta+le is a du))2 ta+le t&at contains e:actl2 one record @rowA. We can use it in a S313-T...I!T' state)ent to consistentl2 return a single value. T&e )eE.C,l accessed in t&e sequence will return t&e current sequence value and t&en auto)aticall2 incre)ent it to t&e ne:t value. 8 P63=I!S36T trigger e:ecutes ,ust +e>ore t&e I!S36T state)ent >or a new record is sent to t&e data+ase. 'racle Sequences are not applica+le >or )aster=detail >or)s suc& as purc&ase orders w&ere an ite) nu)+er needs to +e assigned in t&e detail ta+le. (or e:a)ple4 purc&ase order ite)s are t2picall2 nu)+ered; 1, 2, !DDD. T&e ne:t P' will also nu)+er t&e ite)s 1, 2, !, DDD. 8n 'racle Sequence is designed to deliver unique identi>iers >or pri)ar2 0e2s and s&ould not +e used >or suc& ite) nu)+ers. -.(.( Chec:in* constraints at the client In an2 data+ase s2ste)4 it is alwa2s desira+le to constrain t&e values certain colu)ns can ta0e on. It is possi+le to add constraints to t&e data+ase ta+les t&e)selves in order to en>orce constraints4 &owever4 t&e en>orce)ent onl2 ta0es place w&en a transaction reac&es t&e data+ase. In addition4 )an2 constraints on t&e data t&at involve values o> data >ro) ot&er ta+les )a2 not +e easil2 i)ple)ented as ta+le constraints. *an2 t2pes o> constraints on data can +e c&ec0ed in t&e client using triggers. (or e:a)ple4 in our 3*P1'B33 data entr2 >or)4 we )a2 want to en>orce a constraint t&at no e)plo2ee can act as t&eir own supervisor. T&us >or an2 record4 SS! )a2 not equal S#P36SS!. To i)ple)ent suc& a constraint4 add t&e S#P36SS! >ield to t&e 3*P1'B33 >or) and t&en create a ;HEN4VALIDATE4ITEM trigger on t&e S#P36SS! ite) in t&e 3*P1'B33 data +loc0; BE*IN IF (GSPERSSN J GSSN) THEN MESSA*E(2Employee( m,y )o. (/pe-C>(e .Bem(elCe(R2)$ RAISE FORM&TRI**ER&FAILRE$ END IF$ END$
T&e ('6*GT6I5536G(8I1#63 will cause t&e e:ecution o> t&e ite) validation to +e &alted and t&e user will &ave to c&ange t&e S#P36SS! +e>ore )oving on to anot&er ite). -.(.4 Addin* Alerts @Pop7up "essa*esA In t&e previous e:a)ple4 t&e *3SS853 procedure is used to displa2 t&e error along t&e status +ar at t&e +otto) o> t&e (or)s window. 8 +etter approac& )a2 +e to >orce t&e userFs attention to t&e pro+le). T&is can +e acco)plis&ed +2 creating a pop=up dialog +o: t&at >orces t&e user to read t&e )essage and clic0 an 'H +utton @or so)e ot&er +uttonA. In 'racle (or)s4 t&is is called an 8lert. To set up an 8lert; #se t&e '+,ect !avigator to displa2 t&e 8lerts area. Pull down t&e !avigator )enu and c&oose -reate. -lic0 on t&e de>ault na)e t&at is given >or t&e new alert @so)et&ing li0e 8136T%A and rena)e it; SPERVISOR&ALERT /ring up t&e Propert2 Palette >or t&is 8lert and >ill in t&e >ollowing properties; Title? Supervisor 8lert *essage "essa*e? 3)plo2ees )a2 not supervise t&e)selvesK Alert )t%le? ST'P 9utton 1 &a$el? 'H 1eave t&e 9utton 2 &a$el and t&e 9utton ( &a$el +lan0 De;ault Alert $utton? /utton 1 1eave all o> t&e ot&er properties wit& t&eir de>aults and close t&e Propert2 palette. -&ange t&e a+ove ;HEN4VALIDATE4ITEM trigger on t&e S#P36SS! ite) in t&e 3*P1'B33 data +loc0 to; DECLARE -e./-)&,le-. NMBER$ BE*IN IF (GSPERSSN J GSSN) THEN -e./-)&,le-. GJ SHO;&ALERT (2SPERVISOR&ALERT2)$ RAISE FORM&TRI**ER&FAILRE$ END IF$ END$
T&e SD'WG8136T procedure calls up t&e speci>ied alert and o+tains t&e return value @+ased on t&e +utton t&e user clic0s onA to assign to a local varia+le called -e./-)&,le-.. /elow is an e:a)ple o> t&e 8lert in action; In general4 a >or)4 a P'ST=('6* trigger )ig&t invo0e an I8re 2ou sure 2ou want to 3:itI 8lert wit& IBesI and I!oI +uttons. 'r4 to con>ir) deleting a record4 a P63= -'**IT trigger )ig&t invo0e an I8re 2ou sure 2ou want ot delete t&is 3)plo2eeLI 8lert wit& IBesI and I!oI +uttons. /ased on t&e returnGalert value4 eit&er a co))it or roll+ac0 )ig&t +e issued. -.(.. Populate items ,ith de;ault values T&ere are )an2 cases w&ere de>ault values can +e suggested >or certain data ite)s +ased upon values alread2 supplied in ot&er data ite)s. T&e )et&od &ere is to use a P'ST= IT3* or WD3!=?81ID8T3=IT3* trigger to populate anot&er >ield4 onl2 i> t&e ot&er >ield is currentl2 +lan0. (or e:a)ple4 to populate t&e S#P36SS! data ite) o> t&e 3*P1'B33 +loc0 +ased upon t&e *56SS! o> t&e e)plo2eeFs depart)ent4 t&e >ollowing WD3!=?81ID8T3=IT3* trigger code )ig&t +e used on t&e D!' data ite); BE*IN IF GSPERSSN IS NLL THEN SELECT +ep,-.me).Dm@-(() INTO GemployeeD(/pe-(() FROM +ep,-.me). ;HERE +ep,-.me).D+)/m0e- J GemployeeD+)o$ END IF$ END$
!ote t&at t&e I( state)ent uses GSPERSSN IS NLL to c&ec0 to see i> an2 value &as +een supplied >or S#P36SS!. I> not&ing was t2ped into t&e S#P36SS! data ite)4 t&en its value is !#11. I> t&e user t2pes an2t&ing at all into t&e S#P36SS! data ite)4 t&en t&e I( state)ent will evaluate to >alse and no value will +e suggested. -.(.8 Attachin* ;unctionalit% to command $uttons -o))and +uttons can +e added on a >or) to carr2 out >unctions suc& as e:iting a >or)4 co))itting/saving c&anged records and so on. T&e +asic co))and +utton o+,ect contains properties >or t&e +utton 1a+el @t&e te:t provided on t&e +utton itsel>A. 8dditional properties include visual attri+utes including t&e a+ilit2 to displa2 a +it)ap i)age in place o> t&e +uttonFs nor)al appearance. 'nce a +utton &as +een p&2sicall2 placed on a >or)4 >unctionalit2 is added +ut writing a ;HEN4BTTON4PRESSED trigger. 8s one )ig&t e:pect4 t&is trigger e:ecutes w&en t&e user clic0s on t&e +utton. So4 >or e:a)ple4 to create a +utton to e:it t&e >or) w&en t&e user clic0s on it t&e ;HEN4BTTON4PRESSED trigger )ig&t loo0 li0e; DECLARE -e./-)&,le-+. NMBER$ BE*IN -e./-)&,le-. GJ SHO;&ALERT (2E"IT&ALERT2)$ IF (-e./-)&,le-. J ,le-.&0/..>)1) THEN E"IT&FORM$ END IF$ END$
T&e a+ove code assu)es t&ere is an 8lert called 3$ITG8136T wit& two +uttons; IBesI and I!oI. I> t&e user clic0s on t&e >irst +utton @IBesIA t&en t&e 3$ITG('6* procedure is called and t&e >or) will e:it @closeA. I> t&e user clic0s on an2 ot&er +utton4 t&en t&e 8lert will close and t&e >or) will re)ain open. -.(.G Passin* parameters $et,een ;orms T&ere are )an2 occasions t&at require t&e passing o> data >ro) one >or) to anot&er. 'ne suc& e:a)ple is w&en we quer2 a certain record on one >or) and t&en wis& to call up anot&er >or) wit& t&e sa)e record auto)aticall2 retrieved. In general4 data values can +e passed +etween >or)s using 51'/81 varia+les @treat ;51'/81 as a +loc0 availa+le in all >or)sA or +2 using Para)eter lists. In t&e e:a)ple4 +elow4 t&e para)eter list >eatures will +e used to de)onstrate &ow data can +e passed >ro) one >or) to anot&er. (or t&is e:a)ple4 we wil )a0e use o> two >or)s; 8 +asic 3*P1'B33 >or) wit& all >ields and t&e 3*P1'B33/D3P3!D3!T )aster/detail >or) @created in a previous e:ercise = t&e >ile na)e s&ould &ave +een emp+ep)D1m0A. T&e idea is to place to +utton on t&e 3*P1'B33 >or) t&at w&en pressed4 will call t&e 3*P1'B33/D3P3!D3!T >or) and auto)aticall2 quer2 t&e dependents >or t&e e)plo2ee +eing viewed on t&e 3*P1'B33 >or). T&e )ain steps are; 'n t&e 3*P1'B33 >or)4 create a +utton and la+el it I9uer2 DependentsI. -reate a WD3!=/#TT'!=P63SS3D trigger wit& t&e >ollowing code @co))ents are enclosed in t&e codeA; DECLARE NP De=l,-e pl&>+ ,( .Be >+e).>1>e- 1o- .Be p,-,me.e- l>(. PN pl&>+ P,-,mL>(.$ BE*IN NP See >1 .B,. p,-,me.e- l>(. ,l-e,+y eE>(.(D I1 (o, +e(.-oy >. PN pl&>+ GJ *e.&P,-,me.e-&L>(.(2.mp+,.,2)$ IF NOT I+&N/ll(pl&>+) THEN De(.-oy&P,-,me.e-&L>(.( pl&>+ )$ END IF$ NP C-e,.e , 1-e(B p,-,me.e- l>(. PN pl&>+ GJ C-e,.e&P,-,me.e-&L>(.(2.mp+,.,2)$
-o)pile and save t&is >or). !ow open up t&e emp+ep) @3*P1'B33/D3P3!D3!TA >or). #sing t&e '+,ect !avigator4 create a new P868*3T36 called 3*P1'B33SS!. T&is para)eter will auto)aticall2 +e assigned a value +ased on t&e para)eter list passed to t&e >or) +2 t&e a+ove 6#!GP6'D#-T procedure call. -reate a new trigger called WD3!=!3W=('6*=I!ST8!-3. T&is trigger will e:ecute w&enever t&e >or) is >irst run. DECLARE NP De=l,-e , 1o-m( 0lo=% >+e).>1e- PN 0l%&>+ Blo=%$ BE*IN NP O0.,>) .Be 0lo=% ID o1 .Be EMPLOYEE 0lo=%D TB>( >( .Be PN NP M,(.e- 0lo=% >) .Be emp+ep) m,(.e-N+e.,>l 1o-mD PN 0l%&>+ GJ F>)+&Blo=%(2EMPLOYEE2)$ IF NOT I+&N/ll(0l%&>+) THEN NP CBe=% .o m,%e (/-e o/- p,-,me.e- B,( , C,l/eD I1 .B>( 1o-m PN NP Fe-e eEe=/.e+ 0y >.(el1, .Be) .Be p,-,me.e- F>ll 0e )/llD PN NP I1 .B>( 1o-m >( =,lle+ 1-om EMPLOYEE .Be) .Be p,-,me.e- F>ll PN NP 0e p,((e+ ,lo)@ ,)+ ,((>@)e+ .o GPARAMETERDemployee(() PN IF (GPARAMETERDemployee(() >( )o. )/ll) THEN NP S>)=e Fe B,Ce , p,-,me.e-, /(e >. .o ,l.e- .Be ;HERE Cl,/(e PN NP p-ope-.y (o .B,. >. 0e=ome( ;HERE (()JGPARAMETERDemployee(() PN SET&BLOC'&PROPERTY(0l%&>+,DEFALT&;HERE,2(()J2 SS GPARAMETERDemployee(())$ NP N,C>@,.e .o .Be EMPLOYEE 0lo=% ,)+ eEe=/.e , O/e-y ,/.om,.>=,lly PN *O&BLOC'(2EMPLOYEE2)$ E"ECTE&:ERY$ END IF$ END IF$ END$
-o)pile and save t&e emp+ep) >or). !ow run t&e 3*P1'B33 >or)4 quer2 an e)plo2ee record and clic0 on t&e I9uer2 DependentsI +utton. T&e emp+ep) >or) s&ould appear wit& t&e dependents auto)atical2 queried. T&e a+ove e:a)ples are ,ust a >ew o> t&e great )an2 t&ings one can do wit& 'racle (or)s. T&e on=line &elp t&at s&ips wit& (or)s . contains )an2 e:a)ple >or)s and e:a)ple pieces o> code @see t&e (or)s P1/S91 6e>erenceA t&at go >ar +e2ond t&e si)ple tec&niques de)onstrated a+ove. -.4 !<ercise? Procedures and Tri**ers T&e >ollowing are so)e suggested e:ercises using various co)+inations o> triggers and procedures; -reate an 'racle Sequence @using S91CPlusA t&at will generate new Depart)ent nu)+ers >or t&e D3P86T*3!T ta+le. 8dd t&e requisite P63=I!S36T trigger code to insert a unique D!#*/36 eac& ti)e a new depart)ent record is created. -reate an alert t&at displa2s a warning i> an e)plo2eeFs salar2 is larger t&an t&eir supervisorFs. In a WD3!=?81ID8T3=IT3* trigger4 run a quer2 to c&ec0 i> t&e e)plo2eeFs salar2 is greater t&an t&eir supervisorFs and i> so4 s&ow t&e alert. Put in so)e validation code t&at will c&ec0 to )a0e sure i> a D3P3!D3!T is a S'! or D8#5DT364 t&en t&e D3P3!D3T!Fs /D8T3 )ust +e less t&an t&e 3*P1'B33Fs /D8T3. I> t&is is not t&e case4 s&ow an alert. 8>ter 2ou learn &ow to create 6eports @see t&e ne:t sectionA create a si)ple D3P86T*3!T data entr2 >or) wit& a +utton t&at4 w&en pressed4 will run a report >or t&at depart)ent +2 passing along t&e D!#*/36 as a para)eter. 11. Oracle Reports 9asics We now turn our attention to anot&er Developer tool called 'racle 6eports. T&e 'racle 6eports /uilder allows t&e developer to create sop&isticated reports in a variet2 o> la2outs and contains )an2 custo)iEation >eatures. In t&is section4 t&e +asic steps >or creating a si)ple report and a *aster=Detail report will +e given. 11.1 )tartin* Developer tools under +indo,s -./-0/#T/2111 8 t2pical installation o> Developer creates several >olders under t&e Start Progra)s )enu. T&e )ain ite)s >or t&e 'racle 6eports .i progra)s are >ound under t&e )enu ite); O-,=le Repo-.( 7> and include t&e >ollowing ite)s; To run 'racle 6eports /uilder under Windows 95/9/!T/2"""4 clic0 on t&e S.,-. 4? P-o@-,m( 4? O-,=le Repo-.( 7> 4? Repo-. B/>l+e- )enu ite). 8s wit& 'racle (or)s4 an initial screen will appear; -lic0 on t&e -ancel +utton to proceed directl2 to t&e '+,ect !avigator. 11.2 The Oracle Reports O$5ect #avi*ator T&e 'racle 6eports )ain screen is called t&e '+,ect !avigator @si)ilar to 'racle (or)sA and can +e seen in t&e >ollowing >igure; T&e )ain sections o> t&e '+,ect !avigator are; 1. Data "odel = -ontains in>or)ation a+out queries used >or a report. 2. &a%out = -ontains in>or)ation a+out &ow a report is >or)atted including &eaders4 >ooters4 )argins4 >onts4 etc. 3. Parameter Form = -ontains in>or)ation a+out t&e initial screen t&at is displa2ed w&en a >or) >irst runs. %. Report Tri**ers = P1/S91 code t&at can +e e:ecuted +e>ore4 during or a>ter a report &as +een e:ecuted. 8s wit& 'racle (or)s4 t&e >irst step in using 'racle 6eports is to -onnect to an 'racle server. T&is is acco)plis&ed +2 pulling down t&e F>le )enu and selecting t&e Co))e=. )enu ite). (ill in 2our 'racle #serna)e and 'racle Password @press t&e ta+ 0e2 to )ove +etween t&e >ieldsA. (or t&e D,.,0,(e >ield4 t2pe in t&e service na)e >or 2our 'racle data+ase. (or e:a)ple4 i> 2ou are using Personal 'racle 1ite4 t&e D,.,0,(eG would +e ODBCGPOLITE. -ontact 2our s2ste) ad)inistrator to learn t&e service na)e >or 2our 'racle data+ase and provide t&at in>or)ation in t&e D,.,0,(eG >ield. -lic0 on t&e Co))e=. +utton to co)plete t&e connection @#nder so)e versions o> #!I$4 t&e +utton is la+eled O'A. I> t&e user na)e or password is )ist2ped or incorrect4 t&e dialog +o: will +e re=displa2ed. /e sure to provide 2our 'racle userna)e and password @not 2our #!I$ &ost passwordA. 11.( Creatin* Reports in Oracle Reports -reating reports >ollows a % step process; 1. De>ine t&e Data *odel = T&is step speci>ies w&ic& queries s&ould +e run on t&e data+ase including &ow )ultiple queries are related and &ow t&e2 are grouped. T&is step )ust +e done +2 &and. 9ueries t&at &ave +een created elsew&ere can +e i)ported into 'racle 6eports. 2. De>ine t&e 1a2out = T&is step speci>ies t&e la2out o> t&e report including t&e overall orientation o> quer2 results and t&e suppression o> repeating groups. T&ere are a nu)+er o> de>ault report la2outs t&at can auto)aticall2 +e applied to a data )odel. 3. -reate and/or -usto)iEe t&e Para)eter (or) = I> so)e user input is required in order to run t&e report4 t&en a para)eter >or) )ust +e custo)iEed. 8ll reports &ave a de>ault para)eter >or). %. @optionalA -reate an2 triggers or progra) units t&at will +e e:ecuted wit& t&e report. 'racle 6eports 3." and .." support a wiEard t&at ta0es t&e developer t&roug& all o> t&ese steps. T&is approac& will +e de)onstrated ne:t. 11.4 Creatin* a )in*le7Ta$le Report In t&is section4 we go t&roug& t&e steps >or creating a report t&at views t&e contents o> a single ta+le. 11.4.1 )peci;% the Data "odel and &a%out T&e >irst step is to speci>2 t&e data )odel and la2out o> t&e report. We will use t&e 6eport wiEard to acco)plis& t&is. (ro) t&e '+,ect !avigator4 pull down t&e Tool( )enu and c&oose Repo-. F>H,-+DDD T&e >irst screen >or t&e reports wiEard will appear pro)pting >or t&e st2le o> t&e report and >or t&e 6eport Title. T&e eig&t la2out c&oices include; 1. Ta+ular = Si)ple ta+le wit& colu)n &eadings at t&e top and data records in consecutive rows +elow. 2. (or)=1i0e = -olu)n &eadings on t&e le>t &and side wit& data values ne:t to t&e) on t&e rig&t. 3. *ailing 1a+el = !o colu)n &eadings and records grouped into repeating sections siEed to print directl2 to a s&eet o> )ailing la+els. %. (or) 1etter = 8r+itrar2 place)ent o> data ite)s wit&in a te:t +od2. 5. 5roup=1e>t = 8 *aster/Detail/Detail st2le w&ere t&e )aster records are grouped on t&e le>t &and side wit& details to t&e rig&t. .. 5roup=8+ove = 8 *aster/Detail/Detail st2le w&ere t&e )aster records appear a+ove t&e detail records. <. *atri: = -olu)n la+els on +ot& t&e le>t and t&e top wit& data values in t&e )iddle. Si)ilar to a spreads&eet. . *atri: wit& 5roup = 8 co)+ination o> *aster/Detail @5roup=8+oveA and *atri:. (or t&is report4 t2pe in I3)plo2ee 6eportI as t&e title4 c&oose t&e Ta$ular 1a2out and clic0 on t&e !e:t +utton. T&e ne:t step is to speci>2 t&e T2pe o> quer2 t&e report will +e +ased on. T&e two )ain c&oices are a S91 quer2 and an 'racle 3:press @'18PA quer2. ('r t&is e:a)ple4 c&oose t&e IS91 State)entI and clic0 t&e ne:t +utton. T&e ne:t step is to speci>2 t&e quer2 t&at will >or) t&e +asis o> t&e report. In t&is case4 t2pe t&e >ollowing quer2 in t&e S91 9uer2 State)ent; te:t +o:; SELECT FNAME, LNAME, SSN, SALARY, DNO FROM EMPLOYEE $ T&en clic0 on t&e !e:t +utton to )ove to t&e ne:t step. !ote; I> 2ou did not -onnect to t&e data+ase4 2ou will +e pro)pted >or t&e #serna)e4 Password and Data+ase. In t&e ne:t wiEard dialog +o:4 speci>2 w&ic& colu)ns >ro) t&e S91 9uer2 will +e displa2ed in t&e report output. To speci>2 all colu)ns4 clic0 on t&e dou+le rig&t arrow to +ring all o> t&e -vailable Fields to t&e Dislayed Fields side. -lic0 on t&e !e:t +utton to )ove to t&e ne:t dialog +o:. In t&e ne:t step4 aggregate >unctions can +e applied to t&e >ields on t&e report. (or t&is e:a)ple4 we will displa2 t&e average salar2 as well as a count o> e)plo2ees. Dig&lig&t t&e S8186B >ield and clic0 on t&e -verage +utton. T&en &ig&lig&t t&e SS! >ield and clic0 on t&e Count +utton. T&e ne:t dialog +o: allows 2ou to c&ange t&e >ield la+els and displa2 widt&s >or various >ields in t&e report. 8s a >inal step4 a design te)plate can +e applied to t&e report. Design te)plates include speci>ications >or >onts4 colors and la2out o> t&e report. (or t&is e:a)ple4 c&oose t&e -orporate 2 te)plate and t&en clic0 on t&e (inis& +utton. 8>ter a s&ort dela24 t&e 6eports 1ive Previewer will appear s&owing t&e e:ecuting report. It is possi+le to )a0e c&anges to t&e la2out o> t&e report +2 using t&e tool palette on t&e le>t &and side. W&en 2ou &ave >inis&ed touc&ing up t&e report4 close t&e 6eports 1ive Previewer and t&e '+,ect !avigator will reappear. To view t&e report again4 pull down t&e P-o@-,m )enu and c&oose R/) Repo-.. 11.4.2 )avin*, Generatin* and Runnin* the Report To save a report4 pull down t&e F>le )enu and c&oose t&e S,Ce option. T&is is si)ilar to saving an 'racle (or). T&e source code >or 'racle 6eports are saved in >iles wit& an D-+1 >ile na)e e:tension. -o)piled and generated reports are saved wit& a D-ep e:tension. (or t&is e:a)ple4 save t&is report as employeeD-+1 'nce t&e report is saved4 it can +e run +2 pulling down t&e V>eF )enu and c&oosing t&e R/).>me P-eC>eF )enu ite). 8s t&e report is running4 an 8ctivit2 screen will appear giving an indication o> t&e processing t&at is currentl2 underwa2. T&e 8ctivit2 will go t&roug& 3 stages; -lient 8ctivit2 w&ile t&e queries are prepared4 Server 8ctivit2 w&en t&e queries are e:ecuted and >inall2 -lient 8ctivit2 as t&e report is >or)atted. W&en t&is is >inis&ed4 t&e report will appear on screen. 11.. !<ercise? Creatin* a Report (or t&is e:ercise4 create a report to displa2 all o> t&e records in t&e D3P86T*3!T ta+le including a ,oin wit& t&e 3*P1'B33 ta+le to displa2 t&e last na)e o> t&e depart)ent )anager. Start up t&e 6eport wiEard. #se IDepart)entsI as t&e title and enter t&e >ollowing S91 State)ent as t&e quer2; SELECT +)/m0e-, +),me, m@-(.,-.+,.e, m@-((), l),me FROM +ep,-.me)., employee ;HERE +ep,-.me).Dm@-(() J employeeD(()$ Su))ariEe t&e report wit& an average o> t&e Salar2 colu)n. Save t&e new report as +ep,-.m@D-+1 T&e >inis&ed report s&ould loo0 so)et&ing li0e t&e >ollowing; 11.8 Creatin* a "aster7Detail Report In t&is section4 t&e steps >or creating a report t&at views t&e contents o> two ta+les in a *aster=Detail @one to )an2A relations&ip are given. To avoid an2 con>usion4 Save and -lose an2 e:isting reports +e>ore proceeding. 11.8.1 )peci;% the "aster7Detail Data "odel and &a%out 8s in t&e single=ta+le report4 we +egin +2 speci>2ing t&e data )odel and la2out >or t&e *aster=Detail report +2 using t&e 6eport WiEard. Invo0e t&e wiEard +2 pulling down t&e Tool( )enu and c&oosing Repo-. F>H,-+. (ollowing t&ese steps to co)plete t&e wiEard; 1. (or t&e 6eport Title use; Depart)ents and 3)plo2ees 2. (or t&e )eort Style4 c&oose ,rou -bove. 3. -&oose a S91 State)ent and t&e S91 9uer2; 3D SELECT DNAME, FNAME, LNAME, SALARY 5D FROM DEPARTMENT, EMPLOYEE 7D ;HERE DEPARTMENTDDNMBER J EMPLOYEEDDNO
<. Designate t&e D!8*3 >ield as a ,rou field @1evel 1A. -lic0 on t&e D!8*3 >ield and t&en on t&e rig&t arrow +utton. . Displa2 all >ields in t&e report. 9. -&oose 8verage Salar2 as a (otals >ield. -lic0 on t&e S8186B >ield and t&en clic0 on t&e 8verage +utton. 1". Touc& up t&e >ields and la+els as >ollows; 11D F>el+( ,)+ To.,l( L,0el( 12D DNAME Dep,-.me). N,me 1!D FNAME F>-(. N,me 13D LNAME L,(. N,me 15D SALARY S,l,-y 17D AC@SALARYpe-DNAME ACe-,@eG 1#D AC@SALARYpe-Rep ACe-,@e Fo- ,ll Employee(G
1. #se t&e -orporate 2 te)plate. (ro) t&is point4 clic0 on (inis& to displa2 t&e 1ive 6eport Preview; 11.8.2 )avin*, Generatin* and Runnin* the "aster7Detail Report 8t t&is point4 t&e report can +e saved and 3:ecute @6unA. (or t&is e:a)ple4 save t&e *aster=Detail report as +ep.&empD-+1 11.G !<ercise? Creatin* a "aster7Detail Report In t&is e:ercise4 a )aster=detail report will +e created t&at displa2s eac& 3*P1'B33 record4 wit& a group o> D3P3!D3!T +elow. -reate a new 6eport using t&e wiEard. 5ive a title; I3)plo2ees and T&eir DependentsI Select t&e 5roup 8+ove report t2pe and use t&e >ollowing S91 quer2; SELECT employeeD1),me, employeeDl),me, employeeD0+,.e AS EmpB+,.e, employeeD(eE AS EmpSeE, +epe)+e).D+epe)+e).&),me, +epe)+e).D0+,.e AS DepB+,.e, +epe)+e).D(eE AS DepSeE, +epe)+e).D-el,.>o)(B>p FROM employee, +epe)+e). ;HERE employeeD(() J +epe)+e).De(()$ !ote t&e use o> colu)n aliases @8SA to di>>erentiate t&e +date and se: colu)ns. Select t&e l),me, 1),me, emp(eE, emp0+,.e >ields as t&e I5roup 1I >ields. T&ese s&ould all +e >ro) t&e 3*P1'B33 ta+le. Select all >ields to displa2 in t&e report and do not select an2 >ields >or t&e calculate totals step. Touc& up t&e report in t&e live previewer to >it on one screen. Save t&e report as >ile; emp+epe)D-+1 T&e report s&ould loo0 si)ilar to t&e >ollowing w&en co)pleted; 11.0 Parameter ;orms in Oracle Reports (or eac& o> t&e 'racle 6eports e:a)ples t&us >ar4 all o> t&e records in t&e respective ta+les were returned as part o> t&e report. Dowever4 t&ere )a2 +e situations w&ere onl2 a su+set o> t&e data+ase records are required. In t&ese cases4 we would li0e to pro)pt t&e user to enter so)e criteria t&at can +e used to >ilter t&e report. In 'racle 6eports4 a *arameter Form >ul>ills t&is role. Para)eter >or)s are si)ple 'racle >or)s t&at pro)pt t&e user >or so)e in>or)ation +e>ore a report is e:ecuted. T&is in>or)ation can +eco)e part o> t&e WD363 clause in t&e report quer2 and is used to >ilter t&e records returned in t&e report. Para)eters in 'racle 6eports can eit&er +e >illed in +2 t&e user on a para)eter >or) or can +e >illed in auto)aticall2 +2 passing t&e para)eters in >ro) anot&er 'racle (or)s >or) @see t&e e:a)ple o> para)eter passing in t&e previous section on 'racle (or)sA. In t&e >ollowing e:a)ple4 a si)ple para)eter >or) is auto)aticall2 created +2 'racle 6eports to restrict a quer2 on t&e 3*P1'B33 ta+le +2 s&owing onl2 e)plo2ees in a given depart)ent nu)+er @D!'A supplied +2 t&e user. 1. -reate a new report using t&e report wiEard. Speci>2 I3)plo2eesI as t&e report title and use a Ta+ular report la2out. 2. #se t&e >ollowing S91 quer2 e:actl2 as written. !ote t&e use o> t&e >ull colon in t&e WD363 clause. !D SELECT P 3D FROM employee 5D ;HERE employeeD+)o J GDNO&PARAMETER$ In t&e a+ove quer24 ;D!'GP868*3T36 is t&e na)e o> a run ti)e para)eter. W&en t&e report is e:ecuted4 t&e user will suppl2 a value >or t&is para)eter t&us co)pleting t&e WD363 clause >or t&e quer2. -lic0ing on t&e NeE. +utton will produce t&e >ollowing alert; .. -&oose all o> t&e colu)ns @>ieldsA >or displa2 in t&e report. Do not c&oose an2 >ields >or su))ar2 in>or)ation. <. W&en t&e report wiEard is >inis&ed4 t&e report and para)eter >or) @+ased upon t&e para)eters given in t&e S91 quer2A will +e created. 8s t&e live previewer is running4 t&e new para)eter >or) will +e displa2ed; (or t&is e:a)ple4 c&oose depart)ent 5 @t2pe t&e nu)+er 5 in t&e >ieldA and press t&e enter 0e2. !otice t&at onl2 e)plo2ees in depart)ent 5 are displa2ed in t&e live previewer. 11.0.1 9uildin* a Custom Parameter Form 8t t&is point4 w&enever t&e report is run4 a de>ault para)eter >or) s&owing t&e D!'GP868*3T36 will +e displa2ed. Dowever4 it is possi+le to create a custo) para)eter >or) as s&own in t&e >ollowing steps. 1. Switc& to t&e '+,ect !avigator4 pull down t&e Tool( )enu and c&oose t&e P,-,me.e- Fo-m B/>l+e-. T&is is s&own +elow; 8 nu)+er o> +uilt=in s2ste) para)eters are displa2ed and can +e &ig&lig&ted +2 clic0ing on t&e) wit& t&e rig&t )ouse +utton. !ote t&at at t&e +otto) o> t&is list is t&e D!'GP868*3T36 and it s&ould alread2 +e selected. 2. (or t&is e:a)ple4 in addition to t&e D!'GP868*3T36 also select t&e D3STBP34 D3S!8*3 and -'PI3S para)eters. T&en clic0 t&e O' +utton. 8 new para)eter >or) will +e auto)aticall2 created as s&own +elow. 3. Save t&e report as empp,-,mD-+1. W&en t&e >or) is e:ecuted @pull down t&e P-o@-,m )enu and c&oose R/) Repo-.A4 t&e new para)eter >or) will +e displa2ed as s&own +elow; In t&e a+ove e:a)ple4 1 cop2 o> t&e report will +e sent to t&e printer na)ed IDP 1aser7et Series III. T&e report will onl2 s&ow e)plo2ees in depart)ent %. 't&er Destination T2pe options include Screen4 (ile and 3=)ail. Para)eter >or)s can +e &ig&l2 custo)iEed to include list o> values user pro)pts and ot&er user=>riendl2 >eatures. T&e tec&niques used >or 'racle (or)s can +e easil2 applied to para)eter >or)s in 'racle 6eports. 11. Creatin* "enus in Oracle Forms !ote; T&e properties >or *enus in di>>erent versions o> (or)s see) to c&ange wit& ever2 )inor revision. Please 0eep in )ind4 t&e version o> (or)s 2ou are wor0ing wit& )a2 di>>er slig&tl2 >ro) w&at is s&own in t&is tutorial. T&us >ar4 we &ave covered t&e +asics >or creating >or)s and reports using 'racle Developer. So)e advanced >eatures suc& as using stored procedures @Progra) #nitsA &ave also +een introduced. In a co)plete Data+ase S2ste)4 t&e applications consist o> )an2 >or)s and reports t&at )ig&t +e used +2 a nu)+er o> users. 8ccess to >or)s and reports is t2picall2 acco)plis&ed t&roug& menus. In 'racle Developer4 )enus can +e created to guide users into >or)s and reports o> interest. *enus are designed as part o> t&e 'racle (or)s designer. In 'racle (or)s4 ever2 >or) runs wit& one o> t&e >ollowing; 1. T&e de>ault )enu w&ic& includes t&e 8ction4 3dit4 /loc04 (ield4 6ecord4 9uer24 Window4 Delp )enus. T&e structure o> t&e de>ault )enu cannot +e c&anged. 2. 8 custo) )enu t&at 2ou de>ine as a separate )odule and t&en attac& to t&e >or) >or runti)e e:ecution. 3. !o )enu at all. T&e de>ault )enu is part o> t&e >or) )odule. Dowever4 custo) )enu )odules are separate >ro) >or) )odules. So4 w&en a single=>or) application runs using a custo) )enu4 t&ere will +e two e:ecuta+le >iles; an DFM" >or) )odule an DMM" )enu )odule In a )ulti=>or) application4 *ultiple >or)s can s&are t&e sa)e )enu4 or eac& >or) can invo0e a di>>erent )enu. To e:plicitl2 speci>2 t&e de>ault )enu in (or)s .i; 1. Select t&e na)e o> t&e >or)/)odule in t&e '+,ect !avigator. -lic0 wit& t&e rig&t )ouse +utton and c&oose P-ope-.>e( >ro) t&e pop=up )enu. 2. In t&e "enu "odule propert24 t2pe D3(8#1TMS*86T/86 to get t&e de>ault )enu and a +utton +ar +elow it. I> 2ou want t&e >or) to run wit&out a )enu4 leave t&e "enu "odule propert2 +lan0. To e:plicitl2 speci>2 t&e de>ault )enu in older versions o> Developer; 1. Select t&e na)e o> t&e >or)/)odule in t&e '+,ect !avigator. -lic0 wit& t&e rig&t )ouse +utton and c&oose P-ope-.>e( >ro) t&e pop=up )enu. 2. In t&e "enu "odule propert24 t2pe D3(8#1T. I> 2ou want t&e >or) to run wit&out a )enu4 leave t&e "enu "odule propert2 +lan0. T&e de>ault )enu is suita+le >or control over t&e current >or) +eing e:ecuted4 &owever4 it does not contain custo) )enu ite)s pertaining to a speci>ic application. In t&e >ollowing section4 t&e steps to create a custo) )enu structure will +e introduced. 11.1 The Oracle Forms "enu Bierarch% T&e 'racle (or)s )enu &ierarc&2 contains t&ree o+,ect categories; 1. "enu modules = 1i0e >or) )odules4 a )enu )odule can contain its own ite)s @)enus and )enu ite)sA4 progra) units and ot&er o+,ects. 2. "enus = Including )ain )enus4 individual )enus4 and su+)enus 3. "enu items 11.2 Creatin* a Custom "enu Designing a custo) )enu requires >ive +asic steps; 1. -reating a )enu )odule 2. -reating )enus and )enu ite)s 3. 8ssigning co))ands to )enu ite)s %. Saving and generating t&e )enu )odule 5. 8ttac&ing a )enu )odule to a >or) 11.2.1 Creatin* a "enu "odule T&e >irst step in designing a custo) )enu is to create a )enu )odule. T&ere are several wa2s to create a new )enu )odule; 1. Pull down t&e F>le )enu4 &ig&lig&t t&e NeF )enu ite) and t&en select t&e Me)/ )enu ite). 2. !avigate down to t&e "enus su+tree in t&e '+,ect !avigator4 pull down t&e N,C>@,.o- )enu and c&oose t&e C-e,.e )enu ite). 8 new )enu )odule will +e created and a de>ault na)e will +e assigned. -lic0 on t&is de>ault )enu na)e and assign it a )ore )eaning>ul na)e suc& as myme)/. 11.2.2 Creatin* menus and menu items -reating )enus and )enu ite)s can +e acco)plis&ed using t&e "enu !ditor. To activate t&e )enu editor4 >irst &ig&lig&t t&e na)e o> 2our )enu4 t&en pull down t&e Tool( )enu and clic0 on t&e Me)/ E+>.o- ite). T&e )ain )enu ite)s go across t&e top o> t&e screen. To add a new )enu across t&e top4 clic0 on t&e 9uild Across icon on t&e tool+ar; Su+=)enus and )enu ite)s appear +elow eac& one. To add a new su+=)enu or )enu ite)4 clic0 on t&e 9uild Do,n icon on t&e tool+ar; To c&ange t&e na)e o> a )enu or )enu ite)4 clic0 in t&e )enu o+,ect and over=write t&e na)e t&at appears t&ere. #sing t&e icons4 create and re=la+el several )enus and )enu ite)s to appear as >ollows; 'nce t&is is co)pleted4 t&e +asic )enu structure will +e in place. T&e ne:t step is to add >unctionalit2 to eac& )enu ite). 11.2.( Assi*nin* Commands to "enu Items T&e de>ault +e&avior >or clic0ing on an2 )enu is >or t&at )enuFs ite)s to +e displa2ed. T&e ne:t step is to assign co))ands to eac& o> t&e )enu ite)s so t&at w&en a user clic0s on a )enu ite)4 a >or)4 report or S91CPlus script is e:ecuted. To assign a co))and to a )enu ite); 1. Select t&e desired )enu ite) in t&e *enu 3ditor. -lic0 wit& t&e rig&t )ouse +utton and c&oose P-ope-.>e( to +ring up t&e properties o> t&at )enu ite). !ote; T&e pop=up )enu )a2 s&ow P-ope-.y P,le..e 2. T&e properties o> interest &ere are; o Command t%pe? Indicates w&at 0ind o> co))and s&ould +e run; (or)4 6eport4 P1/S914 ot&er )enu. In general4 t&e P1/S91 co))and t2pe is used to launc& 'racle (or)s and 'racle 6eports. T&e speci>ic (or) and 6eport co))and t2pes are )aintained >or +ac0wards co)pati+ilit2 onl2. o "enu Item Code @or Command Te<tA; T&e te:t o> t&e actual co))and to run. To run a >or) >ro) t&e )enu ite)4 c&oose Command T%pe P1/S91. Dou+le clic0 on t&e "enu Item Code @or Command Te<tA propert2 and t2pe in t&e P1/S91 editor; BE*IN RN&PRODCT(FORMS, 2employee2, SYNCHRONOS, RNTIME, FILESYSTEM, 22, 22)$ END$
6#!GP6'D#-T is a P1/S91 +uilt=in >unction t&at runs anot&er 'racle Developer product. T&e para)eters to 6#!GP6'D#-T are; o Product; ('6*S or 63P'6TS o Docu)ent/*odule; na)e o> t&e >ile in single quotes o -o))and *ode; SB!-D6'!'#S or 8SB!-D6'!'#S o 3:ecuta+le *ode; 6#!TI*3 o 1ocation; (I13SBST3* or D8T8/8S3 o Para)eter 1ist; 8 list o> para)eters to pass to t&e >or) or !#11 o Displa2; T2pe o> displa2 to s&ow t&e product on. -an +e !#11 to indicate t&e current displa2. !ote; Starting wit& (or)s 5."4 @w&ic& uses P1/S91 version 2.3A 2ou )a2 not use !#11 in t&e call to 6#!GP6'D#-T &ere. Bou )ust use two single quotes @indicating a Eero lengt& c&aracter stringA. -o)pile t&is code +2 clic0ing on t&e Comp>le +utton. T&en close t&e P1/S91 editor. 6epeat t&e a+ove steps >or eac& )enu ite). 8 >inal )enu ite) s&ould +e created to 3:it t&e application. -all t&e )enu; !<it Application and enter t&e >ollowing P1/S91 code; BE*IN E"IT&FORM$ END$ 3$ITG('6* is a +uilt=in procedure t&at e:its t&e current >or). 8 ?iew o> t&e co)plete myme)/ is s&ow +elow; 11.2.4 )ave and Generate the "enu "odule 8t t&is point4 all o> t&e )enu structure &as +een created and co))ands >or eac& )enu ite) &ave +een speci>ied. T&e )enu )odule )ust now +e saved to a >ile @wit& a Dmm0 e:tensionA and 5enerated or -o)piled. To save t&e )enu )odule4 )a0e sure t&e na)e o> t&e )enu is &ig&lig&ted4 pull down t&e (ile )enu and c&oose t&e S,Ce )enu ite). Speci>2 a >ile na)e wit& a Dmm0 e:tension. T&is is t&e Isource codeI >or t&e )enu. (or t&is e:a)ple4 use t&e >ile na)e myme)/Dmm0. To generate or co)pile t&e )enu )odule4 pull down t&e F>le )enu4 clic0 on t&e A+m>)>(.-,.>o) )enu ite) and c&oose *e)e-,.e >ro) t&e >l2out )enu. In so)e versions o> t&e (or)s /uilder4 t&e )enu ite) )ig&t +e called Comp>le F>le. 5enerating or co)piling a )enu )odule results in a >ile wit& a DmmE e:tension. In t&is e:a)ple4 t&e generated )enu )odule +eco)es; myme)/DmmE 11.2.. Attachin* a "enu "odule to a Form 8 custo) )enu )ust +e attac&ed to a >or) in order to +e displa2ed. T2picall24 a >or) wit& no data entr2 on it is used as t&e )ain screen to &ost t&e custo) )enu. T&e >ollowing steps are di>>erent depending on t&e version o> (or)s +eing used. For Oracle Forms version 4.. For Oracle Forms version 8i 1. -reate a new >or) wit& no +loc0s or ite)s on it. Pull down t&e F>le )enu4 select NeF and t&en select Fo-m. 2. Displa2 t&e properties >or t&e >or) and set t&e "enu "odule propert2 to t&e >ile na)e o> t&e )enu )odule @see previous stepA. (or t&is e:a)ple4 it s&ould +e; myme)/DmmE 3. *a0e sure t&e 2se File propert2 is set to T-/e. %. Save t&e >or) as >ile 0l,)%1o-mD1m0 and generate t&is >or). @!ote 2ou s&ould save t&e t&is >or) in t&e sa)e 1. -reate a new >or) wit& no +loc0s or ite)s on it. Pull down t&e F>le )enu4 select NeF and t&en select -lic0 on t&e na)e o> t&e >or) in t&e o+,ect navigator and rena)e it as 0l,)%1o-m. 2. 'pen up t&e propert2 palette >or t&e >or) and set t&e >ollowing properties; "enu )ource; (ile = T&e )enu in>or)ation will co)e >ro) a >ile. "enu "odule; myme)/DmmE = T&e >ile na)e o> t&e co)piled )enu )odule. Bou )a2 &ave to give t&e e:plicit pat& to t&is DmmE >ile. (or e:a)ple4 i> t&is >ile is on 2our 8; drive t&en t2pe ,GImyme)/DmmE drive and director2 as 2our )enuFs DmmE >ileA. 5. 6un t&e >or). 3. Save t&e >or) as >ile 0l,)%1o-mD1m0 >or). @!ote 2ou s&ould save t&e t&is >or) in t&e sa)e drive and director2 as 2our )enuFs %. 6un t&e >or). !otice t&at w&en running t&is +lan0 >or)4 t&e de>ault )enu is replaced +2 t&e myme)/ *enu *odule. T&e +lan0 >or) t&at is used to &ost t&e )enu need not +e +lan0. Bou )a2 wis& to use t&e 1a2out 3ditor to place so)e grap&ics and a title o> t&e application on t&e canvas. 8not&er use >or t&is space would +e >or so)e si)ple instructions t&e user can read to get started wit& t&e data+ase application. 12.1 Graphics and the Chart +i>ard T&e 'racle 5rap&ics Designer can +e used to create a variet2 o> grap&s and c&arts including +ar c&arts4 line plots and pie grap&s. T2picall24 a grap&ic o+,ect designed wit& 'racle grap&ics is included on eit&er a >or) or a report. T&e 'racle (or)s Designer includes a wiEard t&at will auto)aticall2 construct an 'racle grap&ic o+,ect using data >ro) an e:isting data +loc0. 12.1 Addin* a Chart to a Form In t&e >ollowing e:a)ple4 an 'racle 5rap&ics o+,ect will +e added to a +asic *aster/Detail >or). 8s a >irst step4 create a new *aster/Detail >or) using t&e D3P86T*3!T ta+le @D!#*/36 and D!8*3 colu)nsA as t&e )aster +loc0 and t&e 3*P1'B33 ta+le @(!8*34 1!8*34 D!' and S8186B colu)nsA as t&e detail +loc0. T&e c&art added to t&is >or) will co)pare t&e S8186B values o> t&e e)plo2ees in a given depart)ent. 8n e:a)ple la2out is s&own +elow @note t&e D!' colu)n in t&e 3*P1'B33 +loc0 is not displa2edA; /e sure to save t&is >or) on dis0 +e>ore )oving on to create t&e c&art. To start t&e -&art WiEard4 clic0 on an2 open area o> t&e >or) w&ile in t&e la2out view. T&en pull down t&e Tool( )enu and c&oose t&e CB,-. ;>H,-+. T&e >irst screen o> t&e -&art WiEard will appear as +elow; -lic0 t&e NeE. +utton to )ove to t&e ne:t step in t&e wiEard. In t&e ne:t step4 c&oose t&e t2pe o> c&art @and su+t2pe i> applica+leA to +e created. (or t&is e:a)ple4 c&oose P>e and Dep.B as s&own +elow and clic0 on t&e NeE. +utton; T&e ne:t step is to c&oose w&ic& data +loc0 t&e c&art s&ould +e +ased on. 8ll o> t&e data +loc0s on t&e current >or) s&ould +e displa2ed. (or t&is e:a)ple4 c&oose t&e 3*P1'B33 +loc0 as s&own +elow and clic0 on t&e NeE. +utton; T&e ne:t step is to c&oose w&ic& >ield in t&e data +loc0 s&ould +e used >or t&e $=8:is @or categor2 la+elsA >or t&e c&art. (or t&is e:a)ple4 c&oose t&e 1!8*3 >ield as s&own +elow and clic0 on t&e NeE. +utton; T&e ne:t step is c&oose w&ic& >ield in t&e data +loc0 s&ould +e used as t&e B=8:is values. (or t&is e:a)ple4 c&oose t&e S8186B >ield as s&own +elow and clic0 on t&e NeE. +utton; In t&e last step >or t&e wiEard4 t&e new 'racle 5rap&ics o+,ect )ust +e saved in a >ile. 5ive a new na)e >or t&e grap&ics o+,ect suc& as employeeDo@+ as s&own +elow and clic0 on t&e F>)>(B +utton; 8t t&is point4 t&e grap&ics o+,ect will +e created and placed on t&e >or). #se t&e )ouse to )ove and re=siEe t&e o+,ect as desired. W&en >inis&ed4 save t&e >or) again and run it. T&e >ollowing >igure s&ows t&e >or) as it is running. !otice t&at w&en t&e >or) is queried and as new depart)ent records are retrieved4 t&e e)plo2ees and t&eir associated salaries >or t&at depart)ent are displa2ed in t&e pie c&art. W&en cop2ing >or)s >iles t&at use 'racle 5rap&ics4 +e sure to also cop2 t&e associated grap&ics o+,ect >iles. T&ese >iles t2picall2 &ave an DO*D >ile e:tension. 12.2 !<ercise? Addin* a Chart to a Report (or t&is e:ercise4 add a +ar c&art depicting t&e e)plo2ees salaries to a report s&owing additional 3)plo2ee data. Start +2 creating a +asic ta+ular 6eport )a0ing use o> t&e >ollowing quer2; SELECT FNAME, LNAME, DNO, SALARY FROM EMPLOYEE T&e +asic report is s&own +elow; !e:t4 add t&e -&art using t&e -&art wiEard. Speci>2 ISalariesI as t&e c&art title4 and use a /ar c&art st2le wit& IDept&I as t&e su+=t2pe. (or t&e $ 8:is4 c&oose 1!8*3 and >or t&e B 8:is c&oose S8186B. -&oose to place t&e c&art at t&e end o> t&e report and give t&e c&art o+,ect t&e na)e Irepsal.ogdI. I)portant; *a0e sure t&at t&e c&art o+,ect @t&e .ogd >ileA and t&e report >ile are in te& sa)e director2. /2 de>ault c&art o+,ects )a2 +e stored in anot&er location. I> t&e2 are not toget&er4 2ou will get an error suc& as I6eports is una+le to >ind t&e c&art o+,ectI. /elow is t&e >inal output o> t&e report wit& t&e e)+edded 'racle 5rap&ics c&art o+,ect; 1(. Oracle )chema 9uilder T&e 'racle Sc&e)a /uilder provides an eas2 to use grap&ical user inter>ace >or de>ining and )odi>2ing ta+les4 views and ot&er sc&e)a o+,ects. To run t&e Sc&e)a /uilder4 c&oose it >ro) t&e 'racle )enu. 8s wit& )ost 'racle develop)ent tools4 t&e >irst step will +e to connect to t&e data+ase. T&e -onnect dialog +o: will appear as +elow; Provide a valid userna)e4 password and connect string @Dost stringA and clic0 on t&e Co))e=. +utton to esta+lis& a connection to t&e data+ase. T&e )ain Sc&e)a /uilder screen will appear; 1(.1 Creatin* #e, )chema O$5ects -reating a new ta+le is a straig&t >orward process. (irst4 pull down t&e S=Bem, )enu and c&oose t&e C-e,.e T,0le )enu ite). 8 s)all )enu will appear. -&oose T,0le. T&e )ouse pointer will c&ange to an arrow wit& a M sign. -lic0 in t&e open space o> t&e Sc&e)a /uilder )ain screen and t&e new ta+le will +e created. !ote t&at t&e new ta+le is given a de>ault na)e @TABLE1A and it contains several e:a)ples colu)ns. To c&ange t&e na)e o> t&e ta+le4 clic0 on t&e current na)e and t2pe over it wit& a new na)e. Do not use spaces in t&e ta+le na)e. W&en >inis&ed4 press 3nter or 6eturn to set t&e new na)e >or t&e ta+le. To c&ange t&e na)e o> a colu)n4 clic0 on a colu)n na)e and t2pe over t&e e:isting na)e. To add )ore colu)ns to t&e ta+le4 si)pl2 clic0 t&e lower rig&t &and corner o> t&e ta+le displa2 and drag it downwards. 8dditional colu)ns will appear wit& t&eir de>ault na)es. To c&ange t&e data t2pe and ot&er c&aracteristics o> colu)ns4 dou+le clic0 on t&e colu)n na)e. T&e De>ine -olu)n dialog +o: will appear. Dig&lig&t t&e colu)n 2ou wis& to )odi>2 and c&ange its datat2pe and ot&er options on t&e rig&t &and side. In t&e >igure +elow4 t&e !8*3 colu)n &as +een c&anged to ?86-D86@2"A and a !'T !#11 constraint &as +een added +2 c&ec0ing o>> t&e ReO/>-e+ c&ec0+o:. In t&e >ollowing >igure4 t&e -#ST'*36ID colu)n &as +een designated as t&e 0e2 +2 c&ec0ing o>> t&e P->m,-y 'ey and )>O/e c&ec0 +o:es. In t&e >ollowing >igure4 eac& o> t&e colu)ns in t&e -#ST'*36 ta+le &ave +een de>ined; 'nce eac& o> t&e colu)ns &as +een rena)ed and de>ined4 t&e ta+le )ust +e saved in t&e data+ase. To see t&e S91 state)ents t&at will +e sent to t&e data+ase server4 pull down t&e S=Bem, )enu and c&oose t&e SBoF S:L )enu ite). 8t t&is point4 t&e S91 state)ents t&at will +e used to create t&e sc&e)a can +e saved into a te:t >ile >or >uture use. To save t&e S91 state)ents4 pull down t&e F>le )enu and c&oose S,Ce S:L. 8 standard windows >ile save dialog +o: will appear. T&e de>ault >ile e:tension >or S91 >iles is D(Ol To co))it t&e sc&e)a in t&e data+ase4 eit&er clic0 on t&e Comm>. +utton in t&e SBoF S:L dialog +o: or4 >ro) t&e )ain Sc&e)a /uilder screen4 pull down t&e S=Bem, )enu and c&oose t&e Comm>. S=Bem, )enu ite). 8 dialog +o: will appear s&owing t&e progress. To review4 a t2pical Sc&e)a /uilder session would consist o> adding new ta+les to a sc&e)a using t&e C-e,.e T,0le )enu ite) on t&e S=Bem, me)/. -olu)ns in ta+les can +e de>ined +2 dou+le clic0ing on t&e ta+le icons. 'nce all o> t&e ta+les &ave +een de>ined in t&e Sc&e)a /uilder )ain screen4 save o>> t&e S91 to a >ile and t&en co))it t&e sc&e)a in t&e data+ase. 1(.2 Displa%in* !<istin* )chema O$5ects I> t&e sc&e)a &as so)e ta+les or views alread2 de>ined4 t&ese can +e displa2ed +2 pulling down t&e D,., )enu and c&oosing t&e Sele=. D,., T,0le( )enu ite). 8 dialog +o: will appear displa2ing t&e availa+le ta+les. To include a ta+le in t&e Sc&e)a /uilder )ain screen4 &ig&lig&t a ta+le and clic0 on t&e I)=l/+e +utton. T&e ta+le s&ould appear on t&e )ain screen and t&e na)e o> t&e ta+le will +e gra2ed out in t&e dialog +o:. In t&is e:a)ple4 t&e 3*P1'B33 and D3P86T*3!T ta+les were included in t&e )ain screen. W&en all o> t&e desired ta+les &ave +een displa2ed4 clic0 on t&e Clo(e +utton to close t&e dialog +o:. /elow is t&e resulting )ain screen a>ter t&e 3*P1'B33 and D3P86T*3!T ta+les were added; 1(.( Addin* Relationships $et,een Ta$les 'nce t&e ta+les &ave eit&er +een created or displa2ed in t&e Sc&e)a /uilder )ain screen4 relations&ips +etween ta+les can +e de>ined. In t&is e:a)ple4 t&e D!#*/36 colu)n o> t&e D3P86T*3!T ta+le is related to t&e D!' colu)ns in t&e 3*P1'B33 ta+le. T&e D!#*/36 colu)n in D3P86T*3!T )ust +e de>ined as a Pri)ar2 He2. To create t&e appropriate constraints >or t&is relations&ip4 pull down t&e S=Bem, )enu and c&oose t&e De1>)e Rel,.>o)(B>p )enu ite). 8 dialog +o: will appear wit& spaces >or t&e (oreign He2 and Pri)ar2 He2. (ill t&ese in as appropriate >or t&e relations&ip. In t&is e:a)ple4 t&e (oreign He2 is 3*P1'B33.D!' and t&e Pri)ar2 He2 is D3P86T*3!T.D!#*/36 as s&own in t&e >igure +elow; -lic0 t&e O' +utton to con>ir) t&e relations&ip. T&e displa2 will t&en c&ange. 8 line will appear lin0ing t&e Pri)ar2 He2 and (oreign He2s. 'nce again4 Sc&e)a /uilder provides a view o> t&e S91 t&at will +e used to create t&e (oreign 0e2 constraints t&at will i)ple)ent t&e relations&ip in t&e data+ase sc&e)a. To see t&e S914 pull down t&e S=Bem, )enu and c&oose t&e SBoF S:L )enu ite). 8s +e>ore4 t&e S91 state)ents to create t&e >oreign 0e2 constraints can +e saved to a >ile using t&e F>le )enu and S,Ce S:L )enu ite). (inall24 to co))it t&e c&anges to t&e data+ase4 pull down t&e S=Bem, )enu and c&oose t&e Comm>. S=Bem, )enu ite). T&e ne:t ti)e +ot& D3P86T*3!T and 3*P1'B33 are displa2ed in Sc&e)a /uilder4 t&e relations&ip will auto)aticall2 appear.