Firebird SQL:StoredProc 返回 null 而不是分配的值
我有一个 Firebird StoredProc 在插入之前和更新之前从触发器运行,并且还返回 3 个值。这 3 个值直接更新同一个表中的 3 个字段
我在 SP 开头进行了检查,如果检查为真,我想跳过该 SP,所以我使用了“挂起”和“退出”,但是当我这样做时,我发现了 3 个字段更新为空值。这是为什么 ?
触发器:
CREATE OR ALTER trigger trig1 for table1
active before insert or update position 2
AS
begin
execute procedure my_proc1 new.f1, new.f2
RETURNING_VALUES new.f3, new.f4, new.f5;
end
StoredProc(它非常大,我只放了第一行):
begin
if (COALESCE(Param1,0) = 1) then begin
output1 = 0;
output2 = 0;
output3 = 0;
exit;
end
即使我删除了 IF 块并保留其他所有内容,我在 3 个字段中也不会得到零,而是 NULL !!!。请指教
谢谢
I have a Firebird StoredProc run from a trigger before Insert and before update and also return 3 values. Those 3 values update 3 fields directly in the same table
I put a check at the SP beginning if the check is true I want to skip that SP so I used "suspend" and "Exit" but when I did that I found the 3 fields updates with null value. why is that ?
The trigger:
CREATE OR ALTER trigger trig1 for table1
active before insert or update position 2
AS
begin
execute procedure my_proc1 new.f1, new.f2
RETURNING_VALUES new.f3, new.f4, new.f5;
end
the StoredProc (it is very big I put only first lines):
begin
if (COALESCE(Param1,0) = 1) then begin
output1 = 0;
output2 = 0;
output3 = 0;
exit;
end
Even if I removed the IF block and kept everything else I dont get zeros in the 3 fields but NULL !!!. Please advise
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您没有发布足够的存储过程,所以很难说,但看起来您正在混合可选过程和可执行过程,这是不建议的。即,如果您通过
EXECUTE PROCEDURE
调用 SP,则不应在其中包含SUSPEND
,如果有,则通过SELECT ... FROM SP
调用它代码>. FireBird 在最近的版本中在这方面更加严格,尽管我认为如果您使用“错误的调用机制”,它不会引发异常...无论如何,如果您在可选择的 SP 中调用
EXIT
,那么它会设置 SQLCODE到 100(记录流结束),IOW 它不会设置输出值。所以我的建议是你“清理”你的 SP,要么让它可选择(在你想要返回值的地方有SUSPEND
并通过SELECT
语句调用它)或者使其可执行(删除其中的SUSPEND
语句并通过EXECUTE
调用它)。As you haven't posted enough of the stored procedure, it is hard to tell, but it looks like you're mixing selectable and executable procedures which is not recommended. Ie if you call the SP via
EXECUTE PROCEDURE
you should not haveSUSPEND
in it, if you have, then call it viaSELECT ... FROM SP
. FireBird is stricter in that regard in recent versions, althought I think it doesn't raise exception if you use "wrong calling mechanism"...Anyway, if you call
EXIT
in selectable SP then it sets SQLCODE to 100 (end of record stream), IOW it doesn't set output values. So my suggestion is that you "clean up" your SP, either make it selectable (haveSUSPEND
in places where you want to return values and call it viaSELECT
statement) or make it executable (get rid ofSUSPEND
statements in it and call it viaEXECUTE
).