2

I want to replace two things in one select statement. Now I can replace one character at a time. But as per my requirment, I need to replace two things in one statement.I want to replace one special character by Zero and another is this data is stored in multiple lines. I want to fetch this data in one line.

select replace(message,chr(ACII_Value),0) 
from my_table -- I can replace special character by zero using this.

select (message,chr(10),' ') 
from my_table -- I can put all data in single line using this.

Now I want to do this in one select statement.

2 Answers 2

6
select replace( replace( message, chr(ACII_Value), 0), chr(10), ' ') 
from my_table;
Sign up to request clarification or add additional context in comments.

Comments

1

An alternative is the TRANSLATE function:

select translate(message, chr(ASCII_Value)||chr(10), '0 ') from my_table;

Although if you're only replacing two characters, I'd go with @schurik's answer since it uses a simpler, more common function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.