Using triggers and virtual columns
In this recipe, we will see how to use virtual columns, a new feature in Oracle Database 11g, to avoid the use of DML triggers, resulting in a performance gain in our applications.
Note
Virtual columns can also be used in referential integrity, tables can be partitioned by them, and statistics can be gathered on them.
How to do it...
The following steps will demonstrate the use of virtual columns:
- Connect to the
SH
schema:CONNECT sh@TESTDB/sh
- Create a table and call it
LOANS
:CREATE TABLE sh.LOANS ( LOAN_ID INT NOT NULL, PAYMENT NUMBER, NUMBER_PAYMENTS NUMBER, GROSS_CAPITAL NUMBER);
- Create a trigger on the
LOANS
table to calculate theGROSS_CAPITAL
field, giving the number of payments and the amount of every ...
Get Oracle Database 11gR2 Performance Tuning Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.