2012-09-04 99 views
0

我想使用另一個變量引用一個變量。基本上,我有7個地址字段(地址1,地址等),這將節省編碼,使一個循環,從1到7的很多這裏有一個基本的情況,我需要這樣的:MySQL存儲過程,帶變量名稱的變量

Naddress1 = replace(Naddress1,'.',''); 
Naddress2 = replace(Naddress2,'.',''); 
Naddress3 = replace(Naddress3,'.',''); 
Naddress4 = replace(Naddress4,'.',''); 
Naddress5 = replace(Naddress5,'.',''); 
Naddress6 = replace(Naddress6,'.',''); 
Naddress7 = replace(Naddress7,'.',''); 
Naddress1 = replace(Naddress1,',',' '); 
Naddress2 = replace(Naddress2,',',' '); 
Naddress3 = replace(Naddress3,',',' '); 
Naddress4 = replace(Naddress4,',',' '); 
Naddress5 = replace(Naddress5,',',' '); 
Naddress6 = replace(Naddress6,',',' '); 
Naddress7 = replace(Naddress7,',',' '); 
Naddress1 = replace(Naddress1,'/'',' '); 
Naddress2 = replace(Naddress2,'/'',' '); 
Naddress3 = replace(Naddress3,'/'',' '); 
Naddress4 = replace(Naddress4,'/'',' '); 
Naddress5 = replace(Naddress5,'/'',' '); 
Naddress6 = replace(Naddress6,'/'',' '); 
Naddress7 = replace(Naddress7,'/'',' '); 

我」什麼D類似於:

DECLARE address_iterator INT; 
SET address_iterator = 1; 
WHILE address_iterator <= 7 DO 
Naddress & address_iterator = replace(Naddress & address_iterator, '.',''); 
Naddress & address_iterator = replace(Naddress & address_iterator, ',',' '); 
Naddress & address_iterator = replace(Naddress & address_iterator, '/'',' '); 
END WHILE; 

回答

0

在MySQL中,你可以做這樣的事情 -

UPDATE 
    table 
SET 
    address1 = REPLACE(REPLACE(REPLACE(address1, '.', ''), ',',' '), '/',' '), 
    address2 = REPLACE(REPLACE(REPLACE(address2, '.', ''), ',',' '), '/',' '), 
    address3 = REPLACE(REPLACE(REPLACE(address3, '.', ''), ',',' '), '/',' '); 

否則,你應該在自動化應用這項任務。

+0

忘記提及這是在存儲過程中,但這個答案有很大幫助!謝謝 – user1630799