2. whenever an insert, update, or delete operation is performed. The statementsspecified in the SQL trigger are executed each time an SQL insert, update, ordelete operation is performed. An SQL trigger may call stored procedures or user- defined functions to perform additional processing when the trigger is executed.CURSOR PROGRAM: The following PROGRAM uses a cursor to select the five highest paid employeesfrom the emp table.Input Table SQL> SELECT ename, empno, sal FROM emp ORDER BY sal DESC;ENAMEEMPNOSAL---------- --------- -------- KING 7839 5000 SCOTT77883000 FORD 79023000 JONES 7566 2975 BLAKE76982850 CLARK77822450 ALLEN74991600 TURNER78441500 MILLER7934 1300 WARD7521 1250MARTIN 76541250 ADAMS 78761100 3. JAMES 7900950 SMITH 7369800PL/SQL Block-- available online in file sample2 DECLARECURSOR c1 isSELECT ename, empno, sal FROM empORDER BY sal DESC; -- start with highest paid employeemy_ename VARCHAR2(10);my_empno NUMBER(4);my_sal NUMBER(7,2);BEGINOPEN c1; FOR i IN 1..5 LOOPFETCH c1 INTO my_ename, my_empno, my_sal;EXIT WHEN c1%NOTFOUND; /* in case the number requested */ /* is more than the total*/ /* number of employees */ INSERT INTO temp VALUES (my_sal, my_empno, my_ename); COMMIT; END LOOP; CLOSE c1; END; Output Table SQL> SELECT * FROM temp ORDER BY col1 DESC; 4. NUM_COL1 NUM_COL2 CHAR_COL-------- -------- --------50007839 KING30007902 FORD3000 7788 SCOTT 29757566 JONES2850 7698 BLAKE TRIGGER PROGRAMThis trigger will insert a record into the table product_check before a sql update statement is executed, at the statement level. CREATE or REPLACE TRIGGER After_Update_Row_productAFTER insert On product FOR EACH ROW BEGININSERT INTO product_checkValues(After update, Row level,sysdate); END;/Now lets execute a update statement on table product.UPDATE PRODUCT SET unit_price = 800 WHERE product_id in (100,101);Lets check the data in product_check table to see the order in which the trigger is fired. 5. SELECT * FROM product_check; Output: MesageCurrent_Date------------------------------------------------------------ Before update, statement level26-Nov-2008Before update, row level26-Nov-2008After update, Row level 26-Nov-2008Before update, row level26-Nov-2008After update, Row level26-Nov-2008 After update, statement level26-Nov-2008
Top Related