问题描述
大家好,我正在开发一个Oracle数据库-我是oracle的新手,并且我想使用触发器.我正在使用oracle 11g,我有一个名为计算机的表.当我运行以下触发器时,它会调试并没有给出错误,但是!一旦我尝试将任何数据插入计算机,它就会引发错误并说我必须删除或禁用触发器,或者我有特权/授权问题!
Hey all, I''m developing an Oracle database -I''m kinda new to oracle-, and I want to use triggers. I''m using oracle 11g, I have a table called Computer. When I run the below trigger, it debugs and gives no errors, BUT! once I try to insert any data into Computer, it fires an error and says I have to either drop, or disable the trigger, or I have privileges/authorization issues!
CREATE OR REPLACE TRIGGER "MyUser"."TRG2TEST"
BEFORE INSERT ON COMPUTER
DECLARE NEW AS NEWROW
BEGIN
INSERT INTO COMPUTER (COMPID,COMPNAME,CPU,hdd_size,motherboard,operatingsystem,visible,good) VALUES ((select max(CompID) from IDZ)+1,newRow.CompName,newRow.CPU,newRow.HDD_Size,newRow.MotherBoard,newRow.OperatingSystem,1,1);
END;
请注意,我使用Oracle SQL Developer尝试了此代码.
当我进入SQL-Plus运行此代码(作为系统)时,它总是在表名处停止:"Computer"
我真的需要你的帮助.
Please note that I tried this code using Oracle SQL Developer.
when I go to SQL-Plus to run this code (As system), it always stops at the name of the table: "Computer"
I really need your help. Thank you in advance guys!
推荐答案
SHOW ERRORS TRIGGER TriggerName
看看在交战中有什么错误.
加法:
To see what are the errors in comiplation.
Addition:
CREATE OR REPLACE TRIGGER "MyUser"."TRG2TEST"
BEFORE INSERT ON COMPUTER
FOR EACH ROW
BEGIN
INSERT INTO COMPUTER (COMPID,COMPNAME,CPU,hdd_size,motherboard,operatingsystem,visible,good)
VALUES
(SEQ_CompID.NextVal, :new.CompName, :new.CPU, :new.HDD_Size, :new.MotherBoard, :new.OperatingSystem,1,1);
END;
加法2:
添加了FOR EACH ROW,因为它应在插入的每个新行上分别触发.
Addition 2:
Added FOR EACH ROW because this should fire separately on each new row that is inserted.
这篇关于orc-04098在Oracle中使用触发器时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!