写了一个存储过程,参数是输入数据库名称和表名称,然后对该表的所有字段进行操作,过程如下:
BEGIN
#将表格中含有\N的值置为空
DECLARE table_column VARCHAR(64);
DECLARE flag SMALLINT DEFAULT 0;
DECLARE curl1 CURSOR FOR
SELECT COLUMN_NAME FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = my_data_base AND TABLE_NAME = my_table_name;
DECLARE EXIT HANDLER FOR NOT FOUND SET flag = -1;
OPEN curl1;
REPEAT
FETCH curl1 INTO table_column;
SET @sql1 = CONCAT('UPDATE ', my_data_base, '.', my_table_name, ' SET ', table_column, ' = NULL WHERE ',
table_column, " = \'\\\\N'\; " );
SELECT @sql1;
PREPARE pre1 FROM @sql1;
EXECUTE pre1;
UNTIL flag = -1 END REPEAT;
DEALLOCATE PREPARE pre1;
CLOSE curl1;
END