Firebird SQL:StoredProc 返回 null 而不是分配的值

发布于 2024-12-07 11:14:16 字数 639 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-12-14 11:14:16

由于您没有发布足够的存储过程,所以很难说,但看起来您正在混合可选过程和可执行过程,这是不建议的。即,如果您通过 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 have SUSPEND in it, if you have, then call it via SELECT ... 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 (have SUSPEND in places where you want to return values and call it via SELECT statement) or make it executable (get rid of SUSPEND statements in it and call it via EXECUTE).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文