Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

A core system holds 400,000 lines of business logic in PL/SQL packages, and the company wants to move to Java services and possibly off Oracle. How do you plan this?

I would start with an inventory of the packages by real usage, change frequency and dependencies, because a large share of 400,000 lines is usually dead or rarely used. Then we strangle the system gradually: new features go into Java services, the remaining PL/SQL is wrapped behind APIs, and the most frequently changed areas move first, each protected by characterisation tests that capture today's outputs for real inputs. Efficient set-based SQL stays as SQL even after the move, and we keep PL/SQL skills on the team for the years the old code keeps running.

Why this question is asked

Large PL/SQL estates are common in banks, insurers and telecoms. They often work well, but they are hard to change, hard to test and tie the company to Oracle. A big-bang rewrite of 400,000 lines almost always fails: the business keeps changing the old system while the new one is built, and the rewrite never catches up. Interviewers ask this leadership question to see whether we can plan a multi-year migration that delivers value early and keeps the business safe. In this answer, we will look at how to understand what we have, how the strangler approach works here, how to protect behaviour, what should stay in SQL, and how to keep the team able to support both worlds.

1Understanding What We Have

Before any plan, we need facts about the code. Oracle's data dictionary tells us a lot. DBA_SOURCE holds the code and its line counts, DBA_DEPENDENCIES shows which packages call which and which tables they touch, and runtime views such as V$SQL, or AWR history if it is licensed, show which statements and package calls actually execute and how often. The PL/SQL hierarchical profiler (DBMS_HPROF) and code coverage tools can show which procedures run during a representative period.

Version control gives the other half: which packages change most often. Combining the two produces a simple picture. Code that runs often and changes often is where the migration pays off first. Code that runs often but never changes is stable and can wait. Code that has not run in a year is probably dead, and in practice it is often 20 to 40 percent of a large estate.

SQL
-- Lines of code per package
SELECT owner, name, COUNT(*) AS lines
FROM dba_source WHERE type = 'PACKAGE BODY' AND owner = 'CORE'
GROUP BY owner, name ORDER BY lines DESC;
-- CORE BILLING_PKG 38210
-- CORE RATING_PKG 27455
-- Who depends on a package
SELECT name, type FROM dba_dependencies
WHERE referenced_owner = 'CORE' AND referenced_name = 'RATING_PKG';
Sorting packages by usage and change
Runs often?Changes often?Plan
YesYesMigrate first: highest value
YesNoWrap behind an API, migrate later or never
NoYesCheck why; often a candidate to simplify
NoNoConfirm dead, then delete

2Strangling the System Gradually

The strangler fig approach replaces a system piece by piece while it keeps running. Three rules make it work here. New features are built in Java services from now on, so the PL/SQL estate stops growing. The remaining PL/SQL is put behind an API owned by a service: other code stops calling packages directly and calls the service, which at first simply delegates to the PL/SQL. And we migrate the most frequently changed areas first, because every change made in the new code is a change not made in the old.

The wrapping step is what makes the rest possible. Once callers go through an API, we can replace what is behind it without touching them. A rating service might first call RATING_PKG through JDBC, then run new Java logic for one product line while the rest still goes to PL/SQL, and finally drop the package.

Step throughWrapping before replacing
  1. Callers: web apps, batch jobscall the service API, never the packages directly
  2. Rating service (Java)new logic in Java, routes the rest to PL/SQL
  3. RATING_PKG (PL/SQL)shrinks as product lines move
  4. Oracle tablesshared until the data also moves

4 layers, from the top down. Step through them one at a time.

3Protecting Behaviour With Characterisation Tests

Old PL/SQL rarely has tests, and nobody fully remembers its rules. Characterisation tests capture what the code does today, right or wrong, so the new code can be proven to do the same. We take real inputs, for example a month of anonymised rating requests, run them through the PL/SQL, and store the outputs. The Java implementation must produce identical outputs for the same inputs before it takes over.

In production we can go further with a parallel run: for a period, both implementations compute every result, the old one is used, and the differences are logged. When the difference rate is zero, or every difference is understood and accepted as a bug fix, we switch. This finds the rules nobody documented, such as rounding done in a particular order.

4What Should Stay in SQL

Moving logic out of PL/SQL does not mean moving it out of SQL. PL/SQL packages often contain efficient set-based statements: a MERGE that updates a million rows, a reporting query with analytic functions. Rewriting those as Java loops that fetch rows and update them one by one would make them dozens of times slower.

So the rule is that procedural logic, decisions and orchestration move to Java, while set-based data work stays as SQL, run from Java through JDBC, jOOQ or a repository. If the company later leaves Oracle, that SQL is ported to the new database's dialect, which is a far smaller job than rewriting logic.

5Keeping the Skills and Setting Expectations

A migration like this runs for years, and the PL/SQL keeps running in production throughout. If the team loses its PL/SQL knowledge in year one, every incident in the old code becomes dangerous. So the plan budgets for it: a few experienced PL/SQL developers stay on the team, paired with Java developers on each migrated area so knowledge transfers, and code review rules apply to both languages.

I would also set expectations with leadership. A realistic plan delivers value every quarter, through faster changes in migrated areas and dead code removed, rather than promising a finish date in year one. Leaving Oracle completely may be a goal, but it should be a later decision, made when the remaining PL/SQL is small enough that porting it is clearly cheaper than keeping it.

6Follow-up questions

How do you decide when to also move the data off Oracle?

When the logic in front of a group of tables has moved to services and those services own the tables. Then the data can move with them, one bounded area at a time. Moving the data while PL/SQL still reads it directly would break the old code.

What if the business wants a date for leaving Oracle?

I would give a range based on the inventory, for example that 40 percent of the code is dead and the hot 20 percent can move in 18 months, and show the remaining risk explicitly. A single date for 400,000 lines without that analysis is a guess, and I would say so.

How do you keep the old and new implementations consistent during the parallel run?

Both read the same inputs and we compare outputs, not internal state. The new one writes nothing during the parallel run; only the old one's result is used. That way a bug in the new code shows up as a logged difference rather than a production error.

7Conclusion

In this answer, we planned a move from 400,000 lines of PL/SQL to Java services by first measuring usage, change frequency and dependencies to find the dead code and the hot spots. We strangled the system gradually, with new features in Java, PL/SQL wrapped behind service APIs and the most changed areas migrated first, protected by characterisation tests and parallel runs. We kept efficient set-based SQL as SQL, and we budgeted for PL/SQL skills on the team for the years the old code keeps running.

What to say in the interviewAbout 90 seconds aloud

Open with

I would not plan a rewrite of 400,000 lines; I would plan a gradual strangling, and start with facts. Using DBA_SOURCE and DBA_DEPENDENCIES for size and dependencies, runtime data like V$SQL or the hierarchical profiler for what actually runs, and version control for what changes, I sort packages into four groups.

Then, if they want more

Code that runs and changes often moves first, because that is where the team spends its time. Stable code gets wrapped and can wait. Code that never runs is confirmed dead and deleted, and that is often a third of the estate.

Then three rules: new features go into Java services so the PL/SQL stops growing; callers go through service APIs instead of calling packages, so we can replace what is behind the API without touching them; and each area is migrated with characterisation tests that record today's outputs for real inputs, plus a parallel run in production comparing old and new results before switching.

I would be careful not to turn efficient set-based SQL into slow Java loops: decisions and orchestration move to Java, but a big MERGE stays SQL. And I would keep experienced PL/SQL developers on the team throughout, paired with Java developers, because the old code runs in production for years. Leaving Oracle completely becomes a later decision once the remaining PL/SQL is small.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A core system holds 400,000 lines of business logic in PL/SQL packages, and the company...": https://scrivio-interview-library.netlify.app/databases/oracle-and-sql-server/c48505bc9e/