Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL Newbie Help / Stored Procedure
On 10 May 2002, kshorty_at_phat.com wrote:
> I am trying to create several stored procudures that need to
> accomplish the same task. There is an import table, a map table, and a
> desintation table. I need to loop through the import table, match the
> item number to the mapped id and insert in a new destination table.
> There needs to be a contraint where if the id/date combination already
> exists the row in the destination table is updated vs. inserted.
>
> This should be straightforward, but I keep trying and it does not seem
> to work for me. Originally I created a temporary view and used to map.
> Then I did a giant insert. And in some cases the number of columns in
> the import tables are large. It would be nice to have some checking
> and the capability to move to the next row if one row fails.
>
>> select * import_table
>> select * from map
Do an update of what exists and then an insert of new stuff.
update
(
select item_desc_dest, item_desc_src
from import_table src, map, dest
where src.item_no = map.item_no and map.id = dest.id and src.item_date = dest.item_date
insert into dest (id,item_date,item_desc) select map.id, src.item_date, src.item_desc from import_table src, map, dest
where src.item_no = map.item_no and map.id = dest.id (+) and src.item_date = dest.item_date (+)and dest.id IS NULL
-- Galen deForest Boyer Sweet dreams and flying machines in pieces on the ground.Received on Fri May 10 2002 - 19:46:11 CDT
![]() |
![]() |