Description

CURRENT or STACKED
Specifies which diagnostics area to access.
CURRENT
Specifies to access the first diagnostics area. It corresponds to the previous SQL statement that was executed and that was not a GET DIAGNOSTICS statement. This is the default.
STACKED
Specifies to access the second diagnostics area. The second diagnostics area is only available within a handler. It corresponds to the previous SQL statement that was executed before the handler was entered and that was not a GET DIAGNOSTICS statement. If the GET DIAGNOSTICS statement is the first statement within a handler, then the first diagnostics area and the second diagnostics area contain the same diagnostics information.
statement-information
Returns information about the last SQL statement executed.
variable-1
Identifies a variable declared in the program in accordance with the rules for declaring variables. The data type of the variable must be compatible with the data type as specified in Table 58 for the specified condition information item. The variable is assigned the value of the specified statement information item. If the value is truncated when assigning it to the variable, a warning (SQLSTATE 01004) is returned and the GET_DIAGNOSTICS_DIAGNOSTICS item of the diagnostics area is updated with the details of this condition.

If a specified diagnostic item does not contain diagnostic information, then the variable is set to a default value based on its data type:

  • 0 for an exact numeric diagnostic item,
  • an empty string for a VARCHAR diagnostic item,
  • and blanks for a CHAR diagnostic item.
condition-information
Returns information about the condition or conditions that occurred when the last SQL statement was executed.
CONDITION variable-2 or integer
Identifies the diagnostic for which information is requested. Each diagnostic that occurs while executing an SQL statement is assigned an integer. The value 1 indicates the first diagnostic, 2 indicates the second diagnostic and so on. If the value is 1, then the diagnostic information retrieved corresponds to the condition indicated by the SQLSTATE value actually returned by the execution of the previous SQL statement (other than a GET DIAGNOSTICS statement). The variable specified must be declared in the program in accordance with the rules for declaring numeric variables. The value specified must not be less than one or greater than the number of available diagnostics.
variable-3
Identifies a variable declared in the program in accordance with the rules for declaring variables. The data type of the variable must be compatible with the data type as specified in Table 58 for the specified condition information item. The variable is assigned the value of the specified statement information item. If the value is truncated when assigning it to the variable, an error is returned and the GET_DIAGNOSTICS_DIAGNOSTICS item of the diagnostics area is updated with the details of this condition.

If a specified diagnostic item does not contain diagnostic information , then the variable is set to a default value based on its data type:

  • 0 for an exact numeric diagnostic item,
  • an empty string for a VARCHAR diagnostic item,
  • and blanks for a CHAR diagnostic item.
combined-information
Returns multiple information items combined into one string.
variable-4
Identifies a variable declared in the program in accordance with the rules for declaring variables. The data type of the variable must be VARCHAR. If the length of variable-4 is not sufficient to hold the full returned diagnostic string, the string is truncated, an error is returned and the GET_DIAGNOSTICS_DIAGNOSTICS item of the diagnostics area is updated with the details of this condition.
ALL
Indicates that all diagnostic items that are set for the last SQL statement executed should be combined into one string. The format of the string is a semicolon separated list of all of the available diagnostic information in the form:
item-name=character-form-of-the-item-value;
The character form of a positive numeric value will not contain a leading plus sign (+) unless the item is RETURNED_SQLCODE. In this case, a leading plus sign (+) is added. For example:
 NUMBER=1;RETURNED_SQLSTATE=02000;DB2_RETURNED_SQLCODE=+100;
Only items that contain diagnostic information are included in the string.
STATEMENT
Indicates that all statement-information-item diagnostic items that contain diagnostic information for the last SQL statement executed should be combined into one string. The format is the same as described above for ALL.
CONDITION
Indicates that condition-information-item diagnostic items that contain diagnostic information for the last SQL statement executed should be combined into one string. If variable-5 or integer is specified, then the format is the same as described above for the ALL option. If variable-5 or integer is not specified, then the format includes a condition number entry at the beginning of the information for that condition in the form:
CONDITION_NUMBER=X;item-name=character-form-of-the-item-value;
where X is the number of the condition. For example:
CONDITION_NUMBER=1;RETURNED_SQLSTATE=02000;RETURNED_SQLCODE=+100;
CONDITION_NUMBER=2;RETURNED_SQLSTATE=01004;
CONNECTION
Indicates that connection-information-item diagnostic items that contain diagnostic information for the last SQL statement executed should be combined into one string. If variable-5 or integer is specified, then the format is the same as described above for ALL. If variable-5 or integer is not specified, then the format includes a connection number entry at the beginning of the information for that condition in the form:
DB2_CONNECTION_NUMBER=X;item-name=character-form-of-the-item-value;
where X is the number of the condition. For example:
DB2_CONNECTION_NUMBER=1;CONNECTION_NAME=SVL1;DB2_PRODUCT_ID=DSN07010;
variable-5 or integer
Identifies the diagnostic for which ALL CONDITION or ALL CONNECTION information is requested. The variable specified must be declared in the program in accordance with the rules for declaring numeric variables. The value specified must not be less than one or greater than the number of available diagnostics.

statement-information-item

COMMAND_FUNCTION
Returns the name of the previous SQL statement. For information on the statement string values, see Table 59.
COMMAND_FUNCTION_CODE
Returns an integer that identifies the previous SQL statement. For information on the statement code values, see Table 59.
DB2_DIAGNOSTIC_CONVERSION_ERROR
Returns the value 1 if there was a conversion error when converting a character data value for one of the GET DIAGNOSTICS statement values. Otherwise, the value zero is returned.
DB2_GET_DIAGNOSTICS_DIAGNOSTICS
After a GET DIAGNOSTICS statement, if any errors or warnings occurred during the execution of the GET DIAGNOSTICS statement, DB2_GET_DIAGNOSTICS_DIAGNOSTICS returns textual information about these errors or warnings. The format of the information is similar to what would be returned by a GET DIAGNOSTICS :hv = ALL statement.

If a request was made for an information item that the server does not understand, for example, if the server was at a lower DRDA(R) level than the requesting client, DB2_GET_DIAGNOSTICS_DIAGNOSTICS returns the text 'Item not supported:' followed by a comma separated list of item names that were requested but that the server does not support.

DB2_LAST_ROW
For a multiple-row-fetch statement, a value of +100 may be returned if the set of rows that have been fetched contains the last row currently in the table for cursors that are fetching forward, or contains the first row currently in the table for cursors that are fetching backward. For cursors that are not sensitive to updates, there would be no need to do a subsequent FETCH since the result would be an end of data indication (SQLSTATE 02000). For cursors that are sensitive to updates, a subsequent FETCH may return more data if a row had been inserted before the FETCH was executed. Otherwise, the value zero is returned.

If the number of rows returned is equal to the number of rows requested, then an end of data warning may not occur and DB2_LAST_ROW may not contain +100.

DB2_NUMBER_CONNECTIONS
Returns the number of connections that were made in order to get to the server that fulfilled the request from the client. Each such connection may generate a connection information item area which would be available for the single condition.
DB2_NUMBER_PARAMETER_MARKERS
For a PREPARE statement, returns the number of parameter markers in the prepared statement. Otherwise, the value zero is returned.
DB2_NUMBER_RESULT_SETS
For a CALL statement, returns the actual number of result sets returned by the procedure. Otherwise, the value zero is returned.
DB2_NUMBER_ROWS
If the previous SQL statement was an OPEN or a FETCH which caused the size of the result table to be known, returns the number of rows in the result table. For SENSITIVE cursors, this value can be thought of as an approximation since rows inserted and deleted will affect the next retrieval of this value. If the previous statement was a PREPARE statement, returns the estimated number of rows in the result table for the prepared statement. Otherwise, the value zero is returned.
DB2_NUMBER_SUCCESSFUL_SUBSTMTS
For embedded compound SQL statements, returns a count of the number of successful sub-statements. Otherwise, the value zero is returned.
DB2_RELATIVE_COST_ESTIMATE
For a PREPARE statement, returns a relative cost estimate of the resources required for every execution. It does not reflect an estimate of the time required. When preparing a dynamically defined statement, this value can be used as an indicator of the relative cost of the prepared statement. The value varies depending on changes to statistics and can vary between releases of the product. It is an estimated cost for the access plan chosen by the optimizer. The value zero is returned if the statement is not a PREPARE statement.
DB2_RETURN_STATUS
Identifies the status value returned from the previous SQL CALL statement. If the previous statement is not a CALL statement, the value returned has no meaning and is unpredictable. For more information, see RETURN statement. Otherwise, the value zero is returned.
DB2_ROW_COUNT_SECONDARY
Identifies the number of rows associated with secondary actions from the previous SQL statement that was executed. If the previous SQL statement is a DELETE, the value is the total number of rows affected by referential constraints, including cascaded actions and the processing of triggered SQL statements from activated triggers. If the previous SQL statement is an INSERT or an UPDATE, the value is the total number of rows affected as the result of the processing of triggered SQL statements from activated triggers. Otherwise, the value zero is returned.

If the SQL statement is run using isolation level No Commit, this value may be zero.

DB2_ROW_LENGTH
For a FETCH statement, returns the length of the row retrieved. Otherwise, the value zero is returned.
DB2_SQL_ATTR_CONCURRENCY
For an OPEN statement, indicates the concurrency control option of read-only, locking, optimistic using timestamps, or optimistic using values. Otherwise, a blank is returned.
DB2_SQL_ATTR_CURSOR_CAPABILITY
For an OPEN statement, indicates the capability of the cursor, whether a cursor is read-only, deletable, or updatable. Otherwise, a blank is returned.
DB2_SQL_ATTR_CURSOR_HOLD
For an OPEN statement, indicates whether a cursor can be held open across multiple units of work or not. Otherwise, a blank is returned.
DB2_SQL_ATTR_CURSOR_ROWSET
For an OPEN statement, whether a cursor can be accessed using rowset positioning or not. Otherwise, a blank is returned.
DB2_SQL_ATTR_CURSOR_SCROLLABLE
For an OPEN statement, indicates whether a cursor can be scrolled forward and backward or not. Otherwise, a blank is returned.
DB2_SQL_ATTR_CURSOR_SENSITIVITY
For an OPEN statement, indicates whether a cursor does or does not show updates to cursor rows made by other connections. Otherwise, a blank is returned.
DB2_SQL_ATTR_CURSOR_TYPE
For an OPEN statement, indicates whether a cursor type is dynamic, forward-only, or static. Otherwise, a blank is returned.
DYNAMIC_FUNCTION
Returns a character string that identifies the type of the SQL-statement being prepared or executed dynamically. For information on the statement string values, see Table 59.
DYNAMIC_FUNCTION_CODE
Returns a number that identifies the type of the SQL-statement being prepared or executed dynamically. For information on the statement code values, see Table 59.
MORE
Indicates whether more errors were raised than could be handled.
NUMBER
Returns the number of errors and warnings detected by the execution of the previous SQL statement, other than a GET DIAGNOSTICS statement, that have been stored in the diagnostics area. If the previous SQL statement returned success (SQLSTATE 00000), or no previous SQL statement has been executed, the number returned is one. The GET DIAGNOSTICS statement itself may return information via the SQLSTATE parameter, but does not modify the previous contents of the diagnostics area, except for the DB2_GET_DIAGNOSTICS_DIAGNOSTICS item.
ROW_COUNT
Identifies the number of rows associated with the previous SQL statement that was executed. If the previous SQL statement is a DELETE, INSERT, REFRESH, or UPDATE statement, ROW_COUNT identifies the number of rows deleted, inserted, or updated by that statement, excluding rows affected by either triggers or referential integrity constraints. If the previous statement is a PREPARE statement, ROW_COUNT identifies the estimated number of result rows in the prepared statement. If the previous SQL statement is a multiple-row-fetch, ROW_COUNT identifies the number of rows fetched. Otherwise, the value zero is returned.
TRANSACTION_ACTIVE
Returns the value 1 if an SQL transaction is currently active, and 0 if an SQL transaction is not currently active.
TRANSACTIONS_COMMITTED
If the previous statement was a CALL, returns the number of transactions that were committed during the execution of the SQL or external procedure. Otherwise, the value zero is returned.
TRANSACTIONS_ROLLED_BACK
If the previous statement was a CALL, returns the number of transactions that were rolled back during the execution of the SQL or external procedure. Otherwise, the value zero is returned.

connection-information-item

CONNECTION_NAME
If the previous SQL statement is a CONNECT, DISCONNECT, or SET CONNECTION, returns the name of the server specified in the previous statement. Otherwise, the name of the current connection.
DB2_AUTHENTICATION_TYPE
Indicates the authentication type, whether server or client. Otherwise, a blank is returned.
DB2_AUTHORIZATION_ID
Returns the authorization id used by connected server. Because of userid translation and authorization exits, the local userid may not be the authid used by the server.
DB2_CONNECTION_METHOD
For a CONNECT or SET CONNECTION statement, returns the connection method.
DB2_CONNECTION_NUMBER
Returns the number of the connections.
DB2_CONNECTION_STATE
Indicates the connection state, whether connected or not. Otherwise, the value zero is returned.
DB2_CONNECTION_STATUS
Indicates whether commitable update can be performed or not. Otherwise, the value zero is returned.
DB2_CONNECTION_TYPE
Indicated the connection type (either local, remote, or to a driver program) and whether the conversation is protected or not. Otherwise, the value zero is returned.
DB2_DYN_QUERY_MGMT
Returns a value of 1 if DYN_QUERY_MGMT database configuration parameter is enabled. Otherwise, the value zero is returned.
DB2_ENCRYPTION_TYPE
Returns the level of encryption. Otherwise, a blank is returned.
DB2_PRODUCT_ID
Returns a product signature. If the application server is an IBM(R) relational database product, the form is pppvvrrm, where: For example, if the application server is Version 7 of DB2 UDB for z/OS, the value would be 'DSN07010'. Otherwise, the empty string is returned.
DB2_SERVER_CLASS_NAME
Returns the server class name. For example, DB2 for z/OS, DB2 for AIX(R), DB2 for Windows(R), and DB2 for iSeries.
DB2_SERVER_NAME
For a CONNECT or SET CONNECTION statement, returns the relational database name. Otherwise, the empty string is returned.

condition-information-item

CATALOG_NAME
If the returned SQLSTATE is: and the constraint that caused the error is a referential, check, or unique constraint, the server name of the table that owns the constraint is returned.

If the returned SQLSTATE is class 42 (Syntax Error or Access Rule Violation), the server name of the table that caused the error is returned.

If the returned SQLSTATE is class 44 (WITH CHECK OPTION Violation), the server name of the view that caused the error is returned. Otherwise, the empty string is returned.

CLASS_ORIGIN
Returns 'ISO 9075' for those SQLSTATEs whose class is defined by ISO 9075. Returns 'ISO/IEC 13249' for those SQLSTATEs whose class is defined by SQL/MM. Returns 'DB2 UDB SQL' for those SQLSTATEs whose class is defined by IBM DB2 Universal Database(TM) SQL. Returns the value set by user written code if available. Otherwise, the empty string is returned.
COLUMN_NAME
If the returned SQLSTATE is class 42 (Syntax Error or Access Rule Violation) and the error was caused by an inaccessible column, the name of the column that caused the error is returned. Otherwise, the empty string is returned.
CONDITION_IDENTIFIER
If the value of the RETURNED_SQLSTATE corresponds to an unhandled user-defined exception (SQLSTATE 45000), then the condition name of the user-defined exception is returned.
CONDITION_NUMBER
Returns the number of the conditions.
CONSTRAINT_CATALOG
If the returned SQLSTATE is: the name of the server that contains the table that contains the constraint that caused the error is returned. Otherwise, the empty string is returned.
CONSTRAINT_NAME
If the returned SQLSTATE is: the name of the constraint that caused the error is returned. Otherwise, the empty string is returned.
CONSTRAINT_SCHEMA
If the returned SQLSTATE is: the name of the schema of the constraint that caused the error is returned. Otherwise, the empty string is returned.
CURSOR_NAME
If the returned SQLSTATE is class 24 (Invalid Cursor State), the name of the cursor is returned. Otherwise, the empty string is returned.
DB2_ERROR_CODE1
Returns an internal error code. Otherwise, the value zero is returned.
DB2_ERROR_CODE2
Returns an internal error code. Otherwise, the value zero is returned.
DB2_ERROR_CODE3
Returns an internal error code. Otherwise, the value zero is returned.
DB2_ERROR_CODE4
Returns an internal error code. Otherwise, the value zero is returned.
DB2_INTERNAL_ERROR_POINTER
For some errors, this will be a negative value that is an internal error pointer. Otherwise, the value zero is returned.
DB2_LINE_NUMBER
For a CREATE PROCEDURE for an SQL function, SQL procedure, or SQL trigger where an error is encountered parsing the SQL procedure body, returns the line number where the error possibly occurred. Otherwise, the value zero is returned.
DB2_MESSAGE_ID
Returns the message ID corresponding to the MESSAGE_TEXT.
DB2_MESSAGE_ID1
Returns the underlying i5/OS CPF escape message that originally caused this error. Otherwise, the empty string is returned.
DB2_MESSAGE_ID2
Returns the underlying i5/OS CPD diagnostic message that originally caused this error. Otherwise, the empty string is returned.
DB2_MESSAGE_KEY
For a CALL statement, returns the i5/OS message key of the error that caused the procedure to fail. For a trigger error in a DELETE, INSERT, or UPDATE statement, returns the message key of the error that was signaled from the trigger program. The i5/OS QMHRCVPM API can be used to return the message description and message data for the message key. Otherwise, the value zero is returned.
DB2_MODULE_DETECTING_ERROR
Returns an identifier indicating which module detected the error. For a SIGNAL statement issued from a routine, the value 'ROUTINE' is returned. For other SIGNAL statements, the value 'PROGRAM' is returned.
DB2_NUMBER_FAILING_STATEMENTS
For a NOT ATOMIC embedded compound SQL statement, returns the number of statements that failed. Otherwise, the value zero is returned.
DB2_OFFSET
For a CREATE PROCEDURE for an SQL procedure where an error is encountered parsing the SQL procedure body, returns the offset into the line number where the error possibly occurred, if available. For an EXECUTE IMMEDIATE or a PREPARE statement where an error is encountered parsing the source statement, returns the offset into the source statement where the error possibly occurred. Otherwise, the value zero is returned.
DB2_ORDINAL_TOKEN_n
Returns the nth token. n must be a value from 1 to 100. For example, DB2_ORDINAL_TOKEN_1 would return the value of the first token, DB2_ORDINAL_TOKEN_2 the second token. A numeric value for a token is converted to character before being returned. If there is no value for the token, the empty string is returned.
DB2_PARTITION_NUMBER
For a partitioned database, returns the partition number of the database partition that encountered the error or warning. If no errors or warnings were encountered, returns the partition number of the current node. Otherwise, the value zero is returned.
DB2_REASON_CODE
Returns the reason code for errors that have a reason code token in the message text. Otherwise, the value zero is returned.
DB2_RETURNED_SQLCODE
Returns the SQLCODE for the specified diagnostic.
DB2_ROW_NUMBER
If the previous SQL statement is a multiple row insert or a multiple row fetch, returns the number of the row where the condition was encountered, when such a value is available and applicable. Otherwise, the value zero is returned.
DB2_SQLERRD_SET
Returns Y to indicate that the DB2_SQLERRD1 through DB2_SQLERRD6 items may be set. Otherwise, a blank is returned.
DB2_SQLERRD1
Returns the value of SQLERRD(1) from the SQLCA returned by the server.
DB2_SQLERRD2
Returns the value of SQLERRD(2) from the SQLCA returned by the server.
DB2_SQLERRD3
Returns the value of SQLERRD(3) from the SQLCA returned by the server.
DB2_SQLERRD4
Returns the value of SQLERRD(4) from the SQLCA returned by the server.
DB2_SQLERRD5
Returns the value of SQLERRD(5) from the SQLCA returned by the server.
DB2_SQLERRD6
Returns the value of SQLERRD(6) from the SQLCA returned by the server.
DB2_TOKEN_COUNT
Returns the number of tokens available for the specified diagnostic.
DB2_TOKEN_STRING
Returns a X'FF' delimited string of the tokens for the specified diagnostic.
MESSAGE_LENGTH
Identifies the length (in characters) of the message text of the error, warning, or successful completion returned from the previous SQL statement that was executed.
MESSAGE_OCTET_LENGTH
Identifies the length (in bytes) of the message text of the error, warning, or successful completion returned from the previous SQL statement that was executed.
MESSAGE_TEXT
Identifies the message text of the error, warning, or successful completion returned from the previous SQL statement that was executed.
PARAMETER_MODE
If the returned SQLSTATE is: and the condition is related to the ith parameter of the routine, the parameter mode of the ith parameter is returned. Otherwise, the empty string is returned.
PARAMETER_NAME
If the returned SQLSTATE is: the condition is related to the ith parameter of the routine, and a parameter name was specified for the parameter when the routine was created, the parameter name of the ith parameter is returned. Otherwise, the empty string is returned.
PARAMETER_ORDINAL_POSITION
If the returned SQLSTATE is: and the condition is related to the ith parameter of the routine, the value of i is returned. Otherwise, the empty string is returned.
RETURNED_SQLSTATE
Returns the SQLSTATE for the specified diagnostic.
ROUTINE_CATALOG
If the returned SQLSTATE is: and the condition is related to the ith parameter of the routine, or if the returned SQLSTATE is: and the condition was raised as the result of an assignment to an SQL parameter during an routine invocation, the server name of the routine is returned. Otherwise, the empty string is returned.
ROUTINE_NAME
If the returned SQLSTATE is: and the condition is related to the ith parameter of the routine, or if the returned SQLSTATE is: and the condition was raised as the result of an assignment to an SQL parameter during an routine invocation, the name of the routine is returned. Otherwise, the empty string is returned.
ROUTINE_SCHEMA
If the returned SQLSTATE is: and the condition is related to the ith parameter of the routine, or if the returned SQLSTATE is: and the condition was raised as the result of an assignment to an SQL parameter during an routine invocation, the schema name of the routine is returned. Otherwise, the empty string is returned.
SCHEMA_NAME
If the returned SQLSTATE is: and the constraint that caused the error is a referential, check, or unique constraint, the schema name of the table that owns the constraint is returned.

If the returned SQLSTATE is class 42 (Syntax Error or Access Rule Violation), the schema name of the table that caused the error is returned.

If the returned SQLSTATE is class 44 (WITH CHECK OPTION Violation), the schema name of the view that caused the error is returned. Otherwise, the empty string is returned.

SERVER_NAME
If the previous SQL statement is a CONNECT, DISCONNECT, or SET CONNECTION, the name of the server specified in the previous statement is returned. Otherwise, the name of the server where the statement executed is returned.
SPECIFIC_NAME
If the returned SQLSTATE is: and the condition is related to the ith parameter of the routine, or if the returned SQLSTATE is: and the condition was raised as the result of an assignment to an SQL parameter during an routine invocation, the specific name of the procedure or function is returned. Otherwise, the empty string is returned.
SUBCLASS_ORIGIN
Returns 'ISO 9075' for those SQLSTATEs whose subclass is defined by ISO 9075. Returns 'ISO/IEC 9579' for those SQLSTATEs whose subclass is defined by RDA. Returns 'ISO/IEC 13249-1', 'ISO/IEC 13249-2', 'ISO/IEC 13249-3', 'ISO/IEC 13249-4', or 'ISO/IEC 13249-5' for those SQLSTATEs whose subclass is defined SQL/MM. Returns 'DB2 UDB SQL' for those SQLSTATEs whose subclass is defined by IBM DB2 Universal Database SQL. Returns the value set by user written code if available. Otherwise, the empty string is returned.
TABLE_NAME
If the returned SQLSTATE is: and the constraint that caused the error is a referential, check, or unique constraint, the table name that owns the constraint is returned.

If the returned SQLSTATE is class 42 (Syntax Error or Access Rule Violation), the table name that caused the error is returned.

If the returned SQLSTATE is class 44 (WITH CHECK OPTION Violation), the table name that caused the error is returned. Otherwise, the empty string is returned.

TRIGGER_CATALOG
If the returned SQLSTATE is: the name of the trigger is returned. Otherwise, the empty string is returned.
TRIGGER_NAME
If the returned SQLSTATE is: the name of the trigger is returned. Otherwise, the empty string is returned.
TRIGGER_SCHEMA
If the returned SQLSTATE is: the schema name of the trigger is returned. Otherwise, the empty string is returned.