Solved

How do you interpret Oracle SQLCA Error

Posted on 2008-10-22
4
759 Views
Last Modified: 2013-12-18
Using Pro *C/C++ in unix environment.  How do you display and print and interpret this structure?
0
Comment
Question by:sdruss
  • 2
4 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 22783047
It's defined in

 $ORACLE_HOME/precomp/public/sqlca.h

I've copied the structure itself from the file here.

You can display and print it's fields like you would any other struct.

What do you want to "interpret" about it?

struct   sqlca
         {
         /* ub1 */ char    sqlcaid[8];
         /* b4  */ int     sqlabc;
         /* b4  */ int     sqlcode;
         struct
           {
           /* ub2 */ unsigned short sqlerrml;
           /* ub1 */ char           sqlerrmc[70];
           } sqlerrm;
         /* ub1 */ char    sqlerrp[8];
         /* b4  */ int     sqlerrd[6];
         /* ub1 */ char    sqlwarn[8];
         /* ub1 */ char    sqlext[8];
         };

Open in new window

0
 
LVL 47

Accepted Solution

by:
schwertner earned 500 total points
ID: 22786324
It is explained here:
http://www.cs.ubc.ca/~ramesh/cpsc304/tutorial/EmbeddedSQL/embeddedSQL2.html

If you started doing some programming already, then you might have encountered some seemingly unexplainable problems, as all programmers experience every now and then.  For example, you might have tried to insert a tuple into a relation which violated an integrity constraint. When conditions such as these arise, Oracle returns an error code which specifically indicates the cause of the problem. This error code is returned in a structure:  the  SQLCA  (SQL Communications Area), in your program.  Instead of/in addition to using the SQLCA structure, Oracle also allows you to declare status variables:  SQLSTATE and SQLCODE that you can check after each SQL statement (SQLSTATE is preferred over SQLCODE).  This tutorial will cover only the SQLCA structure.
Besides error codes, the SQLCA structure also contains warning messages and various other administrative variables which can come in fairly handy when debugging your program. The structure definition of SQLCA is:

struct sqlca
{
  char sqlcaid[8];
  long sqlabc;
  long sqlcode;
  struct
    {
      unsigned short sqlerrml;
      char           sqlerrmc[70];
    } sqlerrm;
  char sqlerrp[8];
  long sqlerrd[6];
  char sqlwarn[8];
  char sqlext[8];
};
The values of the structure are updated by Oracle after every SQL statement. The variable which we will find most useful in the SQLCA structure is sqlca.sqlcode (not the same as the SQLCODE status variable), which holds function return status information. After a function call, if sqlca.sqlcode is:
 
0, this implies a successful operation
 
negative, an ORACLE ERROR was encountered.  Such errors are usually fatal, so the current transaction should be rolled back.  An example of an error is an update or insert statement that attempted to insert a duplicate key.  This returns an error code of -1.
 
positive, execution was successful and a status code is returned, but an exception was detected.  See below for an example of such a situation.
 
100 or 1403 (this depends on the precompiler's settings), all rows have been fetched or no rows were returned.

Another useful variable is sqlca.sqlerrm.sqlerrmc, which is a 70 character string holding Oracle error messages.

To use the SQLCA structure, we need to include the following line near the beginning of any program which uses the structure:
 

EXEC SQL INCLUDE sqlca;

..........................................
0
 
LVL 1

Author Comment

by:sdruss
ID: 22790457
Implemented.  Worked well.
0
 
LVL 47

Expert Comment

by:schwertner
ID: 22794190
Thank you so much!
Good luck!
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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.

813 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

12 Experts available now in Live!

Get 1:1 Help Now