Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you interpret Oracle SQLCA Error

Posted on 2008-10-22
4
Medium Priority
?
783 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 74

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 48

Accepted Solution

by:
schwertner earned 2000 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 48

Expert Comment

by:schwertner
ID: 22794190
Thank you so much!
Good luck!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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 how to recover a database from a user managed backup
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

877 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