0

I need to write a SQL query which can fetch a data from one table A.

Senario - Lets take table A has only two column C1 and C2. C1 has row_id's and C2 has vaues like "Site=google;site=gmail,site=yahoo"

Requirment - Need to write a query which can fetch all the row_id from column C1 of table A but the value should come for column C2 as "google;gmail;yahoo". Means it should not show "Site=" for all the values of C2 column in the data fetch. And one more condition that if there is , in place of ; in the value then query should convert it into ; and show the data.

1 Answer 1

4

How about this:

SELECT C1, REPLACE(REPLACE(C2, 'Site=', ''), ',', ';') AS C2
  FROM TABLE

Share and enjoy.

Sign up to request clarification or add additional context in comments.

3 Comments

You need another replace to take Site= and site= into account: SELECT REPLACE(replace(replace('Site=google;site=gmail,site=yahoo', 'Site=', ''), 'site=', ''), ',', ';') AS C2 FROM dual
Thanks for your help..I got resuld :)
@Rene - I thought about that, but decided it was better to leave it as posted to keep it clearer. The OP can add more REPLACE's (or change it to REPLACE(LOWER(C2), 'site=', '') if wanted.

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.