Solved

How do you interpret Oracle SQLCA Error

Posted on 2008-10-22
4
757 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PL/SQL Two PAYER_IDs with PAYER_TYPES these two types 4 35
Oracle TEXT search question 9 48
VB.Net - Oracle BulkCopy from CSV Date Format 7 45
help on oracle query 5 31
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to recover a database from a user managed backup

911 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

21 Experts available now in Live!

Get 1:1 Help Now