Академический Документы
Профессиональный Документы
Культура Документы
Presented by:
Robert Goodman
October 2006
Where Do We Start?
How Do We Debug?
• Available in V8
• Use for Multi Row
Operations
• Use for support long
names
• Use to retrieve additional
information
What Does It Look Like?
EXEC SQL BEGIN DECLARE SECTION;
long row_count, num_condns,
i; long ret_sqlcode, row_num; char ret_sqlstate[6]; ...
EXEC SQL END DECLARE SECTION; ...
• SQLCode • SQLState
– More specific information – Std across whole
– Have associated tokens DB2 family
• Error Code
• Resource Type
– Can point to object
• Resource Name
z/OS
z/OS
Good & Bad SQL Codes
SQLCODE / SQL SELECT DECLARE OPEN FETCH CLOSE INSERT UPDATE DELETE
+000
Normal
N/A
+100
Not Found
N/A
-180 –181
Invalid Date / Time
N/A
-803
Duplicate Key
N/A
-811
Multiple Rows
N/A
-904 N/A
Unavailable Resource
-911 N/A
Rollback Timeout
Checking Leads To
• breaks program logic
• weird program errors
• can extend debugging time
SQL Code Normal
Standard SQL Code
Checking
SELECT
SQL <>0
ERROR
Code
0
Not Found
Fetch Loop
OPEN
CURSOR
SQL <>0
ERROR
Code
0
FETCH
0 SQL <0
ERROR
Code
+100
CLOSE
SQL <>0
ERROR
Code
0
Mismatch
DB2
SQL Error Primary
Code Code Cause Responsibility Problem Resolution Suggestions
-117 N/A The number of SQL coding This error typically happens when the column list
values specified error of an SQL doesn’t match the host variable list. It
does not match can happen when SQL is coded to explicitly or
the number of implicitly select all columns in an SQL vs. an
columns explicit list of host variables. When a column is
implied or added to the table, the explicit list will no longer
specified match the select all list.
SQLState: 42802
Column Mismatch
INSERT INTO
Table_A
TABLE_A
VALUES
(:I-CLIE
#1 I_CLIE
T_CREA
I_ACCN_PATN
,:T_CREA
,:I_ACCN_PATN
)
Alter Table
#2 Add Column
T_MODF
INSERT INTO
TABLE_A Table_A
VALUES I_CLIE
#3
X
T_CREA
(:I-CLIE
I_ACCN_PATN
,:T_CREA T_MODF
,:I_ACCN_PATN
)
DB2 Date, Time &
Timestamp Errors
DB2
SQL Error Primary
Code Code Cause Responsibility Problem Resolution Suggestions
-180 N/A An invalid date, Program Issue In batch programs, it may be helpful to do a
time or DISPLAY of all dates, times and timestamps from
timestamp value the problem SQL to determine the cause of the
was entered into a problem. Make sure that all of these values are
host variable or validated prior to moving them into host variables
SQL parameter. or SQL parameters. Failure to move a valid value
to a newly added date, time or timestamp column
after a program recompile can also cause this error.
-181 N/A The value of a Program Issue This happens when an out of range value is entered
date/time value is into one or more of the components of a date/time
not valid format value. Display the date in the program and
examine the output for the invalid value portion.
Timestamp yyyy-mm-dd-hh-mm-ss-msmsms
yyyy-mm-dd-hh-mm-ss
Date mm/dd/yyyy
yyyy-mm-dd
dd.mm.yyyy
Time hh:mm:ss
hh:mm
hh.mm.ss
hh.mm
hh:mm AM or hh:mm PM
SQL Code: -181 Ranges
Component Valid Range
Year 0001 - 9999
Month 1 – 12
Minute 0 – 59
Second 0 - 59
Microsecond 0 - 9999
Bogus FETCH or CLOSE
DB2
SQL Error Primary
Code Code Cause Responsibility Problem Resolution Suggestions
-501 N/A Attempted a Program logic error Check previous SQL codes for something that
FETCH or may have closed the cursor. If SQL codes are
CLOSE on an not methodically checked, an undetected
unopened cursor rollback will cause a FETCH or CLOSE to
get this return code.
SQLState: 24501
Missing SQL Code Checking
OPEN
CURSOR
SQL <>0
ERROR
Code
0
0 SQL <0
UPDATE Code ERROR
+100
Missing Check
CLOSE
SQL <>0
Code ERROR
0
DB2 Duplicate Key
Errors
DB2
SQL Error Primary
Code Code Cause Responsibility Problem Resolution Suggestions
-803 N/A Attempted to Program Issue A table can have multiple UNIQUE INDEXes.
INSERT or First, it is necessary to determine all of the
UPDATE in UNIQUE INDEXes on a table. A query of
violation of a SYSIBM.SYSINDEXES Next, review the
UNIQUE INDEX program logic to make that it addresses all of the
constraint. UNIQUE constraints. It may be necessary to
handle this (-803) SQLCODE on an INSERT or
UPDATE and automatically increment a sequence
number or timestamp milliseconds if the
application dictates.
SQLState: 23505
Unique Index Elements
PERFORM UT97894P-CHECK-SQLCODE
THRU UT97894P-CHECK-SQLCODE-EXIT
…
DB2 Precompiler
Timestamp Errors
DB2
SQL Error Primary
Code Code Cause Responsibility Problem Resolution Suggestions
-805 N/A The DBRM or Compile Issue or This can occur when a compile is partially
Package in not JCL Issue successful or there is attempt to bind a package
found in the Plan that is not in the plan. Determine the correct
bind parameters and try again.
-818 N/A The DBRM Compile Issue of This can occur when a compile is partially
consistency token JCL Issue successful and the load module consistency
does not match the token doesn’t match the current DBRM. If a
load module recompile doesn’t resolve the problem, it may
be necessary to STEPLIB over to the proper
load libraries. In the production environment,
this is usually caused by a failed production
move. It may be necessary to recompile the
program and move it back into production
recompile can also cause this error.
DBRMlib Loadlib
DB2 Multiple Rows
Errors
DB2
SQL Error Primary
Code Code Cause Responsibility Problem Resolution Suggestions
-811 n/a More than one Program or Data This usually occurs when new data is added so that
value was Issue an embedded SELECT retrieves more than a single
returned on an row result set. A comprehensive treatment of this
embedded issue is detailed in the DB2 Tips and Techniques
SELECT. #8 Existence Checking With a SELECT SQL
Statement. If you need to get the first row of a set
based in a specific order, then the SELECT logic
should be converted to a CURSOR with an
ORDER BY clause followed by a FETCH.
SQLState: 21000
#1 Singleton SELECT
(SELECTS 1 Row & Columns)
EXEC SQL
SELECT
– If SQLCODE is OK (=0);
1 • 1) existence of 1 or more
INTO
:WS400-NUMBER rows
FROM VRI97000 – SQLCODE = 0
WHERE
I_CLIE = :RI000-I-CLIE AND – If SQLCODE fails (<>0);
I_MRI_PATN = :RI000-I-MRI-PATN
FETCH FIRST ROW ONLY • 1) existence of no rows
END-EXEC
– SQLCODE = +100
PERFORM UT97894P-CHECK-SQLCODE • 2) other failure
THRU UT97894P-CHECK-SQLCODE-EXIT
– SQLCODE <0
IF WS960-R-NOTFND
THEN ….
END-IF
#3 Counting Rows
SET WS960-HANDLE-NOTFND TO TRUE
– If SQLCODE is OK (=0); EXEC SQL
• 1) existence of >0 rows SELECT
COUNT(*)
– SQLCODE = 0 INTO
:WS400-NUMB
– INDICATOR-VAR >= 0 :WS400-INDICATOR-VARIABLE
FROM VCP97160
– If SQLCODE fails (<>0); WHERE
I_CLIE = :CP160-I-CLIE AND
• 1) existence of no rows I_CODE = :CP160-I-CODE
– SQLCODE = +100 END-EXEC
IF WS960-R-NORMAL
….
END-IF
DB2 Unavailable
Resources
SQL DB2 Error Primary
Code Code Cause Responsibil Problem Resolution Suggestions
ity
-904 C90080 or The database DBA Issue This condition may appear for a few seconds
C90081 or resource is in a during some database modifications and utility
C90097 READ ONLY, functions. DBAs will diagnose the cause of the
STOPPED or problem and reset the pageset status. If this
COPY happens persistently or repeatedly, notify the DBA
PENDING state. immediately!
C90096 The maximum Program This is caused by a program which is either
number of locks Issue missing commit logic or is not committing
for a package or frequently enough. If commit logic is not found, it
pageset has must be added to the unit of work cycle in the
been exceeded. program. If commit logic is present, lowering
commit WS002-ROWS-TO-COMMIT in the input
parms may resolve the problem.
C900BA A utility DRAIN DBA Issue This normally caused by a database reorg whose
request DRAIN request holds resources for a period that
exceeded the exceed the system timeout limit. This should
maximum time resolve itself within a matter of seconds. If this
limit. situation persists, then contact the DBA
immediately!
D70014 or A database DBA Issue This happens when a tablespace extends to the
D70025 tablespace failed maximum number of extents or there is insufficient
to extend or find space to expand in the tablespace or indexspace
sufficient space STOGROUP. The DBA should be contacted
allocation. immediately!
SQLState: 57011
Common Resource Type
Codes
• DB2 Messages
• DB2 Codes