The problem:
I have a table that contains a CLOB which is a fixed length record from an external source. Where positions 1-5 = fieldA, positions 6-12 = fieldB, etc.
I have another table (LayoutDefinition)that defines that record layout, where
FieldName = 'fieldA'
FieldStart = 1
FieldLength = 5
FieldName = 'fieldB'
FieldStart = 6
FieldLength = 6
I need to retrieve the data from the CLOB and put it into a %rowtype variable such as "tableA_rec tableA%rowtype."
I have implemented a routine that uses a massive case statement, and a loop for each row in the LayoutDefiniton table moves the area of the CLOB into the proper variable in the tablea_rec like;
CASE LayoutDefiniton.FieldName
WHEN 'fieldA' THEN tablea_rec.fieldA:= SUBSTR(inputClob,LayoutDefiniton.FieldStart,LayoutDefiniton.FieldLength);
WHEN 'fieldB' THEN tablea_rec.fieldB:= SUBSTR(inputClob,LayoutDefiniton.FieldStart,LayoutDefiniton.FieldLength);
This of course is very inefficient, as I need to loop through my layout for each record picking apart my data.
What I would like to do is to create a dynamic sql select statement once that will retrieve the data from the table into the proper variables. For example if it were not dynamic it might look like;
select substr(inputCLOB,1,5), substr(inputCLOB,6,6) into FieldA, fieldB from CLOBTable;
Can this be done using Dynamic SQL?
If so what would the syntax look like?