I'm afraid that regex of the form '[^#]+'
does not handle NULL elements. Unfortunately it's the most common answer for questions on parsing delimited strings. For proof and details see post: https://stackoverflow.com/a/31464699/2543416. Using it, the data set with a NULL element 2 gives the following result set:
SUBS
-----------
substr1
substr3
substrN
<NULL here>
SQL>
Instead use this form built on Littlefoot's answer (Note element 2 is NULL):
with test as (select 'substr1##substr3#substrN' col from dual)
select regexp_substr(col, '(.*?)(#|$)', 1, level, NULL, 1) subs
from test
connect by regexp_substr(col, '(.*?)(#|$)', 1, level) is not null;
SUBS
-----------
substr1
substr3
substrN
SQL>
Here the 2nd element's NULL is preserved and the remaining values are in the correct position.
For your case, you may not care about the position of the value, just that it is in the list. But, for re usability (and for accuracy), you could turn this into a function where you pass in the string, the delimiter, and the value you are after and have it return it's position. Non-zero means it is in the list and also you have it's position if that is ever needed. Just a thought.