I have an old legacy data-producing system that provides we data with some identifiers, and then 48 columns. The first 24 columns show units, and then the next 24 show values.
I had thought that maybe I could normalise these when loading with SQLLDR, but as these are comma-seperated rather than positional I thought maybe it would be best to load these into a temp table and then run a PL/SQL Loop to normalise them.
So, my loaded table looks like this:
The months that are provided in each of the 24 columns are a movable feast, but the month is loaded elsewhere, so I have at least worked out how to grab that.
This is what I have begun with:
but already this doesn't work. I get the following error:
ERROR at line 10:
ORA-06550: line 10, column 3:
PL/SQL: ORA-00936: missing expression
ORA-06550: line 7, column 2:
PL/SQL: SQL Statement ignored
ORA-06550: line 12, column 54:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
begin case declare end exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier
And I still haven't got my brain around the way to pick the column names in some kind of loopy-cursor type deal.
I strikes me that someone else must have done this before - so any pointers you guys could give me would be really helpful.
Fee
The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
I had thought that maybe I could normalise these when loading with SQLLDR, but as these are comma-seperated rather than positional I thought maybe it would be best to load these into a temp table and then run a PL/SQL Loop to normalise them.
So, my loaded table looks like this:
Code:
GEOGRAPHY CHAR(5)
CEG_PROD_CODE VARCHAR2(14)
UM1 NUMBER(38)
UM2 NUMBER(38)
...
UM23 NUMBER(38)
UM24 NUMBER(38)
VM1 NUMBER
VM2 NUMBER
...
VM23 NUMBER
VM24 NUMBER
DATE_LOADED DATE
This is what I have begun with:
Code:
DECLARE
fee date;
BEGIN
select add_months(period_number,-24) into fee from ff_header;
for i in 1..24
loop
insert into FF_board
(GEOGRAPHY,CEG_CODE,MNTH,UNIT,VALUE)
VALUES
(select A.GEOGRAPHY, SUBSTR(A.CEG_PROD_CODE, 2,13),
(SELECT TO_CHAR(ADD_MONTHS(FEE,i),'YYMM') FROM DUAL;),
a.UM1, a.VM1
from
ff_results a, ff_territory b
where a.brick = b.brick);
end loop;
end;
ERROR at line 10:
ORA-06550: line 10, column 3:
PL/SQL: ORA-00936: missing expression
ORA-06550: line 7, column 2:
PL/SQL: SQL Statement ignored
ORA-06550: line 12, column 54:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
begin case declare end exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier
And I still haven't got my brain around the way to pick the column names in some kind of loopy-cursor type deal.
I strikes me that someone else must have done this before - so any pointers you guys could give me would be really helpful.
Fee
The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]