我正在尝试将数据插入到oracle数据库(版本11g xe)。但是当我尝试使用toad执行该过程时,我收到错误为'ORA-01403:未找到数据'。 这是我的代码
CREATE OR REPLACE PROCEDURE ACTSINFO.sp_Insert_WorkDetails
(p_workname IN varchar ,
p_workaddress IN varchar)
IS
BEGIN
insert into workdetails (workname,workaddress) values (p_workname,p_workaddress);
END sp_Insert_WorkDetails;
我尝试使用以下statememt
执行该过程EXEC sp_Insert_WorkDetails('test','test');
此外,我已经为表workdetails中workdetailsid的自动增量定义了一个触发器和序列
序列如下
ALTER SEQUENCE ACTSINFO.WORKDETAILS_WORKID_SEQ
INCREMENT BY 1
MINVALUE 0
MAXVALUE 9999999999999999999999999999
NOCACHE
NOCYCLE
NOORDER
触发如下
DROP TRIGGER ACTSINFO.WORKDETAILS_INSERT;
CREATE OR REPLACE TRIGGER ACTSINFO.WORKDETAILS_INSERT
BEFORE INSERT
ON ACTSINFO.WORKDETAILS
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
BEGIN
SELECT WORKDETAILS_WORKID_SEQ.NEXTVAL INTO :NEW.WORKID FROM WORKDETAILS;
END;
我是oracle的新手。请帮助我......
答案 0 :(得分:7)
您的触发器是问题所在:
SELECT WORKDETAILS_WORKID_SEQ.NEXTVAL INTO :NEW.WORKID FROM WORKDETAILS;
如果workdetails中没有行,则select将不返回任何内容。更糟糕的是,如果你的workdetails表有多行,那么这也会失败。
你真的想要以下内容:
SELECT WORKDETAILS_WORKID_SEQ.NEXTVAL INTO :NEW.WORKID FROM dual;
或 - 如果您使用11g - 那么您可以使用:
:NEW.WORKID := WORKDETAILS_WORKID_SEQ.NEXTVAL;