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 的方式无法获取到返回值,求大神指点。

解决方案 »

  1.   

    没问题啊
    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 preparedQuery 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)