有没有一种方法可以在一个脚本中创建多个触发器?
我正在尝试创建多个触发器,只需将一个脚本上传到 Oracle DB/APEX 工作区并运行一次。
与我尝试使用的脚本相比,这是一个简短的脚本:
create or replace trigger "BI_TEC_ROLES"
before insert on "TEC_ROLES"
for each row
begin
if :NEW."ROLE_ID" is null then
select "TEC_ROLES_SEQ".nextval into :NEW."ROLE_ID" from dual;
end if;
end;
create or replace trigger "BI_TEC_STATUSES"
before insert on "TEC_STATUSES"
for each row
begin
if :NEW."STATUS_ID" is null then
select "TEC_STATUSES_SEQ".nextval into :NEW."STATUS_ID" from dual;
end if;
end;
create or replace trigger "BI_TEC_SUBS"
before insert on "TEC_SUBS"
for each row
begin
if :NEW."SUB_ID" is null then
select "TEC_SUBS_SEQ".nextval into :NEW."SUB_ID" from dual;
end if;
end;
我尝试将 GO 放在每个单独的块之间,但仍然只创建第一个触发器,然后给我第二个说法的错误:
Error(7,1): PLS-00103: Encountered the symbol "CREATE"
我希望可以做这个。非常感谢您的时间和兴趣=)
I am trying to create multiple triggers with only uploading one script into an Oracle DB / APEX workspace, and running it once.
Here is a brief script compared to the one im trying to use:
create or replace trigger "BI_TEC_ROLES"
before insert on "TEC_ROLES"
for each row
begin
if :NEW."ROLE_ID" is null then
select "TEC_ROLES_SEQ".nextval into :NEW."ROLE_ID" from dual;
end if;
end;
create or replace trigger "BI_TEC_STATUSES"
before insert on "TEC_STATUSES"
for each row
begin
if :NEW."STATUS_ID" is null then
select "TEC_STATUSES_SEQ".nextval into :NEW."STATUS_ID" from dual;
end if;
end;
create or replace trigger "BI_TEC_SUBS"
before insert on "TEC_SUBS"
for each row
begin
if :NEW."SUB_ID" is null then
select "TEC_SUBS_SEQ".nextval into :NEW."SUB_ID" from dual;
end if;
end;
I have tried putting GO in between each individual block, but still only creates the first trigger then gives me an error for the second saying:
Error(7,1): PLS-00103: Encountered the symbol "CREATE"
I am hoping that it is possible to do this. Thank you very much for your time and interest =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
每次触发后在新行添加一个正斜杠以执行缓冲区中的命令:
Add a forward slash on a new line after each trigger to execute the command in the buffer:
在每个触发器语句之间的空行上放置斜杠“/”作为第一个字符。这在 SQL*PLUS 中相当于“go”。
Put a slash '/' as the first character on a blank line between each trigger statement. This is the SQL*PLUS equivalent of 'go'.
是的,我们可以使用 sql 文件内的 FORWARD SLASH / 在单个脚本中执行多个过程/触发器/函数。
如下所示:
然后oracle会认为它是新的语句/块。
Yes we can execute multiple procedure/trigger/function in single script using the FORWARD SLASH / inside the sql file.
Like below:
Then oracle will consider it as new statement/block.
放置一个正斜杠
在单独一行的两个语句之间
。 Oracle 将接受它作为新语句
Place a forward slash
between the two statements on a separate line.
Oracle will then accept it as a new statement
如何执行:
How to execute it: