Lesson 9: List of Values (Lovs)
Lesson 9: List of Values (Lovs)
In this lesson you will learn how to create an end-user interface and
add more functionality to the basic form that we created in Lesson 8.
Specifically, this will involve:
Creating LOVs, or List of Values, where you will connect your form to another
table from which the users make their selections
Creating Radio Buttons
Creating Combo Boxes and Poplists
Creating Push Buttons
Adding triggers to the Push Buttons for inserting, deleting and retrieving records
List of Values (LOVs)
1. In this form we are designing, we will create a List of Values for major, so that the
user can select a major from the list. To do this, first we will have to create table
called Major_List.
2. To do this, go to SQL*Plus and type the following code at the SQL prompt
SQL> CREATE TABLE MAJOR_LIST
2 (MAJOR VARCHAR2(20));
3. Now type in the following statement to insert more data into the Major_list table:
SQL> INSERT INTO
('Accounting');
SQL> INSERT INTO
Systems');
SQL> INSERT INTO
SQL> INSERT INTO
SQL> INSERT INTO
Sciences');
MAJOR_LIST VALUES
MAJOR_LIST VALUES ('Info.
MAJOR_LIST VALUES ('Marketing');
MAJOR_LIST VALUES ('Finance');
MAJOR_LIST VALUES ('Decision
4. Now, type in Select * from Major_List to view your newly created table and its
records. (See Figure 9.1)
7. Type in the following Select statement in the window to connect the new LOV to
the Major_List table that we created earlier and click OK. (See figure 9.4)
Figure 9.4: The New LOV Window with the select code
select major into :studblock.major from major_list order
by major;
8. Once you click OK, you will come back to the Object navigator window. Now,
name the LOV as MAJOR_LOV by double clicking the word LOV. (See Figure
9.5)
Figure 9.7: Creating a push button to place it beside the Major data field
11. After the push button has been created, then right click on the button and select
Property Palette from the list that pops up. (See Figure 9.8)
Figure 9.10: The Canvas View with the Push Button for the LOV
14. Now back in the canvas, right click on push and this time select the PL/SQL
Editor. (See Figure 9.11)
Figure 9.12: The Window with the list of triggers available to the user
16.
We will write a When-Button-Pressed trigger, since we would like the
code to be activated when the user presses the button. Scroll down and select
When-Button-pressed trigger. (See Figure 9.13)
18.
Figure 9.14: The PL/SQL Editor window
19.
After typing in the code, click compile on the upper left-hand corner of the
window. (See Figure 9.15)
Figure 9.15: The Window for the PL/SQL Editor with the code for the LOV
20.
To test how the button works, you can view the form by returning to the
Canvas View and selecting Run Form from the Program menu. (See Figure 9.16)
Figure 9.18: Selecting the Property Palette for the FTPT_Status field
23.
Change the item type from text to Radio Group and set the initial value to
either FT or PT. Close the Property Palette by clicking the close button on the
upper right hand corner. (See figure 9.19)
Figure 9.20: The palette with the icon for the radio buttons
25.
Drop the radio button into the canvas. Immediately a window will appear,
prompting you to select the radio group you would like to attach this radio button
to. Select the radio group FTPT_Status. (See Figure 9.21)
Figure 9.21: The Window for Attaching the radio button to a radio group
26.
Now right click on the radio button and go to its Property Palette. Change
the label of the button to 'Full_Time', change background color to gray and give
the radio button a value of FT. (See Figure 9.22)
Figure 9.24: Selecting the Property Palette for the rectangle frame
30.
Now, click on the rectangle frame and select Format
format the frame. (See Figure 9.25)
Bevel
Lowered to
Figure 9.25: Formatting the Rectangle Frame around the radio buttons
31.
You can now test your form by selecting Program Run Form. Your form
with the newly created radio buttons should now look like Figure 9.26.
Figure 9.26: The form with the newly created radio buttons
32.
We will now create a drop-down poplist for the variable Start_Sem that
will contain four entries: Fall, Spring, Summer 1 and Summer 2. To do this, go to
the Property Palette for the Start_Sem and change its item type from text to list
items, and select type of list as poplist. (See Figure 9.27). Close the Property
Palette to return to the Canvas View by clicking on the close button in the upper
right hand corner
Figure 9.31: Selecting the Property Palette for the push button
37.
Now select the PL/SQL editor by right clicking on the push button. (See
Figure 9.32).
Figure 9.32: Selecting the PL/SQL Editor for the push button
38.
Select the WHEN-BUTTON-PRESSED-TRIGGER, insert the following
PL/SQL code in the blank space of the editor and then click Compile.
begin
select studid, studname, ftpt_status, sex, start_sem, start_year, major
into :studblock.studid, :studblock.studname, :studblock.ftpt_status,
:studblock.sex, :studblock.start_sem, :studblock.start_year, :studblock.major
from student
where studid = :studblock.studid;
exception
when no_data_found then
message ('Invalid Student Id:Please enter a valid Id.');
raise form_trigger_failure;
end;
39.
In the above code, we are writing a select statement for retrieving the
record of a student with any particular student ID. If no data is found on a
particular student ID, then Developer/2000 will give an error message and raise
the form_trigger_failure trigger. Run the form and type in a invalid STUDID to
check the message. (See Figure 9.33)
Figure 9.33: Error Message when invalid Student ID is entered by the user
In a similar manner, create two other buttons, totaling three push
buttons.
40.
Go to the second push button, right click on it and go to its property
palette. Change its label to Insert. Now come back to the Layout Editor, right
click again on the push button and go to its PL/SQL Editor. In it, write the
following code in the When-Button-Pressed trigger:
Commit;
Clear_Form;
41.
Label the third push button as Clear. At the When-Button-Pressed Trigger,
write the following code:
Clear_Form;
42.
Now go back to the Canvas View and Program
form with the three push buttons. (See Figure 9.34)