我在oracle 12c中创建了一个如下所示的序列,没有问题,
CREATE SEQUENCE EMPLOYEE_SEQ
START WITH 1
MAXVALUE 9999999999999
MINVALUE 1
NOCYCLE
CACHE 20
NOORDER;
然而,我收到的错误是"Error(2,25): PLS-00201: identifier 'EMPLOYEE_SEQ.NEXTVAL' must be declared"
代码
CREATE OR REPLACE TRIGGER EMPLOYEE_TRG BEFORE INSERT ON EMPLOYEE REFERENCING
NEW AS NEW OLD AS OLD FOR EACH ROW
BEGIN
:new.EMPLOYEE_ID := EMPLOYEE_SEQ.nextval;
END EMPLOYEE_TRG;
我该如何解决这个问题?
答案 0 :(得分:0)
您可以尝试:
而不是触发器alter table employee add employee_id number default employee_seq.nextval;
答案 1 :(得分:0)
您的序列不是为此创建的,因此错误,您应该尝试再次创建它或尝试其他操作
CREATE SEQUENCE EMPLOYEE_SEQ START WITH 1 NOCACHE ORDER;
这将运行但没有缓存
并尝试以下触发器:
CREATE OR REPLACE TRIGGER"EMPLOYEE_TRG"
BEFORE INSERT ON employee
FOR EACH ROW
WHEN (NEW.EMPLOYEE_ID IS NULL) BEGIN
:NEW.EMPLOYEE_ID:=EMPLOYEEE_SEQ.NEXTVAL;
END;
或检查权限是否无效
答案 2 :(得分:-1)
我授予数据库用户
后,问题已解决