2010-02-19 46 views

回答

1

這應該工作:

SET @y = CONCAT('SELECT ', @x, ' FROM table;'); 
PREPARE stmt1 FROM @y; 
EXECUTE stmt1; 
+0

...標籤太多;/ – skyman 2010-02-19 11:29:42

+0

您需要在「FROM」 – cjk 2010-02-19 11:49:12

1

可以使用prepared statement如下:

SET @x = 'some_field'; 

SET @s = CONCAT('SELECT ', @x, ' FROM table;'); 

PREPARE stmt FROM @s; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt; 
相關問題