是否允许您检索触发器内的序列
我希望能够获取序列值,并在触发器中的多个操作上使用相同的值来对表进行审计操作。因此,当更新表时,我想获取所有已更新的列。但当我在数据库中注册更改的列时,我希望将它们分组为一个。有没有办法获取序列号并将其存储在触发器内的变量中。我能够编写的代码不断出现 PLS-00357。
CREATE OR REPLACE TRIGGER TRG_EMPLOYEE_CHANGED AFTER INSERT OR DELETE
OR UPDATE ON EMPLOYEE REFERENCING OLD AS old NEW AS new FOR EACH ROW
DECLARE
GROUPID NUMBER := SEQ_POPERATIONLOG_LOGSUBNO.NEXTVAL;
BEGIN
OPERATION('FIRST_NAME', GROUPID, :old.FIRST_NAME, :new.FIRST_NAME);
OPERATION('LAST_NAME', GROUPID, :old.LAST_NAME, :new.LAST_NAME);
OPERATION('ADDRESS', GROUPID, :old.ADDRESS, :new.ADDRESS);
OPERATION('TELEPHONE', GROUPID, :old.TELEPHONE, :new.TELEPHONE);
END;
I want to be able to get teh sequence value and use the same value on several operations in a trigger to do an audit operation for a table. So when a table is updated, I want to get all the column that were updated. But I want to have them grouped as one when I register the changed column in the database. Is there a way to get a sequence number and store in a variable inside a trigger. The code that I was able to make keeps on getting PLS-00357.
CREATE OR REPLACE TRIGGER TRG_EMPLOYEE_CHANGED AFTER INSERT OR DELETE
OR UPDATE ON EMPLOYEE REFERENCING OLD AS old NEW AS new FOR EACH ROW
DECLARE
GROUPID NUMBER := SEQ_POPERATIONLOG_LOGSUBNO.NEXTVAL;
BEGIN
OPERATION('FIRST_NAME', GROUPID, :old.FIRST_NAME, :new.FIRST_NAME);
OPERATION('LAST_NAME', GROUPID, :old.LAST_NAME, :new.LAST_NAME);
OPERATION('ADDRESS', GROUPID, :old.ADDRESS, :new.ADDRESS);
OPERATION('TELEPHONE', GROUPID, :old.TELEPHONE, :new.TELEPHONE);
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 11g 之前,唯一支持从序列中获取值的语法是:
一种替代解决方案是在第一个 INSERT 语句中使用 NEXTVAL 和 CURRVAL(即此会话中最近分配的值)对于其他人。
Prior to 11g, the only supported syntax for getting a value from a sequence was:
One alternative solution would be to use NEXTVAL in the first INSERT statement and CURRVAL (i.e. the most recently assigned value in this session) for the others.
如果您使用的是 Oracle 10g 或更早版本,那么您需要从 Oracle 的虚拟表 DUAL 中选择序列下一个值。
If you are using Oracle 10g or older then you'd need to select the sequence next value from Oracle's dummy table DUAL.
我想我通过使用 select into 得到了答案。
I think I got the answer by using select into.