我必须一次更换不正确的多个数据,所以我使用preg_replace但是我被卡住了,因为它只会替换样式拼写错误。有多种不同的错误样式,我想用一种标准样式替换所有这些样式,所以我使用的是游标。但它给我一个语法错误。
我附上了我的查询。
CREATE PROCEDURE addcorrect()
BEGIN
DECLARE ADDRESS char(90);
DECLARE badaddress CURSOR FOR
SELECT
supplementtal_address_1
FROM aditi_po
WHERE ((
UPPER( street_name ) LIKE '%P%BOX%'
OR UPPER( supplementtal_address_1 ) LIKE 'P%BOX%'
)
AND id NOT IN (
SELECT id
FROM aditi_po
WHERE (street_name LIKE '%PO %Box%'
or supplementtal_address_1 LIKE '%PO %Box%')
));
OPEN badaddress
read_loop: LOOP
FETCH badaddress INTO ADDRESS;
IF done THEN
LEAVE read_loop;
END IF;
if ADDRESS LIKE '%P.O. Box%' THEN
print ADDRESS = PREG_REPLACE('/(.*?)(P.O. Box)/' , '$1PO Box' ,ADDRESS)
ELSE ADDRESS LIKE '%P.O. Box%' THEN print ADDRESS = PREG_REPLACE('/(.*?)(P.O. Box)/' , '$1PO Box' ,ADDRESS)
END IF;
END LOOP;
CLOSE badaddress;
END;
MySQL说:
#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第3行的''附近使用正确的语法
答案 0 :(得分:0)
这个片段看起来很糟糕:
ELSE ADDRESS LIKE '%P.O. Box%' THEN
print ADDRESS = PREG_REPLACE('/(.*?)(P.O. Box)/' , '$1PO Box' ,ADDRESS)
我相信你想要:
ELSEIF ADDRESS LIKE '%P.O. Box%' THEN
print ADDRESS = PREG_REPLACE('/(.*?)(P.O. Box)/', '$1PO Box', ADDRESS)