Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Multi row insert

ömer faruk akyüzlüOct 29 2019 — edited Oct 31 2019

Hello.

This code is not enough. I have summarized my need with an example below.

code color is bold red

example color is black

declare

vcount pls_integer;

pid pls_integer;

alinan pls_integer;

begin

for r in (select id from purchase_order_Details where po_number=:p86_po_number) loop

select count(*) into vcount from teklif_stok where purchase_order_details_id=r.id;

select TOPLAM_GELEN_ADET into alinan from purchase_order_Details where id=r.id;

  if    alinan > vcount then

insert into teklif_stok (purchase_order_details_id) values (r.id) ;

exit when alinan=vcount;

 

elsif alinan < vcount then

delete from teklif_stok where purchase_order_details_id=r.id and urun_adi is null;

end if;

end loop;

commit;

end;

.............................................................................

id= 5 , id=6 (result is 2 rows)

select id from purchase_order_Details where po_number=:p86_po_number;

.....................................................................................................................

select count(*) into vcount from teklif_stok where purchase_order_details_id=5;

vcount=0

select count(*) into vcount from teklif_stok where purchase_order_details_id=6;

vcount=0

...........................................................................................................................

    select TOPLAM_GELEN_ADET into alinan from purchase_order_Details where id=5;

TOPLAM_GELEN_ADET=5

    select TOPLAM_GELEN_ADET into alinan from purchase_order_Details where id=6;

TOPLAM_GELEN_ADET=3

....................................................................................................................................

alinan > vcount   , 5 > 0  and   3> 0

for TOPLAM_GELEN_ADET=5

insert into teklif_stok (purchase_order_details_id) values ('5') ;

insert into teklif_stok (purchase_order_details_id) values ('5') ;

insert into teklif_stok (purchase_order_details_id) values ('5') ;

insert into teklif_stok (purchase_order_details_id) values ('5') ;

insert into teklif_stok (purchase_order_details_id) values ('5') ;

for TOPLAM_GELEN_ADET=3

insert into teklif_stok (purchase_order_details_id) values ('6') ;

insert into teklif_stok (purchase_order_details_id) values ('6') ;

insert into teklif_stok (purchase_order_details_id) values ('6') ;

This post has been answered by ömer faruk akyüzlü on Oct 31 2019
Jump to Answer
Comments
Post Details
Added on Oct 29 2019
4 comments
257 views