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.

PL/SQL & T-SQL (Oracle and SQL Server)  Module 11 – Subprograms, packages and robust error logging

Dependencies, compilation and warnings

Reading object dependencies and status in the data dictionary, predicting which DDL changes invalidate dependent PL/SQL, and compiler warnings.

  • Advanced
  • 15 minutes
  • Examples run with oracle-free 23.26.3.0.0, mssql 17.0.5005.3, Python 3.14.8 and Pyodide 314.0.7
  • By MySmartCoPilot
Free core, Pro depth: 6 of 15 minutes free
Free: The dictionary lists what depends on what and whether it is current · A stale unit is revalidated on use, not broken · Compiler warnings flag risky code before it runs. With a pass: 2 in-depth parts and 3 interview answers, about 9 minutes.

What you will learn

  • Read dependencies and object status in USER_DEPENDENCIES and USER_OBJECTS
  • Predict which dependents an ALTER TABLE ... ADD column invalidates
  • Choose how to recompile a schema after a deployment and find what failed
  • Use PLSQL_WARNINGS and conditional compilation to catch problems at compile time
  • Explain how editions let old and new code run side by side

Before you start

What you’ll learn · Before you start

What you will learn

  • Read dependencies and object status in USER_DEPENDENCIES and USER_OBJECTS
  • Predict which dependents an ALTER TABLE ... ADD column invalidates
  • Choose how to recompile a schema after a deployment and find what failed
  • Use PLSQL_WARNINGS and conditional compilation to catch problems at compile time
  • Explain how editions let old and new code run side by side

Before you start

On this page

A release adds one nullable column to a table that has five direct dependents, and Oracle recompiles exactly two of the six objects around it. Which two depends on how each unit uses the table, not on how big the change is. Predicting that list is what turns a quiet column addition from a surprise into a plan.

This lesson shows how Oracle records dependencies and status, why a stale unit is not a broken one, and how compiler warnings catch risky code before it runs. Two deeper parts then apply the documented rules to a real change, recompile a schema after a deployment, and cover conditional compilation, optimisation and editions.

The dictionary lists what depends on what and whether it is current

A dependency is a reference from one object to another: a procedure that selects from a table depends on that table. Oracle records every such reference and gives every object a status. The views USER_DEPENDENCIES, ALL_DEPENDENCIES and DBA_DEPENDENCIES list each object dependency: A reference from one database object to another, recorded in USER_DEPENDENCIES and checked when the referenced object changes.: the dependent object and its type, and the object and type it references. CREATE statements update the dependencies on their own. Dynamic SQL does not: a statement run with EXECUTE IMMEDIATE creates no dependencies, so a unit that reaches a table only that way is never marked stale when the table changes.

The object status: The STATUS column in USER_OBJECTS: VALID when the object compiled against its current references, INVALID when it compiled with errors, a reference changed or a privilege was revoked. of an object is in USER_OBJECTS. Oracle distinguishes four states: valid, compiled with errors, invalid because something it references changed, and unauthorized because a privilege was revoked. The *_OBJECTS views show the last three all as INVALID. A dependent that references another object is a direct dependent of it, and a dependent of that dependent is an indirect one. The figure shows the six objects of the lesson’s example.

Interactive · step by step Who depends on dep_customers Step through the six objects and see which ones USER_DEPENDENCIES lists under the table and which under the function.
Who depends on dep_customers, step 4 of 4. Showing dep_customers (all six VALID), dep_names_v, dep_all_v, dep_name_of, dep_cities, dep_row_of, dep_report. In focus: dep_customers.dep_customersall six VALIDdep_names_vview, named columnsdep_all_vview, SELECT *dep_name_offunctiondep_citiesproceduredep_row_ofprocedure, ROWTYPEdep_reportcalls the functionno row for dynamic SQL

The drawing shows the whole scene; its 4 steps are listed below.

Every step as text
  1. Five direct dependents. USER_DEPENDENCIES lists a row for each object that references dep_customers directly. Two views, a function and two procedures name it, so the table has five direct dependents.
  2. A sixth object, one step away. dep_report calls dep_name_of and never names the table. It is an indirect dependent of the table, and a direct dependent of the function only.
  3. Status says if it is current. USER_OBJECTS.STATUS reads VALID for all six objects after they compile. A change to the table can make a dependent stale, and the status then reads INVALID until Oracle revalidates it.
  4. Dynamic SQL leaves no row. A statement run with EXECUTE IMMEDIATE creates no dependency, so a unit that reaches the table only that way never appears in the list and is never marked stale.

Checkpoint

Check: Dependencies and status in the dictionary

  1. Question 1 of 2 Which dictionary view lists the objects that reference the table dep_customers?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: USER_DEPENDENCIES, with REFERENCED_NAME = 'DEP_CUSTOMERS'

    The dependencies views record references, and the objects views record status. To find what a change to a table can reach, read the dependencies.

  2. Question 2 of 2 A procedure reads INVALID in USER_OBJECTS. Which statement about its real state can you be sure of?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: It compiled with errors, or something it references changed, or a privilege was revoked

    INVALID covers three causes, and only one of them is an error in the unit. Read USER_ERRORS to tell them apart.

A stale unit is revalidated on use, not broken

INVALID means that the compiled form may no longer match what the unit references, not that the code is wrong. Oracle decides how far a change reaches. With coarse-grained invalidation, a DDL statement that changes a referenced object invalidates all of its dependents. With fine-grained invalidation: Invalidation that marks only the dependents a DDL change affects, those that rely on the changed attribute or whose compiled metadata is no longer correct, not every dependent. it invalidates only the dependents that rely on the changed attribute, or whose compiled metadata is no longer correct. A change that invalidates one object also invalidates that object’s dependents, which Oracle calls cascading invalidation.

When someone next uses an invalid PL/SQL unit, Oracle checks whether a referenced object changed in a way that affects it. If so, it recompiles the unit; if not, it revalidates it without recompiling. A recompile that finishes with errors leaves the unit INVALID, and the errors are in USER_ERRORS and in SHOW ERRORS. A package that is invalidated and revalidated also loses its instantiation in every session that held it, which is the discarded state of the packages lesson.

Interactive · stage by stage From a DDL change to a valid unit Step through what Oracle decides for one dependent, from the change to the next call.
From a DDL change to a valid unit, step 6 of 6. Showing DDL on the table, Does it affect the unit?, Unit stays VALID, Unit is stale, Next call or compile, Back to VALID, Stays INVALID. In focus: Back to VALID, Stays INVALID, recompile-fails.not affectedcompile failsDDL on the tablefor example ADD columnDoes it affect the unit?the rules decideUnit stays VALIDnothing to doUnit is staleINVALIDNext call or compileOracle revalidatesBack to VALIDcompiled or revalidatedStays INVALIDerrors in USER_ERRORS

The drawing shows the whole scene; its 6 steps are listed below.

Every step as text
  1. The change runs. An ALTER TABLE changes a referenced object. Oracle looks up the dependents of the table and decides, for each one, whether the change affects it.
  2. The rules decide. With fine-grained invalidation a dependent is marked only when it relies on what changed or its compiled metadata is no longer correct. With coarse-grained invalidation every dependent is marked.
  3. Unaffected units stay VALID. A dependent the change does not touch keeps its status and its compiled form. Nothing is recompiled and nobody notices.
  4. Affected units go stale. An affected dependent is marked INVALID, and so are its own dependents by cascade. Nothing is recompiled yet; the work waits for the next use.
  5. The next use revalidates. When the unit is referenced, Oracle checks whether a referenced object changed in a way that affects it. If so it recompiles the unit, and if not it revalidates it without recompiling.
  6. Success or errors. A clean compile or revalidation makes the unit VALID again. A compile with errors leaves it INVALID, and its errors are in USER_ERRORS and SHOW ERRORS.

Checkpoint

Check: Stale units and revalidation

  1. Question 1 of 2 A function is INVALID because its table changed in a way that affects it. A client calls the function. What happens?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Oracle recompiles the function, and the call runs if the compile succeeds

    An invalid PL/SQL unit is revalidated when it is referenced: recompiled if a referenced object changed in a way that affects it, otherwise revalidated without recompiling.

  2. Question 2 of 2 dep_report only calls the function dep_name_of and never names the table. The table change invalidates dep_name_of. What happens to dep_report?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: It is marked invalid by cascade, and revalidated without recompiling if the function's signature is unchanged

    Direct dependents are invalidated only by changes that affect them, but indirect dependents can be invalidated by changes that do not affect them. That is why the list of stale units can be longer than the list that recompile.

Compiler warnings flag risky code before it runs

A warning reports a condition that is not serious enough to stop compilation. The message code has the form PLW-nnnnn, and each warning belongs to one of three categories: SEVERE for conditions that might cause wrong results, such as aliasing problems with parameters; PERFORMANCE for conditions that might slow the code, such as passing a VARCHAR2 value to a NUMBER column; and INFORMATIONAL for code that is merely untidy, such as code that can never run. PLSQL_WARNINGS: A compilation parameter that enables or disables compiler warnings by category or number, or turns a named warning into an error; ENABLE:ALL turns them all on. turns warnings on and off for the instance, the session or one stored unit.

Warnings are read where errors are: in USER_ERRORS and with SHOW ERRORS.

Two parts of depth follow. The first applies Oracle’s rule table to the six objects, predicts what an ADD column and a DROP column invalidate, and recompiles after a deployment.

The second part covers conditional compilation: Directives such as $IF and $ELSE that are evaluated at compile time, selecting which code to include based on version or other constants., which selects code at compile time. It also covers the PLSQL_OPTIMIZE_LEVEL: A compilation parameter that sets how much effort the compiler spends optimising PL/SQL library units. and native compilation: Compiling a PL/SQL unit to native machine code instead of interpreting it., which trade compile effort for speed. The last topic is edition-based redefinition: A feature that lets old and new PL/SQL code run side by side in separate editions during online upgrades., which keep old and new code side by side.

Checkpoint

Check: Compiler warnings and their categories

  1. One question Code that can never run, such as a branch behind a constant FALSE, belongs to which warning category?

    Choose one answer.

    Show the answer: One question

    Answer: INFORMATIONAL

    The three categories are SEVERE, PERFORMANCE and INFORMATIONAL, and code that can never run is Oracle's own example of the last.

Predicting what a DDL change invalidates, and recompiling after it Pro: opens with a Pro, Premium or Ultimate pass

Oracle publishes the rules that decide which dependents a change invalidates, and they can be applied by hand. This part applies them to the six objects, checks the answer with a model and a script, and then recompiles a schema after a deployment and reads what failed.

In this part:

  • Applying the rule table to an ADD column
  • The same table for a DROP column, and the unit that cannot recompile
  • Watching it in the dictionary, and what Oracle’s note adds
  • Recompiling after a deployment and reading what failed

1 diagram · 3 runnable examples (Python, SQL) · about 9 minutes

Opening this part with your pass…

This part opens 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.

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

Conditional compilation, optimisation, native compilation and editions Pro: opens with a Pro, Premium or Ultimate pass

Some problems are better caught when a unit is compiled than when it runs. This part applies warnings to a unit with a branch that cannot run, selects code by database version, and weighs the optimisation level, native compilation and editions.

In this part:

  • Reading a warning, then making it an error
  • Choosing code at compile time with conditional compilation
  • The optimisation level and native compilation
  • Editions and wrapping

4 runnable examples (Python, SQL) · about 6 minutes

Opening this part with your pass…

This part opens 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.

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

Practise: predict the invalid units

Each question gives a unit and a change. Work out which exception of the rule applies, if any, before you choose.

Practice that adapts to you

Practise this lesson

7 questions about 9 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 7 A view and a function both select from a table. Which query lists both as dependents of the table?

    Choose one answer.

    Show the answer: Question 1 of 7

    Answer: SELECT name, type FROM user_dependencies WHERE referenced_name = 'T'

    Dependencies are recorded when objects are created and listed in the dependencies views.

  2. Question 2 of 7 A procedure reaches a table only through EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM dep_customers'. The table is altered. What does USER_DEPENDENCIES say about the procedure?

    Choose one answer.

    Show the answer: Question 2 of 7

    Answer: It does not list the procedure, so the procedure is not marked stale

    The list is complete only for static references. A unit that builds statements at run time needs a source search.

  3. Question 3 of 7 Nobody has called an INVALID function since the table changed. What is its compiled form?

    Choose one answer.

    Show the answer: Question 3 of 7

    Answer: Out of date, and Oracle will check it when the function is next used

    INVALID means stale. The unit is recompiled or revalidated the next time it is referenced.

  4. Question 4 of 7 A procedure names a column that has been dropped. It is called, and Oracle tries to recompile it. Where do you find the reason it stays INVALID?

    Choose one answer.

    Show the answer: Question 4 of 7

    Answer: In USER_ERRORS, or with SHOW ERRORS

    The error rows name the line and the message, such as an invalid identifier for the dropped column.

  5. Question 5 of 7 A package that holds session state is invalidated and then revalidated. What happens to a session that was using it?

    Choose one answer.

    Show the answer: Question 5 of 7

    Answer: Its instantiation, with the state, can be lost

    This is the ORA-04068 of the packages lesson, reached here through a dependency change instead of a replaced body.

  6. Question 6 of 7 Which warning category fits a parameter aliasing problem that might cause wrong results?

    Choose one answer.

    Show the answer: Question 6 of 7

    Answer: SEVERE

    Aliasing is Oracle's example of a SEVERE warning.

  7. Question 7 of 7 A unit compiles with a warning. Where can you read it?

    Choose one answer.

    Show the answer: Question 7 of 7

    Answer: In USER_ERRORS, or with SHOW ERRORS

    The static view *_ERRORS and the SQL*Plus command SHOW ERRORS show both errors and warnings.

Interview questions

Warm-up (fresher to 2–5 years): how do you find every object that depends on a table?

Query USER_DEPENDENCIES with WHERE referenced_name = 'YOUR_TABLE'; each row gives a dependent object and its type. The ALL_ and DBA_ versions widen the search to other schemas. The list is complete only for static references: a statement run through dynamic SQL creates no dependency, so search the source for the table name as well when a unit builds statements at run time.

Three longer questions follow, about a deployment that left objects invalid, a column addition whose effects you must predict, and an upgrade that cannot take the application offline:

  1. Mid to senior

    After a large schema migration, 150 PL/SQL objects show STATUS INVALID. The team plans to let them recompile on first call. What is the risk, and how would you handle them before the application starts?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Senior to staff

    A release adds a nullable column to a busy table. Its dependents are a view with SELECT *, a function that selects one named column with a bind variable in its WHERE clause, a procedure that selects one named column with no variable, and a procedure using table%ROWTYPE. Which will Oracle recompile, and how would you check?

    Model answer, Pro. First step and follow-ups

  3. Senior to staff

    Your team is deploying a major PL/SQL change and the application must stay online. A colleague suggests edition-based redefinition. What does the team need to prepare, and how would you roll back if the new code fails?

    Model answer, Pro. First step and follow-ups

Flashcards · 8 cards

Recall it, then check

Say the answer to yourself before you look: recalling it is what makes it stick.

  1. Where does Oracle record which object depends on which?

    In USER_DEPENDENCIES, ALL_DEPENDENCIES and DBA_DEPENDENCIES: each row gives the dependent object and its type and the referenced object and its type. CREATE statements update these on their own.

  2. Why is a unit that reaches a table only through EXECUTE IMMEDIATE never marked stale?

    Dynamic SQL creates no dependencies, so Oracle records nothing to invalidate when the table changes.

  3. Which states can an object be in, and how do the dictionary views show them?

    Valid; compiled with errors; invalid because something it references changed; and unauthorized because a privilege was revoked. The OBJECTS views show the last three all as INVALID.

  4. What does INVALID actually mean for a PL/SQL unit?

    That the compiled form may no longer match what the unit references, not that the code is wrong. On its next use Oracle recompiles it if a referenced object changed in a way that affects it, and otherwise revalidates it without recompiling.

  5. How do coarse-grained and fine-grained invalidation differ, and what cascades?

    Coarse-grained invalidation marks every dependent of the changed object; fine-grained marks only the dependents that rely on the changed attribute or whose compiled metadata is no longer correct. A change that invalidates one object also invalidates that object's dependents, which Oracle calls cascading invalidation.

  6. Where are the errors of a recompile that failed?

    The unit stays INVALID and the errors are in USER_ERRORS and in SHOW ERRORS. A package that is invalidated and revalidated also loses its instantiation in every session that held it.

  7. What are the three categories of PL/SQL compiler warning?

    SEVERE for conditions that might cause wrong results, such as aliasing problems with parameters; PERFORMANCE for conditions that might slow the code, such as passing a VARCHAR2 value to a NUMBER column; and INFORMATIONAL for untidy code, such as code that can never run. Each message code has the form PLW-nnnnn.

  8. What can PLSQL_WARNINGS be set for, and where do warnings appear?

    For the instance, the session or one stored unit. Warnings are read where errors are: in USER_ERRORS and with SHOW ERRORS.

Key takeaways

  • USER_DEPENDENCIES lists the references between objects, and USER_OBJECTS.STATUS shows whether each is current.
  • INVALID means stale, not broken: Oracle recompiles or revalidates the unit on its next use.
  • Fine-grained invalidation marks only the dependents a change affects, and each operation has its own rule table.
  • After a deployment, recompile on purpose instead of letting the first caller find a failure.
  • Warnings, conditional compilation and editions are settings chosen at compile or upgrade time.

Terms in this lesson

conditional compilation
Directives such as $IF and $ELSE that are evaluated at compile time, selecting which code to include based on version or other constants.
edition-based redefinition
A feature that lets old and new PL/SQL code run side by side in separate editions during online upgrades.
fine-grained invalidation
Invalidation that marks only the dependents a DDL change affects, those that rely on the changed attribute or whose compiled metadata is no longer correct, not every dependent.
native compilation
Compiling a PL/SQL unit to native machine code instead of interpreting it.
object dependency
A reference from one database object to another, recorded in USER_DEPENDENCIES and checked when the referenced object changes.
object status
The STATUS column in USER_OBJECTS: VALID when the object compiled against its current references, INVALID when it compiled with errors, a reference changed or a privilege was revoked.
PLSQL_OPTIMIZE_LEVEL
A compilation parameter that sets how much effort the compiler spends optimising PL/SQL library units.
PLSQL_WARNINGS
A compilation parameter that enables or disables compiler warnings by category or number, or turns a named warning into an error; ENABLE:ALL turns them all on.

References

Report a problem with this lesson

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.