Creating a trigger in Oracle Express

强颜欢笑 提交于 2019-11-29 22:50:42
Michael T

It seems that SQL Developer thinks that you are running a plain DML (data manipulation) script, not a DDL (data definition). It also thinks that :new.id is a bindable variable.

Why this happens, I don't know; I can't reproduce it in Oracle SQL Developer 2.1.

Try to open a new SQL worksheet window in the theschema schema and execute a "whole" script (not a statement) by pressing F5 (not F9).

This is how I have solved this problem, put "set define off;" before the command:

set define off;
create or replace trigger [...]
[...]
end;
/

Then highlight both commands and press F9 to run. Or you could run all the commands with F5.

It seems, that if the commands are executed separetly with F9, then the set define off does not take affect.

For my case, solution was entering "newrow" for 'new' and "oldrow" for 'old' as values for the binds...

Rod Hittle

I am a novice at this so keep that in mind as I give my answer. I think the issue is that the code

create or replace trigger insert_nums
before insert on theschema.thetable
for each row
begin
select test1_sequence.nextval into :new.id from dual;
end;

Is actually a script and not straight forward SQL statement. Hence you have to run the "Run Script". I discovered that when I had a worksheet open in SQL Developer that if I had anywhere in the worksheet the any code for trigger like above then even I just tried to run a statement that SQL Developer would look back in the worksheet and try to run the script. To stop that from happening I had to comment out the code. And If I did want to run the code for the trigger than I had to open a new worksheet, place the code there and do a RUN SCRIPT.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!