gpt4 book ai didi

java - 更新后触发,错误: Scalar subquery is only allowed to return a single row

转载 作者:搜寻专家 更新时间:2023-10-30 23:39:19 25 4
gpt4 key购买 nike

我需要解决我的问题。提前致谢。我使用 Derby DB。

我有一张只有几列的表格。我在更新后为我需要的特定列创建了触发器。当我尝试更新行中的列时出现此错误。

Error code 30000, SQL state 21000: Scalar subquery is only allowed to return a single row.

只有当我在主表中有两行或更多行时才会出现此错误。如果我在表“帐户”中只有一行,一切正常。

这是触发器的代码:(accounts 是主表,accounts_history 是新表)

CREATE TRIGGER aft_update AFTER UPDATE of balance,date
ON accounts

FOR EACH ROW MODE DB2SQL

insert into accounts_history

(old_id,new_name,new_balance,new_date) values
(

(select id from accounts),(select name from accounts),

(select balance from accounts),(select date from accounts)
);

最佳答案

标量子查询应该最多返回一行且恰好返回一列。

只需使用 insert 。 . .选择:

insert into accounts_history(old_id, new_name, new_balance, new_date)
select id, name, balance, date
from accounts;

关于java - 更新后触发,错误: Scalar subquery is only allowed to return a single row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37017171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com