New to SQL. Using oracle sql developer Version 3.1.07. Is there any way to separate elements of a string column that contains a string like:
dublin.ie;montreal.com;paris.com
I want to split them based on the ; so that I can manipulate them individually (and do so for every row of the table). This is because I want to delete everything that ends in .com but not effect the rest.
I want to use the most basic sql I can, as I am quite the newbie and I’m using quite an old version.
Any ideas? Thanks again you guys. The help so far has been great.
I’d say the table is badly structured – there should be a row for each domain. That is going to make a solution very difficult for a beginner.
You need a piece of sql that will create a row for each domain stored in the ; separated list.
so dublin.ie;montreal.com;paris.com;bristol.uk
becomes:-
and then bind the rows that don’t have .com back into a single row, to get
I had a similar issue – I has a field that contained comma separated country codes.
The report user I was working for wanted country names. I had a COUNTRY table that contained Country Code and Country Name, but the comma separated list wouldn’t join to it, as it has “GB,FR,IT” where the country table has “GB” for “Great Britain” and so on.
I solved this by creating a row (in memory) for each of the comma separated values, joining these rows to the COUNTRY table, returning the names of the countries, and then bound the country name back into a single line, like this:-
“Great Britain, France, Italy”.
Here’s the code I used – it’s not for beginners, though. You might want to try using REPLACE and INSTR and SUBSTR, but you’ll need to know in advance how many entries each field contains, otherwise you’ll probably need to work within loops, using PLSQL.
If i were you, I’d ask the DBA (if it is possible) to structure the data properly so that the fields contain atomic values, not arrays of values.