Академический Документы
Профессиональный Документы
Культура Документы
DE"LAE
return4alert !.M#E2
#E6,!
,( ':-.PE--! K :--!* T)E!
return4alert :K -)O?4ALET ':-.PEV,-O4ALET:*2
A,-E (OM4T,66E4(A,L.E2
E!D ,(2
E!D2
The SBOWF=+-0T procedure calls up the speci7ied alert and o$tains
the return value ;$ased on the $utton the user clic*s on< to assign to a
local varia$le called return4alert.
"elow is an e3a!ple o7 the =lert in action4
In general. =lerts !a, provide several di77erent $uttons 7or the user to clic* on.
or e3a!ple. to con7ir! e3iting a 7or!. a POST6O0# trigger !ight invo*e
an H=re ,ou sure ,ou want to -3itH =lert with H?esH and H&oH $uttons. Or. to
con7ir! deleting a record. a P0-6'O##IT trigger !ight invo*e an H=re ,ou
sure ,ou want ot delete this -!plo,eeOH =lert with H?esH and H&oH $uttons.
"ased on the returnFalert value. either a co!!it or roll$ac* !ight $e issued.
9)-). Automatic Forms 1uer0
=s discussed earlier in the tutorial. $, de7ault. when a 7or! runs. the underl,ing
ta$le data is not auto!aticall, queried and displa,ed. It is up to the user to
e3ecute a quer,. 7or e3a!ple. $, pulling down the quer, !enu and choosing
-3ecute.
To auto!ate this process. create a WB-&6&-W6O0#6I&ST=&'- trigger
that navigates to the !aster data $loc* and then issues the -G-'8T-F28-0?
$uilt6in procedure. or e3a!ple. assu!ing the !aster $loc* is na!ed
H-#P+O?--H. the 7ollowing code will cause a quer, to $e e3ecuted
i!!ediatel, a7ter the 7or! opens4
#E6,!
6O4#LO"5':EMPLOYEE:*2
E0E".TE4>.EY2
E!D2
9)-); #opulate items wit$ default values
There are !an, cases where de7ault values can $e suggested 7or certain data
ite!s $ased upon values alread, supplied in other data ite!s. The !ethod here
is to use a POST6IT-# or WB-&6:=+ID=T-6IT-# trigger to populate
another 7ield. onl, i7 the other 7ield is currentl, $lan*. or e3a!ple. to populate
the S8P-0SS& data ite! o7 the -#P+O?-- $loc* $ased upon the #/0SS&
o7 the e!plo,eeEs depart!ent. the 7ollowing WB-&6:=+ID=T-6IT-# trigger
code !ight $e used on the D&O data ite!4
#E6,!
,( :-.PE--! ,- !.LL T)E!
-ELE"T 7e%art$ent.$Frssn
,!TO :e$%lo&ee.su%erssn
(OM 7e%art$ent
?)EE 7e%art$ent.7nu$8er K :e$%lo&ee.7no2
E!D ,(2
E!D2
&ote that the I state!ent uses :-.PE--! ,- !.LL to chec* to see i7 an, value
has $een supplied 7or S8P-0SS&. I7 nothing was t,ped into the S8P-0SS&
data ite!. then its value is &8++. I7 the user t,pes an,thing at all into the
S8P-0SS& data ite!. then the I state!ent will evaluate to 7alse and no value
will $e suggested.
9)-)C Attac$ing functionalit0 to command 5uttons
'o!!and $uttons can $e added on a 7or! to carr, out 7unctions such as e3iting
a 7or!. co!!itting1saving changed records and so on. The $asic co!!and
$utton o$%ect contains properties 7or the $utton +a$el ;the te3t provided on the
$utton itsel7<. =dditional properties include visual attri$utes including the
a$ilit, to displa, a $it!ap i!age in place o7 the $uttonEs nor!al appearance.
Once a $utton has $een ph,sicall, placed on a 7or!. 7unctionalit, is added $ut
writing a ?)E!-#.TTO!-PE--ED trigger. =s one !ight e3pect. this trigger
e3ecutes when the user clic*s on the $utton. So. 7or e3a!ple. to create a $utton
to e3it the 7or! when the user clic*s on it the ?)E!-#.TTO!-PE--ED trigger
!ight loo* li*e4
DE"LAE
return4alert !.M#E2
#E6,!
return4alert :K -)O?4ALET ':E0,T4ALET:*2
,( 'return4alert K alert48uttin1* T)E!
E0,T4(OM2
E!D ,(2
E!D2
The a$ove code assu!es there is an =lert called -GITF=+-0T with two
$uttons4 H?esH and H&oH. I7 the user clic*s on the 7irst $utton ;H?esH< then the
-GITFO0# procedure is called and the 7or! will e3it ;close<. I7 the user
clic*s on an, other $utton. then the =lert will close and the 7or! will re!ain
open.
9)-)D #assing parameters 5etween forms
There are !an, occasions that require the passing o7 data 7ro! one 7or! to
another. One such e3a!ple is when we quer, a certain record on one 7or! and
then wish to call up another 7or! with the sa!e record auto!aticall, retrieved.
In general. data values can $e passed $etween 7or!s using /+O"=+ varia$les
;treat 4/+O"=+ as a $loc* availa$le in all 7or!s< or $, using Para!eter lists.
In the e3a!ple. $elow. the para!eter list 7eatures will $e used to de!onstrate
how data can $e passed 7ro! one 7or! to another.
or this e3a!ple. we wil !a*e use o7 two 7or!s4 = $asic -#P+O?-- 7or!
with all 7ields and the -#P+O?--1D-P-&D-&T !aster1detail 7or! ;created
in aprevious e3ercise 6 the 7ile na!e should have $een e$%7e%n.9$8<. The idea
is to place to $utton on the -#P+O?-- 7or! that when pressed. will call the
-#P+O?--1D-P-&D-&T 7or! and auto!aticall, quer, the dependents 7or
the e!plo,ee $eing viewed on the -#P+O?-- 7or!. The !ain steps are4
On the -#P+O?-- 7or!. create a $utton and la$el it H2uer,
DependentsH.
'reate a WB-&6"8TTO&6P0-SS-D trigger with the 7ollowing code
;co!!ents are enclosed in the code<4
DE"LAE
-- DeBlare %l4i7 as tAe i7enti9ier 9or tAe %ara$eter list
%l4i7 Para$List2
#E6,!
-- -ee i9 tAat %ara$eter list alrea7& eHists. ,9 so+ 7estro& it
%l4i7 :K 6et4Para$eter4List':t$%7ata:*2
,( !OT ,74!ull'%l4i7* T)E!
Destro&4Para$eter4List' %l4i7 *2
E!D ,(2
-- "reate a 9resA %ara$eter list O/
%l4i7 :K "reate4Para$eter4List':t$%7ata:*2
DE"LAE
-- DeBlare a 9or$s 8loB3 i7enti9er
8l34i7 #loB32
#E6,!
-- O8tain tAe 8loB3 ,D o9 tAe EMPLOYEE 8loB3. TAis is tAe
-- Master 8loB3 in tAe e$%7e%n $aster/7etail 9or$.
8l34i7 :K (in74#loB3':EMPLOYEE:*2
,( !OT ,74!ull'8l34i7* T)E!
-- "AeB3 to $a3e sure our %ara$eter Aas a Galue. ,9 tAis 9or$
-- Cere eHeBute7 8& itsel9+ tAen tAe %ara$eter Cill 8e null.
-- ,9 tAis 9or$ is Balle7 9ro$ EMPLOYEE tAen tAe %ara$eter
Cill
-- 8e %asse7 alonF an7 assiFne7 to :PAAMETE.e$%lo&eessn
,( ':PAAMETE.e$%lo&eessn is not null* T)E!
-- -inBe Ce AaGe a %ara$eter+ use it to alter tAe ?)EE
"lause
-- %ro%ert& so tAat it 8eBo$es ?)EE
ssnK:PAAMETE.e$%lo&eessn
-ET4#LO"54POPETY'8l34i7+DE(A.LT4?)EE+:ssnK: RR
:PAAMETE.e$%lo&eessn*2
-- !aGiFate to tAe EMPLOYEE 8loB3 an7 eHeBute a Nuer&
auto$atiBall&
6O4#LO"5':EMPLOYEE:*2
E0E".TE4>.EY2
E!D ,(2
E!D ,(2
E!D2
'o!pile and save the e$%7e%n 7or!.
&ow run the -#P+O?-- 7or!. quer, an e!plo,ee record and clic* on
the H2uer, DependentsH $utton. The e$%7e%n 7or! should appear with
the dependents auto!atical, queried.
The a$ove e3a!ples are %ust a 7ew o7 the great !an, things one can do with
Oracle or!s. The on6line help that ships with or!s contains !an, e3a!ple
7or!s and e3a!ple pieces o7 code ;see the or!s P+1S2+ 0e7erence< that go
7ar $e,ond the si!ple techniques de!onstrated a$ove.
9)7 4?ercise> #rocedures and Triggers
The 7ollowing are so!e suggested e3ercises using various co!$inations o7
triggers and procedures4
8se a si!ple Depart!ent data entr, 7or! and create an Oracle Sequence
;using S2+@Plus< that will generate new Depart!ent nu!$ers 7or the
D-P=0T#-&T ta$le. =dd the requisite P0-6I&S-0T trigger code to
insert a unique D&8#"-0 each ti!e a new depart!ent record is
created.
=dd a WB-&6&-W6O0#6I&ST=&'- trigger to the a$ove
Depart!ent 7or! that will auto!aticall, quer, the D-P=0T#-&T ta$le
when this 7or! is opened.
8se a si!ple -!plo,ee data entr, 7or! and create an alert that displa,s
a warning i7 an e!plo,eeEs salar, is larger than their supervisorEs. In a
WB-&6:=+ID=T-6IT-# trigger. run a quer, to chec* i7 the
e!plo,eeEs salar, is greater than their supervisorEs and i7 so. show the
alert.
8se the -!plo,ee1Dependent #aster1Detail 7or! ,ou created in e3ercise
5.) and put in so!e validation code that will chec* to !a*e sure i7 a
D-P-&D-&T is a SO& or D=8/BT-0. then the D-P-&D-&TEs
"D=T- !ust $e less than the -#P+O?--Es "D=T-. I7 this is not the
case. show an alert.
=7ter ,ou learn how to create 0eports ;see the ne3t section< create a
si!ple D-P=0T#-&T data entr, 7or! with a $utton that. when
pressed. will run a report 7or that depart!ent ;show all e!plo,ees 7or
e3a!ple< $, passing along the D&8#"-0 as a para!eter.
&ote that ,ou will need to use so!e code in ,our $utton si!ilar to the
7ollowing4
DE"LAE
re%orti7 EPOT4O#=E"T2
GieC4re%ort VA")A2'100*2
re%ort4result VA")A'/0*2
re%4status VA")A2'20*2
-- DeBlare %l4i7 as tAe i7enti9ier 9or tAe %ara$eter list
%l4i7 Para$List2
#E6,!
-- !OTE: ,n or7er to launBA a re%ort 9ro$ (or$s+ &ou $ust AaGe
tAe e%orts serGer
-- runninF on &our loBal $aBAine.
-- At a DO- %ro$%t t&%e: rCserGer -install loBalAost
autostartK&es
-- TAis Cill install a re%orts serGer 9or &our $aBAine
'loBalAost* an7 start it u%.
-- !eHt+ Breate a e%orts O8IeBt in (or$s O8IeBt !aGiFator.
-- TAis is na$e7 SMYEPOTS 9or tAis eHa$%le. TAis re%orts
-- o8IeBt Cill AaGe %ro%erties inBlu7inF tAe %atA to tAe aBtual
-- re%ort 9ile '.r79 9ile* &ou Cant to run.
%l4i7 :K 6et4Para$eter4List':t$%7ata:*2
,( !OT ,74!ull'%l4i7* T)E!
Destro&4Para$eter4List' %l4i7 *2
E!D ,(2
-- "reate a 9resA %ara$eter list
%l4i7 :K "reate4Para$eter4List':t$%7ata:*2
E!D2