我查看了类似的问题,但似乎没有一个能帮助我解决我得到的错误。
以下是我要创建的程序:
CREATE PROCEDURE replaceFieldTextTo (IN v_string_from VARCHAR(255), IN v_string_to VARCHAR(255))
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE table_name_value VARCHAR(64);
DECLARE column_name_value VARCHAR(64);
DECLARE cursor_fields CURSOR FOR SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE 'field_%_value';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor_fields;
ColumnList: LOOP
FETCH cursor_fields INTO table_name_value, column_name_value;
IF done THEN
Leave ColumnList;
END IF;
SET @sql = CONCAT('UPDATE ', table_name_value, ' SET ', column_name_value, ' = replace(', column_name_value, ', "', v_string_from, '", "', v_string_to ,'"');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END LOOP;
CLOSE cursor_fields;
END;
语句本身创建得很好。但是调用它会导致错误。
基本上我想在多个表中查找和替换文本,但我得到:
mysql> CALL replaceFieldTextTo("http://dev.mywebsite.org","/");
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
我没有真正看到这个问题。我在mysql控制台中使用delimiter //
和delimiter ;
之后将其作为前缀。