遇到一个Oracle触发器的问题,发生原因:
第一次在plsql上跑下面代码没一点问题,既编译通过也触发器也能正常执行。
代码1:
-- Create table
create table ww_img_down_history ( id int not null primary key,img_id int not null,user_id int not null,user_name varchar2(50),time_recorded varchar2(20) not null );
-- Add comments to the table
comment on table ww_img_down_history
is '党群专业线流程的下载记录表';
-- Add comments to the columns
comment on column ww_img_down_history.img_id
is '对应到docimagefile表的id';
comment on column ww_img_down_history.user_id
is '下载人id';
comment on column ww_img_down_history.user_name
is '下载人名称';
comment on column ww_img_down_history.time_recorded
is '下载时间';
create sequence ww_img_down_history_id start with 1 increment by 1 cache 10;
CREATE OR REPLACE TRIGGER ww_img_down_history_trigger BEFORE INSERT ON ww_img_down_history FOR EACH ROW BEGIN SELECT ww_img_down_history_id.nextval INTO :new.id FROM dual;
END;
commit;
然后我执行下面代码,把表、序列、触发器都删掉。
代码2:
drop table ww_img_down_history;
drop sequence ww_img_down_history_id;
drop trigger ww_img_down_history_trigger;
之后再执行代码1,那么问题就出现了,触发器编译通过,但是在插入数据触发器得到执行时,会发生错误。
但是把触发器删掉之后再用大写创建一次就搞定:
drop trigger ww_img_down_history_trigger;
CREATE TRIGGER WW_IMG_DOWN_HISTORY_TRIGGER BEFORE INSERT ON WW_IMG_DOWN_HISTORY FOR EACH ROW BEGIN SELECT WW_IMG_DOWN_HISTORY_ID.nextval INTO :new.id FROM dual;
END;
commit;
原因以后有空研究。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。