Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

8 questions: 3 warm-ups and 5 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. 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

  2. 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

  3. 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.

  1. 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

    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.

    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
  2. 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

    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
  3. 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

    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
  4. 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

    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
  5. 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

    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

All COBOL interview questions · The COBOL track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.