首页 > 解决方案 > 在oracle中将字符串转换为字符

问题描述

嗨,我有以下数据'1,2,3',我需要将其转换为'1','2','3'我将在此使用的数据

Select * from dual where to_chat(month) in ('1','2','3')

由于quater,我不能像那样直接使用查询

Quater no.    Month
1             1,2,3
2             4,5,6
...  

所以我必须像这样使用 case 但 case 语句以这样的格式返回'1','2','3'

 Select * from dual 
where to_chat(month) in (
select 
case quarter 
when 1 then '1','2','3' 
when 2 then '4','5','6' 
end 
from dual )

输入

'1,2,3'

预期产出

'1','2','3'

标签: sqloracleoracle11goracle-sqldeveloper

解决方案


您可以使用regexp_like()

where regexp_like(<whatever>, replace('1,2,3', ',', '|'))

在字符串中加上单引号仍然不能让你做你想做的事情like。它仍然是一个字符串,但其中包含单引号和逗号。


推荐阅读