对SELECT中的单个字段进行双重REPLACE

时间:2012-09-18 15:39:32

标签: mysql

如何在同一个字段上运行两次替换的选择?

SELECT `id`, `name`, `address`, REPLACE( `info`, '|', '-' ) AS `info` 
INTO OUTFILE '/tmp/" . $SESSION . "NET_SCAN.csv' 
FIELDS TERMINATED BY '|' 
ENCLOSED BY '' 
LINES TERMINATED BY '\n' 
FROM `net_scan`;

我想在同一个字段上运行辅助REPLACE。

2 个答案:

答案 0 :(得分:4)

只需在其中使用REPLACE

REPLACE(REPLACE(field, 'bad', 'good'), 'better', 'worse')

答案 1 :(得分:2)

replace(REPLACE( `info`, '|', '-' ), 'x', 'y'))