set @s1 = (select if ((select count(*) from information_schema.columns where table_name='foo' and column_name='bar_id') > 0,
'select 1',
'alter table foo add column bar_id bigint;'));
prepare stmt from @s1;
execute stmt;
deallocate prepare stmt;
update foo set bar_id = baz_id;
に私のコードを変更した場合、私は更新ステートメント
set @s1 = (select if ((select count(*) from information_schema.columns where table_name='foo' and column_name='bar_id') > 0,
'select 1',
'alter table foo add column bar_id bigint; update foo set bar_id = baz_id;'));
prepare stmt from @s1;
execute stmt;
deallocate prepare stmt;
近くMySQLの構文に問題があると言う
それが動作します。 if文の中にupdate文が必要です。
私はこれをSPにすることはできません。
エラー:あなたの最初のコードブロックで
ERROR 1064 (42000): 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 'update foo set bar_id = baz_id' at line 1
エラーメッセージを読んでみてください。通常は何が間違っているのかを示します。 –
エラーはちょうど私に正しい構文を使用するように頼みます。 –
いいえ、慎重に見てください:**近所 'update foo set ** –