I am using an Oracle database and I'm trying to select values between parentheses. Here is my table, which has ID
and Roads
as columns. I have read-only access to this database so I can only use SELECT
:
ID Roads
-- -----
1 #Chaussée de Waterloo (Ixelles)#
2 #Rue Reper-Vreven (Bruxelles)#
3 #Rue des Fraises (Anderlecht)#
4 #Chaussée de Roodebeek (Woluwe-Saint-Lambert)#
5 #Square Jean Absil (Etterbeek)#Avenue Hansen-Soulie (Etterbeek)#Avenue Le Marinel (Etterbeek)#
Basically, from the Roads
column, I only want to keep the values between parentheses. As the final query has other tables in it, I want a select distinct. The desired output is:
ID Roads
------------------
1 Ixelles
2 Bruxelles
3 Anderlecht
4 Woluwe-Saint-Lambert
5 Etterbeek, Etterbeek, Etterbeek
I tried the following query, which works fine when there is only one set of parentheses, but this doesn't work when there are several (like for ID 5), as it only gives back the values in the first set of parentheses:
select distinct substr(roads, instr(roads,'(') + 1, instr(roads,')') - instr(roads,'(') - 1) as roads
from table
Does anyone know where I'm going wrong?