PL/SQL & T-SQL (Oracle and SQL Server) Module 16
Across both engines: porting and concurrency interview questions
Interview questions on “Across both engines: porting and concurrency”: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
How does a PL/SQL EXCEPTION section map to T-SQL?
The statements move into BEGIN TRY ... END TRY and the handlers into one BEGIN CATCH ... END CATCH block that follows it. PL/SQL picks a handler by exception name; T-SQL has a single CATCH block that reads ERROR_NUMBER(), ERROR_MESSAGE() and the other error functions, the counterparts of SQLCODE and SQLERRM, and branches on the number, 8134 for example where PL/SQL had WHEN ZERO_DIVIDE, with a last branch for WHEN OTHERS. An application error raised with RAISE_APPLICATION_ERROR and a number from -20000 to -20999 becomes THROW with a number of 50,000 or more, and a RAISE that re-raises inside a handler becomes THROW; with no arguments.
From the lesson Porting code between PL/SQL and T-SQL
-
Fresher to mid
Where does a PL/SQL package variable go in a T-SQL port?
A package variable keeps its value for the whole session and across calls, and T-SQL has neither packages nor variables that outlive a batch. Small values that belong to one session, such as a counter or the current user's id, move to SESSION_CONTEXT: sp_set_session_context stores a key with a value of up to 8,000 bytes, 1 MB in all, and SESSION_CONTEXT reads it in later batches of the same session. Values that must last beyond the session, or that several sessions share, move to a table. Package constants become literals, functions or rows of a settings table.
From the lesson Porting code between PL/SQL and T-SQL
-
Fresher to mid
Why can a report wait for a writer on SQL Server but not on Oracle?
The engines serve readers in different ways. Oracle answers each query from the data committed when the query began: when a row has been changed and not committed, it rebuilds the old version from undo data, so a reader takes no lock and a writer's lock never stops it; only SELECT ... FOR UPDATE asks for the row lock. SQL Server's default, READ COMMITTED with READ_COMMITTED_SNAPSHOT off, takes a shared lock on each row it reads, and a shared lock waits for a writer's exclusive lock until the writer's transaction ends, or until SET LOCK_TIMEOUT ends the statement with error 1222. Turning READ_COMMITTED_SNAPSHOT on makes SQL Server readers use row versions, and they stop waiting.
From the lesson Oracle vs SQL Server: reads, locks and deadlocks
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
A PL/SQL billing package of 12 procedures is being ported to T-SQL. Design its parity tests: which cases you write, how you compare the results of the two engines, and which differences, if any, you would accept.
- What it tests
- Turning the semantic and error differences between the engines into concrete test cases, and comparing results across engines with a canonical fingerprint rather than by eye.
- First step
- List the rules that can change results without an error, empty strings, NULLs, case, spaces, division, dates, errors and package state, and write at least one case per rule that each procedure touches and that would fail if the port broke it. Then fix one canonical form for the results of the reference queries.
- Follow-ups
-
- How do you keep the utPLSQL and tSQLt suites from drifting apart?
- Which differences would you accept, and where do you record them?
- How do both suites run before every merge?
From the lesson Porting code between PL/SQL and T-SQL
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; a pass never renews. 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 staff
SSMA converted a PL/SQL schema of 40 objects to T-SQL, its report shows no conversion errors, and the team wants to switch the callers next week. What can a clean conversion still hide, and how would you find it before the switch?
- What it tests
- Knowing that a conversion without errors can still change results and transaction behaviour, and planning checks that find those changes before callers depend on them.
- First step
- A clean report means every object became valid T-SQL, not that it behaves the same. Start from the behaviours that change silently and where they live in the code: string and NULL handling, ordering, dates, division, error handlers, transaction boundaries and package state.
- Follow-ups
-
- Which objects would you test first, and why?
- What would make you delay the switch?
- How would you go back if a difference appears after it?
From the lesson Porting code between PL/SQL and T-SQL
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A transfer procedure ported from PL/SQL to T-SQL kept its old deadlock handler: catch the error, pause, run the failed UPDATE again, commit. Since the port, a few customers a week receive credits that nobody debited. Explain what changed and redesign the handler so that it is correct on both engines.
- What it tests
- Knowing what ORA-00060 and error 1205 each roll back, and redesigning a retry so that it is correct on both engines.
- First step
- Compare what each error leaves behind. ORA-00060 undoes only the statement that detected the deadlock, so on Oracle the debit was still in the open transaction when the credit ran again. Error 1205 rolls back the victim's whole transaction, so on SQL Server the debit is gone and the repeated credit runs alone.
- Follow-ups
-
- Why did the old handler ever work on Oracle?
- Which errors should the new handler retry, and how many times?
- How would you show that the fix works before the next release?
From the lesson Oracle vs SQL Server: reads, locks and deadlocks
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
An Oracle batch runs at SERIALIZABLE and retries on ORA-08177. Its port to SQL Server sets SERIALIZABLE too. It never fails now, but order entry waits for minutes while the batch runs. Explain why, and choose the SQL Server setup that keeps the batch's Oracle behaviour.
- What it tests
- Knowing that Oracle's SERIALIZABLE works with versions and SQL Server's with locks, and choosing the SQL Server level that keeps the batch's behaviour, with its prerequisite, its error and its cost.
- First step
- The two levels share a name, not a mechanism. Oracle's SERIALIZABLE reads versions and locks nothing it reads, so order entry never waited. SQL Server's holds shared and key-range locks to the end of the transaction, so every order that touches a row or range the batch read waits for the batch.
- Follow-ups
-
- What must be switched on in the database before the batch can use that level?
- Which error takes the place of ORA-08177, and what does the batch do with it?
- What does that level cost the server while the batch runs?
From the lesson Oracle vs SQL Server: reads, locks and deadlocks
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
Three queries make up a month-end report: the ledger total, the total per account and the number of postings. On Oracle it runs in SET TRANSACTION READ ONLY and the numbers always agree. On SQL Server with READ_COMMITTED_SNAPSHOT on, they sometimes disagree by one posting. Explain why, and port the report.
- What it tests
- Telling statement-level from transaction-level read consistency, and porting a read-only Oracle transaction to the SQL Server setting that keeps one view for all three queries.
- First step
- RCSI gives each statement the data committed when that statement began. A posting committed between the first and the third query is in one number and not in another. Oracle's READ ONLY transaction gave all three queries the view of its own start.
- Follow-ups
-
- Why not run the report at SERIALIZABLE instead?
- What changes if the report also writes a summary row?
- How would you test that the three numbers now agree?
From the lesson Oracle vs SQL Server: reads, locks and deadlocks
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
All PL/SQL & T-SQL (Oracle and SQL Server) interview questions · The PL/SQL & T-SQL (Oracle and SQL Server) track