oracle PL/SQL 调用触发器内的函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18158894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PL/SQL calling a function inside a trigger
提问by teppuus
I am trying to create a function using Oracle PL/SQL that stores the current date into a variable. This function will be called inside a trigger. The trigger (among other things) will insert this variable into a new table that has already been created. My code complies and runs without errors, but it doesn't work. Nothing happens. The trigger is an ON DELETE trigger, so when I delete one row from the original table, it just stays. Any clues what I am missing? Thank you.
我正在尝试使用 Oracle PL/SQL 创建一个将当前日期存储到变量中的函数。此函数将在触发器内调用。触发器(除其他外)会将此变量插入到已创建的新表中。我的代码符合并且运行没有错误,但它不起作用。没发生什么事。触发器是一个 ON DELETE 触发器,所以当我从原始表中删除一行时,它只是保持不变。我缺少什么线索?谢谢你。
Function:
功能:
CREATE OR REPLACE FUNCTION get_date (i_stdid archive_student.stdid%TYPE)
RETURN date
AS
v_date DATE;
BEGIN
SELECT CURRENT_DATE INTO v_date FROM DUAL;
RETURN v_date;
END;
Function call inside trigger:
触发器内部的函数调用:
CREATE OR REPLACE TRIGGER ARCHIVE_DELETED_STUDENT
AFTER DELETE ON STUDENT
FOR EACH ROW
DECLARE
v_date archive_student.change_date%TYPE;
BEGIN
-- other if statements here that are working properly
v_date := get_date(:old.stdid);
INSERT INTO archive_student (change_date) VALUES (v_date);
END;
采纳答案by ThinkJet
You doing well, check this SQLFiddle.
你做得很好,检查这个 SQLFiddle。
Only one thing - you missed stdid
while inserting into archive_student
so it is null after insert.
只有一件事 - 你stdid
在插入时错过了archive_student
所以插入后它是空的。