Home » SQL & PL/SQL » SQL & PL/SQL » insert
insert [message #39161] Sat, 22 June 2002 09:30 Go to next message
rao
Messages: 25
Registered: July 1999
Junior Member
how to check whether insert is successful

ex:
insert into t1(a1, a2, a3) values (1, 2, 3)
can i use
if(sql%notfound) then ///sql%notfound is this right
raise insertfailed;
end if;

appreciate any help
Re: insert [message #39163 is a reply to message #39161] Sat, 22 June 2002 13:52 Go to previous messageGo to next message
Amit Chauhan
Messages: 74
Registered: July 1999
Member
Hi,
Any failure in insert will raise an error. It wont make sense to use SQL% for that. Use something like this :
begin
  begin
    insert into t1(a1, a2, a3) values (1, 2, 3);
  exception
    when others then
      dbms_output.put_line ('An error occured in inserting ' || substr (sqlerrm, 1, 200));
  end;
 -- ....do something else
end;


Hope that helps.

Amit
Re: insert [message #39169 is a reply to message #39161] Sat, 22 June 2002 23:13 Go to previous message
Amit Chauhan
Messages: 74
Registered: July 1999
Member
Hi,
I think, if you insert statement is failing, then the exception is been raised from that statement, so your statement, SQL%NOTFOUND is never executed. So it directly goes to WHEN OTHERS exception block.

Hope that helps
Amit
Previous Topic: Finding the Second largest value from a column
Next Topic: what is the NOLOGGING effect on Table
Goto Forum:
  


Current Time: Fri Apr 26 00:42:24 CDT 2024