佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1272|回复: 1

如何在ORACLE中使用TRIGGER

[复制链接]
发表于 17-3-2005 07:18 PM | 显示全部楼层 |阅读模式
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;
/
回复

使用道具 举报


ADVERTISEMENT

发表于 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

使用方法:

  1. CLOSE DATABASES

  2. OPEN DATABASE (HOME(2) + 'data\testdata')
  3. USE customer  && Open customer table

  4. * Set trigger on maxordamt field to fail with values <= 50
  5. CREATE TRIGGER ON customer FOR UPDATE AS maxordamt <= 50

  6. ON ERROR  && Restore the system error handler

  7. WAIT WINDOW "Press a key to test trigger with value of 60"+CHR(13);
  8. +"When you get the error message, press Ignore."
  9. REPLACE maxordamt WITH 60    && Displays an error message
  10. ? maxordamt

  11. WAIT WINDOW "Press a key to test with value of 50."
  12. REPLACE maxordamt WITH 50    && Value is accepted
  13. ? maxordamt
  14. DELETE TRIGGER ON customer FOR UPDATE  && Remove the trigger
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 13-11-2024 03:29 PM , Processed in 0.121762 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表