Firebird 根据查询计算触发器中的字段值
我正在尝试使此触发器起作用:
CREATE trigger trig_tbl_art for tbl_art active before update position 0 AS begin IF (NEW.e OLD.e) THEN IF (NEW.f = OLD.f) THEN NEW.f = SELECT (NEW.e)*CAST(row_b AS NUMERIC(9,2)) FROM table_a WHERE row_a = 'someval'; end
想法是仅在 tbl_art.e 更改时计算 tbl_art.f 的值。
NEW.f 应该是 NEW.e * [查询返回的值]
有什么帮助吗?
I'm trying to make this trigger work:
CREATE trigger trig_tbl_art for tbl_art active before update position 0 AS begin IF (NEW.e OLD.e) THEN IF (NEW.f = OLD.f) THEN NEW.f = SELECT (NEW.e)*CAST(row_b AS NUMERIC(9,2)) FROM table_a WHERE row_a = 'someval'; end
The idea is to compute the value of tbl_art.f only when tbl_art.e changes.
NEW.f should be NEW.e * [the value returned from the query]
Any help please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 PSQL 中,您不能将查询结果直接分配给变量...这是因为查询可以返回多列,但您可以在 select 语句中使用 into 子句:
您有责任确保查询仅返回一行。
In PSQL you cannot assign the result of a query directly to a variable... this is since queries can return multiple columns, but you can use the into clause in your select statement:
You are responsible to ensure the query returns only one row.