DELIMITER //
DROP PROCEDURE IF EXISTS uppercasecol //
CREATE PROCEDURE uppercasecol(IN tblname VARCHAR(200))
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE oldname VARCHAR(200);
DECLARE cur CURSOR FOR SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='ADM01' AND TABLE_NAME=tblname;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
REPEAT
FETCH cur INTO oldname;
SET @newname = UPPER(oldname);
#IF newname equals to oldname, do nothing;
#select 'a' <> 'A'; -> 0
#select 'a' <> BINARY 'A'; -> 1
SET @isNotSame = @newname <> BINARY oldname;
IF NOT done && @isNotSame THEN
SET @SQL = CONCAT('ALTER TABLE `',tblname,'` CHANGE COLUMN `',oldname,'` @newname');
PREPARE tmpstmt FROM @SQL;
EXECUTE tmpstmt;
DEALLOCATE PREPARE tmpstmt;
END IF;
UNTIL done END REPEAT;
CLOSE cur;
END //
DELIMITER ;
CALL uppercasecol('USER_MODULE');
我使用上面的代码将列名转换为大写,但代码在CONCAT中给出错误1604(42000)('ALTER TABLE ',tblname,'
CHANGE COLUMN ',oldname,'
@newname')。任何人都可以帮助我...
thanx