0

I am using

 SELECT REPLACE(REPLACE(Status,'O','New'),'C','Closed') as STATUS, 

in Oracle SQL Select

The problem is that my table has both: 'C' and 'Closed'

So it is actually replacing 'C' with 'Closed' and replacing 'Closed' with 'Closedlosed'

How do I get it to replace only when entire field matches?

4

1 回答 1

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

你能提供样本数据吗?

于 2013-10-18T16:10:06.543 回答