【问题标题】:SQL*PLUS Trigger has not compiled but no errors shown upSQL*PLUS 触发器未编译但未显示错误
【发布时间】:2020-04-24 23:08:52
【问题描述】:

我正在尝试使用sqlplus 创建序列和触发器,并且所有内容都是用 bash 脚本编写的。 我的代码如下

su -p oracle -c "$ORACLE_HOME/bin/sqlplus -l mydb/mypass@localhost:1521/xe << !
    create sequence SEQ_NAME start with 1000 maxvalue 9999;

    create or replace trigger TRG_NAME
    before insert on TABLE_NAME
    for each row
    begin
        select SEQ_NAME.nextval into :new.MY_ID from dual;
    end;
!
"

执行上述命令后,我预计会收到一些类似的日志

Sequence created

Trigger compiled

但只有日志Sequence created 出现。结果,只创建了序列,而没有创建触发器。我知道通过检查 SQL Developer 工具

问题是当我使用 SQL Developer 工具并执行脚本时

create sequence SEQ_NAME start with 1000 maxvalue 9999;

create or replace trigger TRG_NAME
before insert on TABLE_NAME
for each row
begin
select SEQ_NAME.nextval into :new.MY_ID from dual;
end;

然后一切正常!序列和触发器已创建!

对这个问题有什么想法吗?

【问题讨论】:

标签: oracle plsql sqlplus database-trigger


【解决方案1】:

试试这个,请告诉我们。

su -p oracle -c "$ORACLE_HOME/bin/sqlplus -l mydb/mypass@localhost:1521/xe << !
    create sequence SEQ_NAME start with 1000 maxvalue 9999
    /
    create or replace trigger TRG_NAME
    before insert on TABLE_NAME
    for each row
    begin
        select SEQ_NAME.nextval into :new.MY_ID from dual;
    end;
    /
!
"

【讨论】:

  • 感谢您的回答,几乎正确!在end 之后,您错过了;。否则,我得到Warning: Trigger created with compilation errors./的目的是什么?
  • 刚刚更正了在触发器定义中的“结束”字后添加分号。
  • 在 SQL*Plus 中,斜杠符号强制执行语句(例​​如:create 语句)或 pl/sql 块(例如:触发器的 create 块)。
  • 请阅读下面非常有趣的关于分号和斜线区别的解释:stackoverflow.com/a/10207695/297267
猜你喜欢
  • 1970-01-01
  • 2010-12-12
  • 2014-01-04
  • 2016-10-16
  • 2016-03-21
  • 2018-09-14
  • 1970-01-01
  • 2016-10-30
  • 1970-01-01
相关资源
最近更新 更多