2013-10-09 53 views

回答

2
SELECT my_function(group_concat(letters)) FROM table WHERE type = 'some_type'; 
+0

我更新了問題,以反映它實際上是一個相當複雜的過程......我不認爲你可以從一個選擇調用程序......對不起,我的問題的歪曲+。 1回答原來的問題。 – OliverSamson43

+0

只要我得到足夠的代表;) – OliverSamson43

2

您可以將值賦給用戶定義的變量,然後將該變量傳遞給該函數。

例如:

SELECT group_concat(letters) 
INTO @foo 
FROM table 
WHERE type = 'some_type'; 

call my_function(@foo); 
2

是的,你可以將字符串傳遞給所返回的子查詢的結果的過程。

但不是作爲裸查詢:

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 

如果你用括號括起來的查詢,則會被計爲標量子查詢,即,必然要返回一行的子查詢,一列:

mysql> call foo((select group_concat(user) from mysql.user)); 
+--------------------+ 
| s     | 
+--------------------+ 
| root,root,bill,xbm | 
+--------------------+ 
相關問題