私は動作するストアドプロシージャを持っています:
call my_procedure('A,B,C,D');
A、B、Cに別のテーブルのサブクエリからのリストを入力したい、例えば:
call my_procedure(
SELECT group_concat(letters) FROM table WHERE type = 'some_type')
);
可能?それとも私はそれを間違っていますか?
私は動作するストアドプロシージャを持っています:
call my_procedure('A,B,C,D');
A、B、Cに別のテーブルのサブクエリからのリストを入力したい、例えば:
call my_procedure(
SELECT group_concat(letters) FROM table WHERE type = 'some_type')
);
可能?それとも私はそれを間違っていますか?
値をユーザー定義変数に割り当ててから、その変数を関数に渡すことができます。
例えば:
SELECT group_concat(letters)
INTO @foo
FROM table
WHERE type = 'some_type';
call my_function(@foo);
はい、サブクエリの結果として返される文字列をプロシージャに渡すことができます。
しかし、裸のクエリとしてではありません:
mysql> create procedure foo (in s text) begin select s; end !!
mysql> call foo( select group_concat(user) from mysql.user );
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
'select group_concat(user) from mysql.user )' at line 1
クエリを括弧で囲むと、スカラー サブクエリ、つまり 1 行 1 列を返すようにバインドされたサブクエリとしてカウントされます。
mysql> call foo( (select group_concat(user) from mysql.user) );
+--------------------+
| s |
+--------------------+
| root,root,bill,xbm |
+--------------------+