Home » SQL & PL/SQL » SQL & PL/SQL » insert into
insert into [message #603605] Tue, 17 December 2013 19:26 Go to next message
nataliafoster26
Messages: 64
Registered: October 2013
Member
insert into
before i do this i want to know if is possible
to have

if....then
begin
update......
commit;
insert into table(......)

insert into table_2(....)

exception when others then
......
end;


1)i know it will work with one insert into,
but will it work if i have to insert into?
2) if one insert into talbe doesnt compile good will it throw a exception too?
Re: insert into [message #603607 is a reply to message #603605] Tue, 17 December 2013 20:28 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
Assuming everything compiles, the code will jump straight to the exception block as soon as it encounters the first runtime error. So in your case, if there is an error in the first INSERT then the second INSERT will not run and therefore cannot throw an error.

Ross Leishman
Re: insert into [message #603608 is a reply to message #603605] Tue, 17 December 2013 20:29 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
If/when compile time error occurs, then no run time EXCEPTION is possible since no procedure exists to be executed.

do you really want to COMMIT after UPDATE & before EXCEPTION handler ROLLBACK after INSERT EXCEPTION?

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: insert into [message #603617 is a reply to message #603605] Wed, 18 December 2013 00:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Also read WHEN OTHERS.

Re: insert into [message #603706 is a reply to message #603617] Wed, 18 December 2013 10:30 Go to previous messageGo to next message
nataliafoster26
Messages: 64
Registered: October 2013
Member
just to give you an idea this is how the original code looks like
with only one insert. as i can see doing it with 'when others' is not a good
idea but i cant change it or atleast they told me i shouldnt
IF vReturnValue = 'SUCCESS' THEN
                           BEGIN
                                UPDATE p_contract_mf_auto_debit
                                SET last_pymt_date = sysdate,
                                    payments_processed = NVL(payments_processed,0) + 1
                                WHERE contr_num IN (SELECT cad.contr_num
                                                    FROM p_contract_mf_auto_debit cad, p_contract_lead cl, p_contract_purchase cp, ar_club_group gc, p_member_contract mc
                                                    WHERE cad.contr_num = cp.contr_num
                                                    AND cp.contr_num = cl.contr_num
                                                    AND cl.lead_id = x.lead_id
                                                    AND cp.club_mbr_type = gc.mbr_type
                                                    AND opt_in = 'Y'
                                                    AND mc.parent_mbr_contr_id = x.parent_mbr_contr_id
                                                    AND mc.mbr_contr_id = cp.mbr_contr_id
                                                   -- AND
                                                    AND gc.club_group_code = x.club_group_code);
                                COMMIT;
                                
                      
                                
                                --26432 + insert into s_remark comments
                                 INSERT INTO S_REMARK (rem_id,
                                                      remtype_id,
                                                      remarea_id,
                                                      lead_id,
                                                      mbr_contr_id,
                                                      personnel_id,
                                                      date_time_created,
                                                      rem_desc)
                                              VALUES (pnRemarkID,
                                                      1,
                                                      1,
                                                      x.lead_id,
                                                      x.parent_mbr_contr_id,
                                                      vPersonnelID,
                                                      SYSDATE,
                                                      'MF Surepay auto-debit:'||x.payment_amt||', '||x.club_group_code);
                                                      
                            EXCEPTION WHEN OTHERS THEN
                                vComment     := 'ATLAS Check Settle Table Error: '||SQLERRM||' '||vComment;
                                vMessage     := 'ATLAS Check Settle Table Error: '||SQLERRM||' '||vMessage ;
                                vReturnValue := 'ATLAS CheckSettle Error';
                            END;

[Updated on: Wed, 18 December 2013 10:31]

Report message to a moderator

Re: insert into [message #603708 is a reply to message #603706] Wed, 18 December 2013 10:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
atleast they told me i shouldnt


Thanks for us, elders, this guarantees we'll have work until we'll retire.

Re: insert into [message #603709 is a reply to message #603706] Wed, 18 December 2013 10:40 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
what problem are you trying to solve?
How will you, I, or anyone recognize any future post as being correct solution?

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: insert into [message #603710 is a reply to message #603709] Wed, 18 December 2013 10:47 Go to previous messageGo to next message
nataliafoster26
Messages: 64
Registered: October 2013
Member
i was just making sure if i add another insert into table
it will work or not
Re: insert into [message #603713 is a reply to message #603710] Wed, 18 December 2013 10:55 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
there's no limit to the number of dml statements you can put into a block of code you know.
Re: insert into [message #603714 is a reply to message #603710] Wed, 18 December 2013 11:28 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
nataliafoster26 wrote on Wed, 18 December 2013 08:47
i was just making sure if i add another insert into table
it will work or not


unwilling or incapable to run simple test yourself to observe the results?
Previous Topic: update sql script
Next Topic: how to allow a user to view roles on a DB
Goto Forum:
  


Current Time: Fri Apr 26 23:31:10 CDT 2024