Page 454
Listing 16.2. PL/SQL block for the database trigger body.
begin if inserting then insert into student_schedule_journal (operation, student_ID, Class_ID, Grade, Date_Grade_Assigned, Changed_By, Changed_Date) values (`I', :new.Student_ID, :new.Class_ID, :new.Grade, :new.Date_Grade_Assigned, user, sysdate); elsif updating then insert into student_schedule_journal (operation, student_ID, Class_ID, Grade, Date_Grade_Assigned, Changed_By, Changed_Date) values (`U', :new.Student_ID, :new.Class_ID, :new.Grade, :new.Date_Grade_Assigned, user, sysdate); elsif deleting then insert into student_schedule_journal (operation, student_ID, Class_ID, Grade, Date_Grade_Assigned, Changed_By, Changed_Date) values (`I', :new.Student_ID, :new.Class_ID, :new.Grade, :new.Date_Grade_Assigned, user, sysdate); end if; end;
ANALYSIS
As you can see in Listing 16.2, the trigger body consists of a PL/SQL block with an IF statement. Each clause in the IF statement tests for the operation that is being performed. For instance, the first portion of the IF statement tests to see if the triggering event is an INSERT; if so, a row is inserted into the Student_Schedule_Journal with the following values. Click Close to exit the Database Trigger Editor.
Operation | I, because the operation is an INSERT |
Student_ID | :new.Student_ID, which contains the value for Student_ID that is being inserted in the Student_Schedule table |
Class_ID | :new.Class_ID, which contains the value for Class_ID that is being inserted in the Student_Schedule table |
Grade | :new.Grade, which contains the value for Grade that is being inserted in the Student_Schedule table |
Page 455
Let's test the trigger. You can do this by using either SQL*Plus or SQL Worksheet.
Figure 16.20.
Student_Schedule_Journal
table is empty.
Page 456
Figure 16.21.
Viewingrecords in the
Student_Schedule
table.
Listing 16.3. Assigning a grade with an UPDATE statement.
update Student_Schedule set Grade = `A', Date_Grade_Assigned = sysdate where Student_ID = `10231324' and Class_ID = `109100';
As shown in Figure 16.22, the Student_Schedule_Journal now has a single row with the expected values, including:
Operation | U, which corresponds to the UPDATE statement that was executed |
Grade | A, which is the grade that was changed |
Date_Grade_Assigned
|
Page 457
Figure 16.22.
Verifying that the
trigger has fired.
This lesson explored these key concepts regarding Oracle Graphics and Procedure Builder:
Page 458
On Day 17, "Introduction to Oracle Power Objects," you will learn about this intuitive, object-oriented tool for developing client/server applications. Power Objects differs significantly from Oracle Forms. It uses a scripting language named Oracle Basic.
Q Does Oracle Graphics offer the capability to "drill-down" into a chart for the purpose of seeing the details of a chart element?
A Yes. You can specify a detail query that will be executed when the user clicks on an element in the chart. The main chart is referred to as the master chart. A parameter is created that is used to define the relationship between the master and detail charts.
Q What are some of the built-in packages that you can view with Procedure Builder?
A The built-in packages include
- TEXT_IO for reading from and writing to files
- DDE, which provides Dynamic Data Exchange support within Oracle Forms, Reports, Graphics, and other Windows-based programs
- TOOL_ENV for obtaining the values of Oracle environment variables
The purpose of the Workshop is to allow you to test your knowledge of the material discussed in the lesson. See if you can correctly answer the questions in the quiz and complete the exercises before you continue with tomorrow's lesson.