sql - Inserting data in another table having different data structure in oracle -
i have table table1
item_code desc month day01 day02 day03 fg0050bcyl0000cd cyl head feb-15 0 204 408 fg00186cyl0000cd power unit feb-15 425 123 202
i want insert data in table table2 table1 in such way.
item_code month date quantity fg0050bcyl0000cd feb-15 01-feb-2015 0 fg0050bcyl0000cd feb-15 02-feb-2015 204 fg0050bcyl0000cd feb-15 03-feb-2015 408 fg00186cyl0000cd feb-15 01-feb-2015 425 fg00186cyl0000cd feb-15 02-feb-2015 123 fg00186cyl0000cd feb-15 03-feb-2015 202
please tell me how achieve via pl sql
the following should close:
begin arow in (select * table1) loop insert table2(item_code, month, "date", quantity) values (arow.item_code, arow.month, to_date(arow.month, 'mon-rr')+0, arow.day01); insert table2(item_code, month, "date", quantity) values (arow.item_code, arow.month, to_date(arow.month, 'mon-rr')+1, arow.day02); insert table2(item_code, month, "date", quantity) values (arow.item_code, arow.month, to_date(arow.month, 'mon-rr')+2, arow.day03); end loop; end;
note column names desc
, date
both reserved words in oracle, requires quoted shown above. simpler use different names, such description
, activity_date
, eliminate need quote these names every time they're used.
best of luck.
Comments
Post a Comment