创建Oracle序列触发器

前端之家收集整理的这篇文章主要介绍了创建Oracle序列触发器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建seuqunce触发器,但是当我在sql Developer中执行触发器创建sql时发生错误.我不明白,其实一切都很好.我在下面分享详情,请帮帮我,谢谢.

我的触发器sql

CREATE OR REPLACE TRIGGER "TRIGGER1" BEFORE INSERT ON ACCOUNTS
FOR EACH ROW
 WHEN (new."ID" IS NULL) 
BEGIN
  SELECT ACCOUNTS_SEQ.NEXTVAL 
  INTO :new."ID" 
  FROM dual;
END;
/

错误描述:

Error starting at line : 5 in command -
CREATE OR REPLACE TRIGGER "TRIGGER1" BEFORE INSERT ON ACCOUNTS
FOR EACH ROW
 WHEN (new."ID" IS NULL) 
BEGIN
  SELECT ACCOUNTS_SEQ.NEXTVAL 
  INTO :new."ID" 
  FROM dual
Error report -
sql Command: trıgger "TRIGGER1"
Failed: Warning: completed with warning

Error starting at line : 12 in command -
END
Error report -
Unknown Command
尝试以下方式:
CREATE OR REPLACE TRIGGER TRIGGER1
BEFORE INSERT ON ACCOUNTS
FOR EACH ROW
 WHEN (new.ID IS NULL) 
BEGIN
  SELECT ACCOUNTS_SEQ.NEXTVAL 
  INTO :new.ID
  FROM dual;
END;
/

你的序列应该是这样的

CREATE OR REPLACE SEQUENCE ACCOUNT_SEQ 
 START WITH 1 
 INCREMENT BY 1;

希望能帮助到你.

原文链接:https://www.f2er.com/oracle/205643.html

猜你在找的Oracle相关文章