Q1
What is SQLCODE and what are common values?
SQLCODE is a return code in SQLCA indicating the result of SQL execution.
Common SQLCODE values:
| 0 | Successful execution |
| 100 | No data found / End of cursor |
| -803 | Duplicate key on insert |
| -811 | Multiple rows returned for singleton SELECT |
| -904 | Unavailable resource |
| -911 | Deadlock/timeout |
| -922 | Authorization failure |
| -927 | DB2 not available |
Negative = Error, 0 = Success, 100 = No data
Q2
What is SQLCODE and common values?
SQLCODE indicates SQL result. 0=success, 100=not found/EOF, negative=error. Common: -803 duplicate key, -811 multiple rows, -904 unavailable, -911 deadlock, -818 timestamp mismatch.
Q3
Explain INNER JOIN vs LEFT OUTER JOIN.
INNER returns only matching rows. LEFT OUTER returns all left rows plus matching right (NULL if no match). LEFT preserves all left table rows.
Q4
How to handle NULL values?
NULL means unknown/missing. Use IS NULL/IS NOT NULL. COALESCE(col,default) substitutes. Indicator variables in COBOL detect NULL. NVL alternative function.
Q5
How does cursor work?
DECLARE defines cursor. OPEN executes SELECT. FETCH retrieves rows. CLOSE releases resources. FOR UPDATE allows positioned UPDATE/DELETE. WITH HOLD survives COMMIT.
Q6
What is indicator variable?
Indicator detects NULL. Declare: 01 VAR-IND PIC S9(4) COMP. Use: INTO :VAR:VAR-IND. Negative means NULL. Required for nullable columns.
Q7
How does COMMIT work?
COMMIT makes changes permanent, releases locks. ROLLBACK undoes changes. Implicit COMMIT at program end. Frequent COMMIT reduces lock duration.