Tutorial For Oracle10g Forms and Reports
Tutorial For Oracle10g Forms and Reports
You have an Oracle account on Oracle server and you have Oracle10g Developer
Suite installed and configured to the Oracle10G Server on your workstation.
You
have created a Student table (FTPT_STATUS, MAJOR, SEX,
START_SEM, START_YEAR, STUDNAME) in Oracle database by using
Oracle10g Designer or SQL*Plus.
Lesson 1
Create your first block and form based on your Student table
Oracle10g Forms/Reports is an Oracle tool that helps you to create web-enabled forms and
reports based on the tables that you have created using Oracle10g Designer or SQL Plus
commands. Starting from Oracle10g, Oracle10g Forms/Reports has become one of Oracle10g
Developer Suite components. You can use Oracle10g Forms/Reports to:
Add various functionality, like radio buttons, combo boxes, and list of values to make
your forms and reports more user friendly.
Write triggers on your objects to add functionality to them and capture errors.
Object
Navigator: In this tool you can view all your objects, add new objects and
name/rename your objects.
Layout Editor: This tool helps you design your forms and reports and add various
objects to them like push buttons and list boxes.
PL/SQL Editor: This is the tool that is used to write all the codes for the triggers,
procedures or functions.
Menu Editor: This tool will help you create a customized menu that can be attached to
your form or report.
3. Double click Data Blocks, Select 'Use the Datablock Wizard' and click OK--This is
the easiest method to design a new form.
4. You will now see the Welcome to the Datablock Wizard Window. Click Next to
proceed.
5. You will now see the window for the Datablock Wizard. Select Table or View as in
the figure and click Next.
6. You will now see the window that prompts you to select a table or a view--your form
will be created based on this selection. Since no table or view is being shown, click on
browse to look at the list of tables and views in your database.
7. Once you click browse, the connect window will appear. Type in your username,
password and database to connect to the database.
8. You will now see the tables window. Select current users and tables and click OK.
9. You will now see the list of tables created in your database. Select Students and click
OK.
10. You will now see your selected table and its available columns on your screen. Click
on the single right arrow to select the first column to be shown in your form; in this
case the STUDID column. You will now see this column under the database items
selected sub-window.
11. To move the rest of the columns, simply click on the double right arrow and this will
select all your columns in to the database items.
12. You will now see the Congratulations window. Make sure that "Create the data block,
then call the Layout Wizard" is selected and click on Finish.
13. You will now see the Layout Wizard Welcome window, click next. You will see the
following screen, click next.
14. select the items that you would like to show in the form. Make sure that the data block
selected is Students and then click the double right arrow to move all the columns of
the Student block from the available items to the displayed items. Click on Next to
continue.
15. The window with the prompt for the height and width of the items will appear. Click
Next to accept the default values.
15. The Layout Wizard will now prompt you to select the layout or view style of your
block. Select Form and click Next.
16. The Layout Wizard will now prompt you to select a title for the form that you are
creating. Type in Student Records. Click Next to continue.
17. Congratulations! You have now successfully created your first form. Click Finish to
view your form.
18. You will now see the canvas view of the form that you have created. You can now add
various objects like push buttons, combo boxes and radio buttons to your form to
make it more graphical and user friendly. We will do this in the next lesson.
19. You can now format the form manually. Click on the frame to select it. Then drag the
frame to make it bigger.
20. You can now space out the data fields to make your form more visually appealing.
You can do this by simply selecting the data field and dragging it to your desired area.
21. After you have formatted all the data fields, your form should look like the following:
Lesson Summary
Next, you will learn to add more objects and functionality to your basic form. For this,
proceed to Lesson 2.
Lesson 2
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 1. 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
Adding triggers to the Push Buttons for inserting, deleting and retrieving records
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
3. Now type in the following statement to insert more data into the Major_list table:
SQL> COMMIT;
4. Now, type in Select * from Major_List; to view your newly created table and its
records.
5. Now, Open the Module you previously created in Oracle Forms Builder. First,
double click LOV in the Object Navigator on Forms Builder, then select Use LOV
Wizard.
6. Immediately, the window for LOV Wizard will pop up, select Next, you will have
the following screen:
7. Click Build SQL Query, then highlight MAJOR_LIST table, click Include:
Close Select Data Tables window, select MAJOR in Query Builder window:
Click next, you will have the following window, type in MAJOR_LOV as title for
your LOV:
Click Finish at this point, you will come back to the Object navigator window. Now,
name the LOV as MAJOR_LOV by double clicking the icon under LOVs:
Which opens the following window, change the LOV name to MAJOR_LOV, then
close the Property Palette.
12. Now go back to the Canvas View by clicking on the small picture icon just beneath
the word Canvases in the Object Navigator.
13. In the Canvas View, we will create a push button and position it right beside the
Major data field. To create the push button, select the box like icon from the
toolbox, click on it once and drop it beside the Major data field.
14. After the push button has been created, then right click on the button and select
Property Palette from the list that pops up.
15. Once you are in the Property Palette, remove the label, specify Iconic as Yes and in
the icon Filename type Down. Click on the close button in the lower taskbar
located on the upper right corner.
16. You will now return to Canvas View. Your Canvas will now look like:
17. Now back in the canvas, right click on push and this time select the PL/SQL Editor.
15. In the PL/SQL Editor we will write a trigger that will connect this button to the
table called Major_List, so that when the user clicks on the button they will be
able to view the list of options. When you select the Pl/SQL Editor, the window
for the new trigger selection will appear.
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.
17. Immediately, you will see the PL/SQL Editor window. Type in the following code
in the blank space in the Editor.
Declare
Return_LOV Boolean;
Begin
Return_LOV :=show_LOV('Major_LOV');
End;
18. After typing in the code, click compile on the upper left-hand corner of the
window.
19. 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. (note: if you have not
installed Oracle Jinitiator on your pc, the system will automatically start Oracle
Jinitiator installation process when you click Run Form. You will have to let
system complete the installation process in order to use Run Form function. Also,
you must keep the OC4J Running when using Run Form).
20. When the form is running, type in an ID number in the STUDID field (there has
to be data in the primary field). Then click the button with the down arrow. The
list of majors will pop up. To return to the canvas View, simply click OK in the
list of majors and click the close button in the upper right taskbar.
21. We will now create radio buttons for the FTPT_Status to give the user an option
of creating either Full-Time or Part-Time.
22. To do this, right click on the FTPT_Status field in the canvas view and go to its
Property palette.
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.
24. Once you return back to the canvas, you will realize that the data field for the
FTPT_Status is no longer visible. This is because we have specified it to be a
radio group and not a text item. To see them, we will have to insert radio buttons.
Select radio button from the tool palette on your left.
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.
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.
27. In the same manner create a second radio button, attach it to the radio group
FTPT_Status, give it a label of 'Part-Time' and a value of PT.
28. Select a rectangle from the palette and draw it around the radio buttons.
29. Go to the Property Palette for the rectangle frame by right clicking on it.
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 list style as poplist.
33. Click on Elements in List and type in the list elements and list values. In this
lesson, the list elements and values will be same and will be Fall, Spring, Summer
1 and Summer 2. (or 01, 02, 03, 04, depending on the data type in your
database ).
34. Now go to Programs Run Form to view your newly created Poplist.
35. We will now create three push buttons and write triggers for each button. To
create a push button, select the button icon from the palette on the left of the
canvas and drop in the lower part of the form.
36. We will change the label of the first push button in the property palette to
"Retrieve." To do this, right click on the button and go to its Property Palette.
37. Now select the PL/SQL editor by right clicking on the push button.
begin
from student
where studid = :student.studid;
exception
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 10g Forms/Reports 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.
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 Run Form to view your form
with the three push buttons.
Lesson Summary
In this lesson, you have learned how to add various objects to your form and write triggers on
them to add functionality. Specifically this involved:
1. Creating LOVs, or List of Values, where you connected to another table from
which users make their selections
5. Adding triggers to the push buttons for inserting, clearing and retrieving
records
In the next lesson we will create another push button for deleting records, to which we will
add alerts for warning the user before a record is deleted. We will also use a procedure to
create the above mentioned functionality. To learn how to do this, proceed to Lesson 3.
Lesson 3
Create Alerts (a modal window) on a push button that will function as a warning
or a message to the users when they click the button.
Create
Procedures which are stored blocks of code which can be called from
multiple objects saving the time taken for retyping codes
Creating an Alert
Change the title of the alert to Delete Alert, and Name to Delele_Alert.
You can add a third button to the alert or just keep the OK and Cancel
4. To activate the alert, we will create a procedure which we will call from the delete
button. To add a procedure, go to the Object Navigator and double click on
Program Units. Immediately the window for the new Program unit will appear.
5. In the window for the new Program Unit, type in the name as Display_Delete-
Alert. Make sure that procedure is selected as the type of Program Unit and click
OK.
6. Once you click OK, you will be automatically taken to the PL/SQL Editor
window.
7. In the PL/SQL Editor, type in the following code for activating the alert. You
may have to delete a couple of lines from the Editor to avoid duplication. In this
code, we will declare a number variable called return_alert. We will then set it to
show the alert that we created earlier in this lesson called Delete_Alert. We will
then write a simple if/then statement, such that if the user clicks on OK, which is
alert button 1, then 10g Forms/Reports will perform the deletion and commit the
changes. Otherwise, it will exit the alert window and help the users decide on
their action. (See the following to get a view of the code as it should look in the
PL/SQL editor. Do not forget to compile.)
8. We will now add a push button to the form and then add the above procedure to
it, so that whenever the user clicks on delete, the alert will be shown. To do this,
go the Layout Editor by double-clicking Canvas icon and add a push button to
the form, go its properties, and change the label to Delete (use the steps used to
create a push button in Lesson 2). Now go to its PL/SQL Editor by right clicking
on the push button.
10. The last line of the code will call the previously created procedure
Display_Delete_Alert and activate the alert whenever the user clicks on the delete
button. The first two lines of code delete the record for any particular student ID.
Lesson Summary
Create alerts on push buttons (delete) so that when the user clicks on the button
the alert is shown as a warning
Create procedures or stored blocks of code that can be called from any object
Next you will learn how to create reports. To do this, proceed to Lesson 4
Lesson 4
In this lesson you will learn how to create reports based on our existing Student table.
Specifically, this will involve:
Our objective will be to create a simple report that will list students along with some student
attributes. Students in this report will be categorized by major. As a starting point, let us
assume that the STUDENT table has the following rows.
You may enter the data shown below using the INSERT statement in SQL*Plus covered
earlier in the tutorial. For example, the following statement may be used to insert the first row
(for the student Diana with Student Id '1113').
SQL> insert into student values ('1113', 'Diana', 'PT', 'F', 'Fall', 1996,
'Marketing', 'Y');
Or, you may enter data directly from the previous ly created form.
Creating Reports:
2. Immediately, you will see the Welcome to Report Builder Window. Select the
radio button for the Build a new report manually and click OK.
3. Once you click OK, you will see the Report Editor-Data Model window, with a
default name for the Data Model.
4. The Report Editor is the tool that you will use to create your data model for the
report. Click on the SQL icon (See the following) in the toolbar located on the left
hand side, and drag and drop it on the palette. Immediately, the SQL Query
Statement window will appear. Type in the displayed SQL query to view student
information in order of major.
5. Once you click OK, Oracle10g Forms will prompt you to connect to the database.
Type in your User Name, Password and Database.
6. You will now see your data model, where Q_1 stands for the name of the query
and G_Major, stands for its associated record group which contains the list of
fields that you will be able to view in your report.
7. To change the name of your query, right click on it and select the Property
Inspector:
8. Immediately, you will see the window for the Property Inspector. Change the
name by typing in the name (Q_StudMajor) beside the 'Name' tab, and press
enter. You can also change or edit your SQL query by clicking on the space
beside the SQL Query Statement tab.
9. Your Data Model should now look like the following:
10. Recall that we have been asked to create a report that will display a list of students
and their related information organized by Majors. To do this, we will move the
Major records into a separate record group. In Oracle10g Reports terms, it is
called to 'break out'. First, click on the G_Major, and drag and lower it to create
more space between the record group and the query. Then select Major, and
drag and drop it on the line connecting Q_StudMajor and G_Major.
Figure 11.12: Creating a Break Group
11. Your Data Model should now look like the one in Figure 11.13 with a new group
for Major.
12. Right click on the G_1 to go to its Property Palette. Change its name to G_Break.
13. Your Data Model should now look like the following:
14. Now select Report Wizard from the Tools Menu to generate the report.
15. You will now see the first screen of the Report Wizard. Select “Create both Web
& Paper Layout”, click next, and Type in "List of Students by Major" in the
Title box. Next, select the radio button for Group Above in order to create breaks
after record groups for each Major. Now, click Next.
16. You will now see your SQL statement again. You can edit your statement here if
you choose to. At this time we will use the query that we had entered earlier.
Click Next.
17. You will now be prompted to select the fields that you would like to designate as
group fields. Selected Major into Group Fields window (see the following). Now,
select the next tab, Fields.
19. You will now be prompted to select fields for which you would like to calculate
totals. Let us assume that we have been asked to provide the total number of
students in each major and also the Grand total of the number of students. To do
this, select StudID, and click on Count.
20. Your Screen should look like the following with Count (StudId) in the Totals
column). Click Next.
22. The final modification involves selecting an appropriate template for the report.
In this case, we will select Beige from the list provided. You are free to select any
template of your choice. Click Finish.
24.Web-enable Reports:
To web enable the report, click Run button on the top of the window, Oracle10g Reports will
generate a report in HTML version. You can deploy this file on a web server to publish it on-
line.
Lesson Summary
Generate reports based on the created Data Model using the Report Wizard