Solved

SQLCODE outside exception block

Posted on 2014-01-15
6
494 Views
Last Modified: 2014-01-19
Somebody asked me a question if  I can use SQLCODE and SQLERRM outside exception block, I am not sure. Please suggest !!!!
0
Comment
Question by:d27m11y
6 Comments
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 166 total points
Comment Utility
I'll defer to the docs:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/sqlcode_function.htm#LNPLS01349

Pay attention to:  In an exception handler
SQLCODE Function

In an exception handler, the SQLCODE function returns the numeric code of the exception being handled. (Outside an exception handler, SQLCODE returns 0.)

To add to the docs:  I've never seen it used outside of an exception handler.

Can I ask what the person that asked was thinking where it might be useful besides during an exception?
0
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 167 total points
Comment Utility
You can use but they will not print anything...

try this :

begin
dbms_output.put_line('checking...');
dbms_output.put_line('sqlcode:' || sqlcode);
dbms_output.put_line('sql errm:' || sqlerrm);
end;
/

output is :

checking...
sqlcode:0
sql errm:ORA-0000: normal, successful completion
0
 

Author Comment

by:d27m11y
Comment Utility
Well, this was an interview question and I answered NO and I was not given any scenario..
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 28

Expert Comment

by:Naveen Kumar
Comment Utility
yep. that is just to test how good one is in understand what can be done and what cannot be done etc with the techinical stuff :)

Thanks,
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
Looks like you 'can' but the answer is 'it doesn't do anything'.

Unless, the interviewers know something we don't.  Which is always possible!

Leave this open for a while to see if anyone else knows of a way.
0
 
LVL 34

Accepted Solution

by:
johnsone earned 167 total points
Comment Utility
Think about it for a minute.  SQLCODE returns the error code from the previous statement.  If the previous statement had an error in it, then you would jump to an exception handler and never make it to the SQLCODE call.

Take for example this pseudo code:

begin
  insert into tab values (1, 37);
  if SQLCODE < 0 then
       dbms_output.put_line('In if statement');
  end if;
exception
   when dup_val_on_index then
       dbms_output.put_line('In error handler');
end;

Open in new window


Now, if that insert statement failed because you were violating a primary key, which message would get printed?

There may be a few cases of warnings (not errors) where processing would continue and not drop into an exception handler.  I cannot think of any, but that would be the only case where SQLCODE would contain a value other than 0 outside of an exception handler.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now