我正在使用
SELECT REPLACE(REPLACE(Status,'O','New'),'C','Closed') as STATUS,
Oracle SQL Select中的
问题是我的桌子有两个: 'C' 和 '闭合'
所以它实际上用'Closed'替换'C'并用'Closedlosed'替换'Closed'
如果仅在整个字段匹配时如何才能将其替换?
答案 0 :(得分:2)
一种可能的解决方案是使用正则表达式仅匹配C
字符而不是其他内容:
WITH
my_data AS
(SELECT 'Closed' AS status FROM dual
UNION ALL SELECT 'C' AS status FROM dual)
SELECT
regexp_replace(status, '^C$', 'Closed') AS rep_status
FROM
my_data
;
检查SQLFiddle:http://sqlfiddle.com/#!4/d41d8/19247
您能提供样本数据吗?