2012-06-01 36 views
0

我一直遇到问题,即在附加了触发器后将值插入表中。 触发如下:DB2 SQL - 在触发器生成后无法成功插入表

CREATE TRIGGER trig 
AFTER INSERT ON Follows 
REFERENCING NEW as N 
FOR EACH row 
WHEN ((Select email from Celebrity) <> N.followed_email) 
UPDATE followSuggestion SET followSuggestion.Suggested_follower = N.followed_email, followSuggestion.Suggested_followee = N.follower_email 
; 

插入代码如下:

INSERT INTO follows 
VALUES('[email protected]','[email protected]'); 

,误差如下

DB21034E The command was processed as an SQL statement because it was not a 
valid Command Line Processor command. During SQL processing it returned: 
SQL0811N The result of a scalar fullselect, SELECT INTO statement, or VALUES 
INTO statement is more than one row. SQLSTATE=21000 

SQL0811N The result of a scalar fullselect, SELECT INTO statement, or VALUES INTO statement is more than one row. 

谢谢先进!

回答

3

,我认为这就是问题所在:

(Select email from Celebrity) <> N.followed_email 

子查询可能会返回多个行,以便标量操作<>将无法正常工作。 您必须将该条件改为类似于:

WHEN ((Select COUNT(email) from Celebrity WHERE email = N.followed_email) = 0) ... 
+0

非常好的一点,非常感谢您的简洁明确的答案! – Quentin