简体   繁体   中英

Split comma delimited string with array values

I wanted to replace a data from release db to test db with prefix(each store in storeList array).

I'm getting error like "Unknown system variable 'store'"

But I don't know why this error occurs.

DELIMITER
CREATE PROCEDURE `replace_release_to_test_db`(baseUrl VARCHAR(255),     substituteDomain VARCHAR(255), IN storeList VARCHAR(255))
BEGIN
   DECLARE pos int;
   SET storeList = LTRIM(RTRIM(storeList))+ ',';
   SET pos = SUBSTRING_INDEX(storeList,',', 1);
        WHILE pos > 0 do
            SET store = LEFT(storeList, pos - 1);
            IF store <> '' THEN
                SET oldDomain = CONCAT(store,".",baseUrl);
                SET newDomain = CONCAT(substituteDomain,"-",store,".",baseUrl);
                UPDATE core_config_data SET value = REPLACE(value, oldDomain, newDomain);
            END IF
            SET storeList = RIGHT(storeList, LEN(storeList) - pos);
            SET pos = SUBSTRING_INDEX(storeList,',', 1);
        END WHILE;

        UPDATE core_config_data SET value = REPLACE(value, CONCAT("http://",baseUrl), CONCAT("http://"substituteDomain,".",baseUrl));
        UPDATE core_config_data SET value = REPLACE(value, CONCAT("https://",baseUrl), CONCAT("https://"substituteDomain,".",baseUrl));

        SELECT * FROM core_config_data WHERE value LIKE '%abc.kr%';
END
DELIMITER;

CALL replace_release_to_test_db("abc.kr","test", "my,sg,ph,id,th,us,my-mobile,sg-mobile,ph-mobile,id-mobile,th-mobile,us-mobile")

You have SET store = LEFT(storeList, pos - 1); (and IF store ... and so on) but you have not declared a variable named store .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM