查看: 1311|回复: 1
|
如何在ORACLE中使用TRIGGER
[复制链接]
|
|
CREATE OR REPLACE TRIGGER trigger_insert
AFTER INSERT ON tableA
REFERENCING NEW AS newRow
FOR EACH ROW
BEGIN
INSERT INTO tableA_tri VALUES (:newRow.acc_no, to_char(sysdate, 'yyyymmdd'), to_char(sysdate, 'HH24:MI:SS'), 'INSERT', USERENV('TERMINAL'));
END;
/
CREATE OR REPLACE TRIGGER trigger_update
AFTER UPDATE ON tableA
REFERENCING NEW AS newRow
FOR EACH ROW
BEGIN
INSERT INTO tableA_tri VALUES (:newRow.acc_no, to_char(sysdate, 'yyyymmdd'), to_char(sysdate, 'HH24:MI:SS'), 'UPDATE', USERENV('TERMINAL'));
END;
/
CREATE OR REPLACE TRIGGER trigger_delete
AFTER DELETE ON tableA
FOR EACH ROW
BEGIN
INSERT INTO tableA_tri VALUES (ld.acc_no, to_char(sysdate, 'yyyymmdd'), to_char(sysdate, 'HH24:MI:SS'), 'DELETE', USERENV('TERMINAL'));
END;
/ |
|
|
|
|
|
|
|
发表于 21-3-2005 09:05 AM
|
显示全部楼层
以下是 Visual FoxPro 的 Trigger 的语法。(供参考)
Create Trigger On TableName For Delete / Insert / Update As lExpression
Delete Trigger On TableName For Delete / Insert / Update
使用方法:
- CLOSE DATABASES
- OPEN DATABASE (HOME(2) + 'data\testdata')
- USE customer && Open customer table
- * Set trigger on maxordamt field to fail with values <= 50
- CREATE TRIGGER ON customer FOR UPDATE AS maxordamt <= 50
- ON ERROR && Restore the system error handler
- WAIT WINDOW "Press a key to test trigger with value of 60"+CHR(13);
- +"When you get the error message, press Ignore."
- REPLACE maxordamt WITH 60 && Displays an error message
- ? maxordamt
- WAIT WINDOW "Press a key to test with value of 50."
- REPLACE maxordamt WITH 50 && Value is accepted
- ? maxordamt
- DELETE TRIGGER ON customer FOR UPDATE && Remove the trigger
复制代码 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|