COBOL Module 13
Db2 and embedded SQL interview questions
Interview questions on db2 and embedded SQL: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
What is a host variable in embedded SQL, and what does an indicator variable add?
Answered in the lesson Embedded SQL: host variables, SQLCA and SQLSTATE
-
Fresher to mid
What do SQLCODE 0, +100 and a negative SQLCODE mean, and why do portable programs test SQLSTATE?
Answered in the lesson Embedded SQL: host variables, SQLCA and SQLSTATE
-
Fresher to mid
What are the four statements of a cursor, and how does a program know it has read the last row?
Answered in the lesson Cursors, commits and restartable batch
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
The column OD_LIMIT was changed to allow NULL for accounts without an overdraft. The nightly statement program, unchanged, now stops with SQLCODE -305 on some accounts. Explain it, fix it, and say how you find every program at risk from the change.
- What it tests
- Indicator variables, why a schema change breaks programs nobody touched, the COALESCE trade-off, and impact analysis across programs.
- First step
- Find the statement in the program that reads OD_LIMIT and check its host variable: with no indicator variable, a NULL has nowhere to go. IBM's -305 says an indicator must be supplied for a column that can return a null value.
- Follow-ups
-
- Why not just use COALESCE?
- How do you find the other programs that read OD_LIMIT?
- How should the schema change have been released?
From the lesson Embedded SQL: host variables, SQLCA and SQLSTATE
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A team wants to run the SQL of its Db2 COBOL programs against PostgreSQL in local tests. Every check paragraph is an EVALUATE on Db2's SQLCODE numbers. What breaks, how do you restructure the checks, and what can such tests never prove about Db2?
- What it tests
- Portable error handling with SQLSTATE, where SQLSTATE still differs between products, and what a second database can and cannot test.
- First step
- Run the same statements on both databases and compare the SQLCA. In the lesson's run four failures gave the same SQLSTATE on both while every SQLCODE differed, so checks on SQLCODE send PostgreSQL's errors down the wrong branch.
- Follow-ups
-
- Which outcomes still need product-specific handling?
- Where do you keep the codes so programs do not repeat them?
- What must still be tested on Db2 itself?
From the lesson Embedded SQL: host variables, SQLCA and SQLSTATE
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
An interest-posting program over 200 accounts commits every 50 rows. It abended at row 120 and operations reran it from the start. Customers then complained that interest was paid twice. Explain what happened with numbers, and redesign the program so a rerun is safe.
- What it tests
- Units of work and what a failure rolls back, why commits alone do not make a program restartable, and a restart key committed with the work.
- First step
- Work out what each commit made permanent before the failure, and what the failure undid. Then follow the rerun: which accounts it posted that the first run had already committed.
- Follow-ups
-
- How many accounts were paid twice, and how would you find them?
- Where must the restart key live, and why?
- How do you prove the redesign before the next failure?
From the lesson Cursors, commits and restartable batch
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
To stop a long Db2 batch from holding locks all night, a developer added a COMMIT every 1,000 rows inside its cursor loop. Now the program fails on the first FETCH after the first COMMIT. Explain it, and compare the ways to fix it.
- What it tests
- What COMMIT does to cursors, held cursors and where they are positioned, and restart design for a cursor loop that commits.
- First step
- Read the SQLCODE and SQLSTATE of the failing FETCH, then the DECLARE CURSOR statement, and ask what a COMMIT does to a cursor that was declared that way.
- Follow-ups
-
- What does WITH HOLD change, and what does it not?
- What would you do if the cursor could not be held?
- Is 1,000 a good interval?
From the lesson Cursors, commits and restartable batch
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
A customer search builds its dynamic SQL by pasting the name a clerk types into the statement. Searches for names such as D'SOUZA fail, and a security review flags the code. Explain both findings and rewrite the search safely.
- What it tests
- Why pasted input changes a statement, parameter markers with PREPARE and EXECUTE USING, and validation as a second layer.
- First step
- Print the statement text the program builds for D'SOUZA and read it as the database will: the apostrophe in the name is also the character that ends an SQL string.
- Follow-ups
-
- Why is escaping the apostrophe not enough?
- What still needs validating once a marker is used?
- How would a test catch the weakness before review?
From the lesson Cursors, commits and restartable batch
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes