DB2beginner

SQL Fundamentals for DB2 on z/OS

Understand the baseline SQL skills expected for DB2 z/OS interviews and how embedded SQL differs from ad hoc SQL.

DB2 for z/OS speaks standard SQL, but interviewers expect fluency in both the ad hoc query sense (writing correct SELECT/INSERT/UPDATE/DELETE statements) and the embedded sense (how that same SQL gets woven into a COBOL program for batch or CICS use). Getting comfortable with both contexts, and knowing what changes between them, is the entry point for every other DB2 topic.

Embedded SQL is like filling out a bilingual form where certain blanks (host variables) are shared between two languages — English on one side, SQL on the other — and after submitting the form, you always check a stamped status code at the bottom before assuming the clerk actually processed it the way you expected.

Key Concepts

1
Ad hoc SQL, run through tools like SPUFI or QMF, is exactly what you'd expect from any relational database — joins, WHERE clauses, GROUP BY, ORDER BY — and interviewers use simple query-writing exercises to confirm baseline competency before moving into DB2-specific territory. Embedded SQL adds a layer: statements are wrapped in EXEC SQL/END-EXEC, values move in and out of the database via host variables (COBOL working-storage fields prefixed with a colon in the SQL, like :WS-CUST-ID), and every statement's outcome must be checked via SQLCODE in the SQLCA (SQL Communication Area).
2
A foundational distinction interviewers probe is singleton SELECT versus cursor-based retrieval: a SELECT INTO expecting exactly one row works fine for single-row lookups, but any query that might return more than one row requires a cursor (DECLARE, OPEN, FETCH, CLOSE) because COBOL has no native way to receive a result set directly the way a SELECT INTO can receive one row.
3
A reliable interview signal is whether a candidate naturally checks SQLCODE after every embedded SQL statement rather than assuming success — SQLCODE = 0 means success, +100 means no rows found (not necessarily an error condition, often just 'nothing matched'), and negative values indicate genuine errors that typically require a program to log the problem and take a defined recovery path rather than continue blindly.