insert into [message #603605] |
Tue, 17 December 2013 19:26 |
|
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 |
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 #603706 is a reply to message #603617] |
Wed, 18 December 2013 10:30 |
|
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 #603714 is a reply to message #603710] |
Wed, 18 December 2013 11:28 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
nataliafoster26 wrote on Wed, 18 December 2013 08:47i 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?
|
|
|