I would gratefully receive any help regarding SQL query. I have a single field with a set of data stored in the field ‘DataSet’ that is delimited by | and follows the pattern of
per line with an unlimited number of lines
example entry in the DataSet field could be
what I want to do with a SQL command is to first split the complete data set into lines and also into values i.e
i.e tmpVal6 is the remainder of DataSet that hasn’t been parsed. I then plan to set Dataset = tmpVal6 and loop through this until all rows are done.
I’ve got so far in that I know how to select tmpVal2,3,4,5
With help from google I've managed to work out how to retrieve the individual values, but Im stuck on the obvious bit
How do I improve the SQL statement below to store values tmpVal1 and tmpVal6? a colleague on his way out took a quick look and said "oh, use dual"??
but my SQL knowledge is very limited at best so excuse the stupidness of my request..
I'm gonna go grab some food and let my brain cool down before tackling it again.
Cheers
Chef
product name|product code|version name|version code
example entry in the DataSet field could be
first|12345|version745|99985
second|23456|ver666|68452
third|3456_00|v9864|7777
second|23456|ver666|68452
third|3456_00|v9864|7777
Code:
tmpVal1 = first|12345|version745|99985 tmpVal2 = first tmpVal3 = 12345 tmpVal4 = version745 tmpVal5 = 99985 tmpVal6 = second|23456|ver666|68452 third|3456_00|v9864|7777
I’ve got so far in that I know how to select tmpVal2,3,4,5
With help from google I've managed to work out how to retrieve the individual values, but Im stuck on the obvious bit
How do I improve the SQL statement below to store values tmpVal1 and tmpVal6? a colleague on his way out took a quick look and said "oh, use dual"??
but my SQL knowledge is very limited at best so excuse the stupidness of my request..
Code:
select substr(DataSet,1,instr(DataSet,'|')-1) tmpVal2 ,substr(DataSet,instr(DataSet,'|')+1 ,instr(DataSet,'|',1,2) -instr(DataSet,'|',1,1)-1) tmpVal3 ,substr(DataSet instr(DataSet,'|',1,2)+1 ,instr(DataSet,'|',1,3) -instr(DataSet,'|',1,2)-1) tmpVal4 ,substr(DataSet instr(DataSet,'|',1,2)+1 ,instr(DataSet,'|',1,4) -instr(DataSet,'|',1,3)-1) tmpVal5 from (select DataSet aString from dual)
Cheers
Chef
Comment