Skip to content

Instantly share code, notes, and snippets.

@hoogenm
Created April 30, 2024 15:56
Show Gist options
  • Save hoogenm/242c8ca57c5e8927a6e640570a06be96 to your computer and use it in GitHub Desktop.
Save hoogenm/242c8ca57c5e8927a6e640570a06be96 to your computer and use it in GitHub Desktop.
Split/splitting a comma delimited string in Oracle (PL/) SQL
select regexp_substr('1,2,3,4','[^,]+', 1, level)
from dual
connect by regexp_substr('1,2,3,4', '[^,]+', 1, level) is not null;
-- Nice, smart, declarative way to split a comma-delimited string in Oracle SQL.
-- From: https://forums.oracle.com/ords/apexds/post/the-fastest-way-to-convert-comma-separated-list-into-table-3353
-- This may be slow for a long string, but for parsing a config value this results in concise code and may prevent boilerplate code.
-- Replace the 'copied & pasted' string (e.g. '1,2,3,4' in the example above) by one variable/constant in PL/SQL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment