GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 144 of 241    Print  
what happens when commit is given in executable section and an error occurs ?please tell me what happens if exception block is committed at the last?

  
Total Answers and Comments: 5 Last Update: February 25, 2008     Asked by: preethi 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: geetha24
 
Whenever the exception is raised ..all the transaction made before will be commited. If the exception is not raised then all the transaction will be rolled back.

Above answer was rated as good by the following members:
kperumal75, manish.baehal
January 21, 2007 23:53:32   #1  
vikrant        

RE: what happens when commit is given in executable se...
all the transactions done by that executable section will be rolled back
 
Is this answer useful? Yes | No
February 07, 2007 08:17:02   #2  
raghav_sy Member Since: January 2007   Contribution: 38    

RE: what happens when commit is given in executable se...
well the answer is what ever done in executable section will be lost. u can see the exapmle:created table d as below:SQL> create table d ( sl number(4) name varchar2(5));now do the following operation:SQL> begin insert into d values ('1223123123' 'geekinterview'); --making insert to fail here commit; exception --catching the exception here when others then commit; end; /PL/SQL procedure successfully completed.now if we use :SQL> select * from d; no rows selectedso even the pl/sql procedure completed successfully no values were saved in d.this is one case where we are giving invalid values for both the fields(in insert stmt.). now see the below procedure:SQL> begin insert into d values ('1223123123' 'RSY'); --first value is incorrect second is correct one commit; exception when others then commit; end; /PL/SQL procedure successfully completed.SQL> select * from d; no rows selectedeven in this case nothinghas been inserted in table d. even though value for name field is a valid data.now there is one possible case:SQL> begin insert into d values ('123' 'RSY'); --both values are correct commit; --commiting first time insert into d values ('1223123123' 'RSY'); --entering values to fail insert commit; exception --handling exception when others then commit; end; /PL/SQL procedure successfully completed.SQL> select * from d; SL NAME--------- ----- 123 RSYso here the first insert has been committed but at the time of second insert the condition fails so second insert is roll backed. but it will not affect data that has been already committed.ok take carecheersRSY
 
Is this answer useful? Yes | No
February 08, 2007 01:06:31   #3  
raghav_sy Member Since: January 2007   Contribution: 38    

RE: what happens when commit is given in executable se...
hi again am posting the same answer i do not know why the answer is not displayed with proper formatting. ok once more i will try:well the answer is what ever done in executable section will be lost. u can see the exapmle:created table d as below:SQL> create table d ( sl number(4) name varchar2(5));now do the following operation:SQL> begin insert into d values ('1223123123' 'geekinterview'); --making insert to fail here commit; exception --catching the exception here when others then commit; end; /PL/SQL procedure successfully completed.now if we use :SQL> select * from d; no rows selectedso even the pl/sql procedure completed successfully no values were saved in d.this is one case where we are giving invalid values for both the fields(in insert stmt.). now see the below procedure:SQL> begin insert into d values ('1223123123' 'RSY'); --first value is incorrect second is correct one commit; exception when others then commit; end; /PL/SQL procedure successfully completed.SQL> select * from d; no rows selectedeven in this case nothinghas been inserted in table d. even though value for name field is a valid data.now there is one possible case:SQL> begin insert into d values ('123' 'RSY'); --both values are correct commit; --commiting first time insert into d values ('1223123123' 'RSY'); --entering values to fail insert commit; exception --handling exception when others then commit; end; /PL/SQL procedure successfully completed.SQL> select * from d; SL NAME --------- ----- 123 RSYso here the first insert has been committed but at the time of second insert the condition fails so second insert is roll backed. but it will not affect data that has been already committed.ok take carecheersRSY
 
Is this answer useful? Yes | No
February 09, 2007 17:15:32   #4  
geetha24 Member Since: March 2006   Contribution: 27    

RE: what happens when commit is given in executable se...
Whenever the exception is raised ..all the transaction made before will be commited. If the exception is not raised then all the transaction will be rolled back.
 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
February 24, 2008 16:52:06   #5  
ae_sathis Member Since: February 2008   Contribution: 1    

RE: what happens when commit is given in executable section and an error occurs ?please tell me what happens if exception block is committed at the last?

SQL> create table d ( sl number(4) name varchar2(5));

now do the following operation:

SQL> begin insert into d values ('1223123123' 'geekinterview');

--making insert to fail here commit; exception


--catching the exception here when others then

commit;

end;

/

PL/SQL procedure successfully completed.

now if we use :

SQL> select * from d;

no rows selected so even the pl/sql procedure completed successfully no values were saved in d.

this is one case where we are giving invalid values for both the fields in insert stmt.).


now see the below procedure:

SQL> begin insert into d values ('1223123123' 'RSY');

--first value is incorrect second is correct one commit;


exception when others then

commit;

end;

/

PL/SQL procedure successfully completed.

SQL> select * from d;

no rows selected even in this case nothing has been inserted in table d.


even though value for name field is a valid data. now there is one possible case:

SQL> begin insert into d values ('123' 'RSY');

--both values are correct commit;


--committing first time insert into d values ('1223123123' 'RSY');

--entering values to fail insert commit; exception

--handling exception when others then commit;

end;

/

PL/SQL procedure successfully completed.

SQL> select * from d;

SL NAME

--------- -----

123 RSY

so here the first insert has been committed but at the time of second insert the condition fails so second insert is roll backed. but it will not affect data that has been already committed.

ok take care

cheers

RSY


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape