not allowed to return a resultset from a trigger mysql

前端 未结 1 1954
小蘑菇
小蘑菇 2020-12-30 07:32
delimiter $$
CREATE TRIGGER REDUCE_NOTE_COUNT
 AFTER DELETE ON iv_notes
 FOR EACH ROW  BEGIN
DECLARE supplierid int(11);
DECLARE customerid int(11);

SELECT supplier         


        
相关标签:
1条回答
  • 2020-12-30 08:13

    You cannot execute SELECT statements from trigger. If you want to set variables, then use SELECT INTO statement, e.g. -

    DECLARE supplierid_ INT(11);
    DECLARE customerid_ INT(11);
    
    SELECT
      supplierid, customerid
    INTO
      supplierid_, customerid_
    FROM
      iv_documents
    WHERE
      id = OLD.note_documentid;
    
    IF supplierid_ = OLD.note_companyid THEN
    ...
    

    Also, rename variables, they have to differ from from field names.

    0 讨论(0)
提交回复
热议问题