0

このトリガーを作成しようとすると、次のエラーが発生します。

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'case where artcStackId = new.artcStackId' at line 7

これが失敗したトリガーです

SET new.artcPublicId = 
 case 
 when new.artcCountry = 'US' then concat(91,new.artcStackId)
 when new.artcCountry = 'UK' then concat(92,new.artcStackId)
 when new.artcCountry = 'CA' then concat(93,new.artcStackId)
 else concat(11,new.artcStackId)
 end case
 where artcStackId = new.artcStackId

これが機能するトリガーです

SET new.artcPublicId = 
case 
when new.artcCountry = 'US' then concat(91,new.artcStackId)
when new.artcCountry = 'UK' then concat(92,new.artcStackId)
when new.artcCountry = 'CA' then concat(93,new.artcStackId)
else concat(11,new.artcStackId)
end

これらの余分なビットを追加すると、失敗します。

4

2 に答える 2

0

最初のトリガーに構文エラーがあります:

end case

公正であるべき

end

つまり、末尾の「ケース」を削除します

編集:

where 条件があることに気付きました: where artcStackId = new.artcStackId
そんなことはできません。new.構文によって参照される現在の行のみを変更できます。

挿入/更新される行のみを更新できるため、where 句を完全に削除する必要があります。

于 2013-01-18T07:33:34.930 に答える
0

どこの条件への参照はありません.私はそれが好きであるべきだと思います where new.artcStackId = new.artcStackId

于 2013-01-18T07:47:31.033 に答える