Email Us : sunilkumark11@gmail.com
Free Training > SQL PL / SQL Forms Reports Oracle Applications
< Previous Next >

 
Forms - Using button control

Create a new form ( using data block wizard and layout wizard ) based on EMPONE table ( same as standard EMP table ).
Save the form with the name EMPTHREE.FMB
In the layout Editor ( F2 ) , create three buttons. ( click on button and click on canvas )

For the 1st button, in the property palette , provide name it as B1 and Label – SAVE
For the 2nd button, provide name as B2 and label – CLEAR
For the 3rd button, provide name as B3 and label – QUIT

Right click on SAVE button smart triggers WHEN-BUTTON-PRESSED
Provide the following code ( just one line code )

Commit_form;

Click on compile. You should get confirmation message “successfully compiled”

Similarly, Right click on CLEAR button smart triggers WHEN-BUTTON-PRESSED
Provide the following code ( just one line code )

clear_block;

Click on compile. You should get confirmation message “successfully compiled”
Similarly, Right click on QUIT button smart triggers WHEN-BUTTON-PRESSED
Provide the following code ( just one line code )

exit_form;

Click on compile. You should get confirmation message “successfully compiled”
Program Compile module
Program Run form
Provide value for few fields EMPNO, ENAME and SAL
Click on SAVE button.
You get confirmation message “Transaction complete: 1 record applied and saved.

You can see, new record is created in the table.

Similarly try CLEAR and QUIT buttons.
Calculate bonus of employee after retrieving data from table
In EMPTHREE.FMB, Layout Editor Create a display Item.
Provide the following properties
General
Name – BONUS
Data
Datatype – Number
Database
Database Item – NO
Prompt
Prompt – Bonus

Create a PRE-QUERY trigger ( Fires before execute_query built_in is executed )
under EMPONE datablock , provide the following code
:EMPONE.DEPTNO :=30;
Click on compile.

Create POST-QUERY trigger ( Fires whenever data is retrieved from table. Fires after execute_query built_in is executed )

Provide the following code
Declare
Netpay number(12,2);
Begin
Netpay := :SAL + nvl (:COMM, 0);
If :JOB ='CLERK' then
:BONUS := netpay * 1.25;
elsif :JOB = 'SALESMAN' then
:BONUS := netpay * 1.35;
elsif :JOB = 'MANAGER' then
:BONUS := netpay * 1.45;
else
:BONUS := netpay *1.9;
end if;
end;

Click on compile.

Create WHEN-VALIDATE-ITEM ( Item level trigger, Fires whenever SAL value is changed ) under SAL item
Provide the following code ( Same as above )
Declare
Netpay number(12,2);
Begin
Netpay := :SAL + nvl (:COMM, 0);
If :JOB ='CLERK' then
:BONUS := netpay * 1.25;
elsif :JOB = 'SALESMAN' then
:BONUS := netpay * 1.35;
elsif :JOB = 'MANAGER' then
:BONUS := netpay * 1.45;
else
:BONUS := netpay *1.9;
end if;
end;
Click on Compile.

Create WHEN-VALIDATE-ITEM ( Item level trigger, Fires whenever COMM value is changed ) underCOMM item
Provide the following code ( Same as above )
Declare
Netpay number(12,2);
Begin
Netpay := :SAL + nvl (:COMM, 0);
If :JOB ='CLERK' then
:BONUS := netpay * 1.25;
elsif :JOB = 'SALESMAN' then
:BONUS := netpay * 1.35;
elsif :JOB = 'MANAGER' then
:BONUS := netpay * 1.45;
else
:BONUS := netpay *1.9;
end if;
end;

Click on Compile.

So, All together we have created four triggers. We can see the triggers which are created in Object Navigator.

File Save
Program Compile Module
Program Run Form
Click on execute_query , we get the data of Deptno – 30 employees.
( As we have initialized deptno – 30 in PRE-QUERY trigger )
Change the SAL and COMM column, automatically BONUS will be reflected.

Assignment -- Create EMP block and four display items ( DA, HRA, PF and GROSS SAL )

If JOB = CLERK
DA =  21% of NETSAL
HRA = 31% of NETSAL
PF  = 11% of NETSAL
If JOB = SALESMAN
DA =  22% of NETSAL
HRA = 32% of NETSAL
PF  = 12% of NETSAL
If JOB = MANAGER
DA =  23% of NETSAL
HRA = 33% of NETSAL
PF  = 13% of NETSAL
If JOB = ANALYST
DA =  24% of NETSAL
HRA = 34% of NETSAL
PF  = 14% of NETSAL
For other jobs
DA =  25% of NETSAL
HRA = 35% of NETSAL
PF  = 15% of NETSAL

< Previous Next >