SUBSTRING_INDEX和MySQL存储过程

时间:2016-02-23 20:44:01

标签: mysql indexing substring

当我使用SUBSTRING_INDEX和MID和LOCATE函数时,我发现很难让MySQL存储过程工作。第一个Select我有作品,另外2个没有。让这个工作起来的任何帮助都会很棒。

CREATE DEFINER=`root`@`localhost` PROCEDURE `Address`(TBL VARCHAR(50))
BEGIN

SET @table_name = TBL;

SELECT CONCAT("UPDATE kalo.",@table_name,' SET AD1 = REPLACE(AD1,".","  ")') INTO @SQL;
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SELECT CONCAT("UPDATE kalo.",@table_name,' SET STNO = SUBSTRING_INDEX(AD1, ' ', +1)') INTO @SQL;
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SELECT CONCAT("UPDATE kalo.",@table_name,' SET STNM = MID(AD1, LOCATE(' ', AD1) + 1)') INTO @SQL;
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

END

0 个答案:

没有答案