Oracle 1Z0-182 study materials
Oracle 1Z0-182 study resources

Role Privileges in a Definer's-Rights Procedure and a Moving Report Snapshot

Oracle 1Z0-182 · Put your knowledge to work in context.

All case studies

Role Privileges in a Definer's-Rights Procedure and a Moving Report Snapshot

Schema ETL owns the procedure ETL.RUN_REPORT, created with the default definer's-rights setting. The procedure selects from APP.V_ORDERS. ETL was granted SELECT on APP.V_ORDERS through the role ETL_ROLE, not directly. Reporting user RPT has CREATE SESSION, has been granted EXECUTE on ETL.RUN_REPORT directly, and has been granted the role RPT_ROLE, which contains SELECT on APP.V_ORDERS. RPT can run SELECT * FROM app.v_orders interactively and see rows, but executing ETL.RUN_REPORT fails with ORA-00942 table or view does not exist. Separately, the month-end report runs four queries in one session over 25 minutes. The nightly load commits between query two and query three, and the report totals do not reconcile. The reporting connection comes from a pool that sometimes returns the session to the pool between queries. Security has also asked what happens if RPT_ROLE is revoked at 09:00 while a report session is still connected.

1. Diagnose the ORA-00942 in ETL.RUN_REPORT and compare the available fixes.

Read the worked answer

This is privilege resolution, not a missing view. In a definer's-rights procedure, the default AUTHID DEFINER, name resolution and privilege checks run as the owner, ETL. Roles are disabled during definer's-rights PL/SQL execution; only direct grants to ETL count. ETL has SELECT on APP.V_ORDERS only through ETL_ROLE, so the procedure cannot see the view. RPT's interactive SELECT works because a normal SQL session has roles enabled.

Options:

  1. GRANT SELECT ON app.v_orders TO etl; This is the smallest change and keeps definer's rights, so all callers share ETL's access.
  2. Recreate the procedure with AUTHID CURRENT_USER. Then RPT's privileges are checked at runtime. Roles are enabled for invoker's-rights execution, but relying on a role grant is fragile if the procedure is later called from another definer's-rights program; a direct grant to RPT is safer.
  3. Move the view into ETL or create a controlled interface object owned by ETL. Do not grant SELECT ANY TABLE. Verify with ALL_TAB_PRIVS and SESSION_PRIVS, and confirm the view owner has privileges on the underlying tables. After fixing, test as RPT, not as ETL, because the failure only appears for callers.

2. Why do the four queries disagree, and what transaction control would make the report internally consistent?

Read the worked answer

Oracle provides statement-level read consistency. Each query sees the database as of its own start time, so a load committing between query two and query three becomes visible to query three. The report is mixing snapshots. A read-only transaction extends consistency to the whole transaction:

SET TRANSACTION READ ONLY;
-- run all four SELECTs
COMMIT;  -- or ROLLBACK

It must be the first statement in the transaction. It sees only changes committed before it began and ignores later commits. Any DML raises ORA-01456, so use a dedicated reporting session, not a pooled connection that might later run updates. A serializable transaction gives the same snapshot semantics but permits DML and can raise ORA-08177 on conflict. If the report cannot hold a transaction open, use Flashback Query with the same timestamp or SCN on every query:

SELECT ... FROM app.v_orders AS OF TIMESTAMP :snapshot_ts;

That requires undo retention long enough to cover the 25-minute window. Also confirm the four queries actually run on the same session; a pool that reclaims the connection between queries starts a new transaction and defeats either approach.

3. Security revokes RPT_ROLE at 09:00 while RPT is connected. What is the immediate effect, and how does that differ from revoking a direct object grant?

Read the worked answer

Role grants are evaluated at logon and when roles are explicitly enabled, so revoking RPT_ROLE does not strip the already-enabled role from an existing session. RPT can continue to exercise privileges obtained through that role until reconnecting or until a SET ROLE statement changes the enabled roles. A new session after 09:00 will not have the role. If immediate removal is required, the DBA can alter the user's default roles, issue SET ROLE NONE in the session, or kill the session; do not assume the revoke is instantaneous for connected users.

A direct object grant behaves differently. Revoking a directly granted object privilege takes effect for subsequent privilege checks in existing sessions; a statement that has not yet parsed fails, although an already-open cursor may continue until it is reprepared. This asymmetry matters for incident response: revoking a role is not a reliable kill switch for a live session, while revoking a direct grant is closer to one. For the procedure problem in this scenario, prefer a direct grant to ETL or an invoker's-rights design, and document that role-based grants are unavailable inside definer's-rights PL/SQL. Test both the connected-session and reconnect paths before declaring the security change complete.