SET m = CONCAT(N'SELECT COUNT(*) INTO @columnExistsCache FROM information_schema.columns WHERE UPPER(TABLE_SCHEMA) = UPPER('',tableSchema,'') AND UPPER(TABLE_NAME) = UPPER('',tabName,N'') AND UPPER(COLUMN_NAME) = UPPER('',columnName,'');');
SET @sqlStr = m;
PREPARE stmt FROM @sqlstr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET columnExists = @columnExistsCache;通過動態sql方式判斷列是否存在,但是select into @para 的方式無法獲取到回傳值,求大神指點。
uj5u.com熱心網友回復:
找到原因了,動態傳參時,引數的前后需要加入轉義單引號。uj5u.com熱心網友回復:
沒問題啊set @a=null;prepare st from 'select count(*) into @a from information_schema.columns'; execute st; deallocate prepare st; select @a;
mysql> set @a=null;prepare st from 'select count(*) into @a from information_schema.columns'; execute st; deallocate prepare st; select @a;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Statement prepared
Query OK, 1 row affected, 2 warnings (0.04 sec)
Query OK, 0 rows affected (0.00 sec)
+------+
| @a |
+------+
| 3532 |
+------+
1 row in set (0.00 sec)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/102409.html
標籤:MySQL
