Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extract Data from Comma Separated List with embedded commas

TubbyOct 24 2018 — edited Oct 25 2018

Howdy,

Within PL/SQL I will have a string value and I need to slice out a portion of that string. The list will be comma delimited BUT will have embedded commas which is where I'm facing my problems.

My requirement is that I will pass a numerical value corresponding to which embedded string I require from my "master string".

A sample of the data I will have is

'F', TO_DATE(' 2007-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'), to_date('01-dec-2018','dd-mon-yyyy')

In PLSQL

declare

  l_high_value varchar2(4000) :=  q'!'F', TO_DATE(' 2007-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'), to_date('01-dec-2018','dd-mon-yyyy') !' ;

begin

  dbms_output.put_line(l_high_value);

end;

/

So this "master string" is comprised of 3 values separated by commas. The problem I am having is that the TO_DATE also has comma values within it and there is no way to know how many commas it will have (hence my sample data).

Within the string above there are 3 values:

  Value 1 above = 'F'

  Value 2 above = TO_DATE(' 2007-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

  Value 3 above = to_date('01-dec-2018','dd-mon-yyyy')

The expectation is that if I pass in a value of 1 to whatever function/routine used I will receive the output of 'F'.

If I pass in the value of 2 I will get TO_DATE(' 2007-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')

If I pass in the value 3 I will get to_date('01-dec-2018','dd-mon-yyyy').

Any questions please let me know.

Cheers,

This post has been answered by Sven W. on Oct 24 2018
Jump to Answer
Comments
Post Details
Added on Oct 24 2018
12 comments
2,407 views