Skip to content
Advertisement

Escape single quotes from comma separated string in Oracle

I am trying to escape single quotes from the comma separated string in Oracle SQL Developer, below is my Select query:

I tried to replace/escape the single quotes from Where IN clause but it gives error of invalid number.

ORA-01722: invalid number

When I am trying to select same string using replace from other select statement it is working.

above query works as expected and gives o/p as '6218, 5577'.

Can anyone please advise, Why it is not working in my main Select statement?

Advertisement

Answer

'6218, 5577' this is a string and not a list of values. So if you do select REPLACE('6218, 5577','''','''''') from dual; you are trying to replace single Quote in your string. since it does not exists in your string, nothing will be replaced.

the result of you select is still the same string and not a list as you expect.

you should split a comma delimited string in rows.

here is one way to do that

than you can use it on your select

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement