Chapter 04 · Users, Schemas, Objects, Data Types, Keys, Constraints, and Sequences

Users vs Schemas, Object Ownership, Naming, Synonyms, and Namespace Semantics

Separate authenticated identity, current schema, object ownership, name resolution, synonyms, and privileges using observable Oracle 26ai evidence.

Intermediate95–115 minutesOwnership + namespace + privilege labOracle AI Database 26ai · RU 23.26.3 baselineFREEPDB1 · SERVICEHUB owner/runtime identitiesLast reviewed: August 2026

Learning outcomes

ServiceHub already separates its schema owner from its runtime identity. The next migration task exposes a classic cross-engine trap: a developer treats an Oracle schema like a PostgreSQL or SQL Server namespace that can be created and assigned independently, then assumes that changing CURRENT_SCHEMA grants access. Oracle's model is different. This lesson builds the ownership and name-resolution map before later lessons create richer objects.

01

Explain the close relationship between an Oracle database user and its same-named schema while distinguishing authenticated identity from current schema.

02

Predict how unqualified and schema-qualified object names are resolved and how quoted identifiers change case sensitivity.

03

Distinguish private and public synonyms from the privileges required on their target objects.

04

Use dictionary and session evidence to prove object ownership, current schema, current user, and synonym targets.

05

Design an owner/runtime naming pattern that remains explicit, least-privileged, and portable across application deployments.

Lab and version baseline

Use the disposable FREEPDB1 lab from Chapter 01 with SERVICEHUB_OWNER and SERVICEHUB_APP. The chapter is reviewed against Oracle AI Database 26ai documentation with July 2026 RU 23.26.3 as the current documented RU, SQL Developer 26.2, and SQLcl 26.2.1. Oracle AI Database Free remains capped at 2 foreground CPU cores, 2 GB combined SGA/PGA RAM, and 12 GB user data; Oracle states that Free has no Support SRs or patches, including security patches, so it is a learning baseline rather than a production recommendation. No paid option or management pack is required by the mandatory Chapter 04 labs. Record your own V$VERSION, COMPATIBLE, PDB, client, and driver state before assuming a feature is present.

1. User, schema, and current schema are related—but not interchangeable

In Oracle, creating a database user creates an account that can own a schema with the same name. The schema is the namespace that contains objects owned by that user. The authenticated session identity and the default schema used for name resolution normally start aligned, but they are separate session properties. ALTER SESSION SET CURRENT_SCHEMA changes where Oracle first looks for unqualified schema objects; it does not log in as that owner and it does not add object privileges.

sql · prove identity, current schema, and container
SELECT SYS_CONTEXT('USERENV','SESSION_USER')  AS session_user,       SYS_CONTEXT('USERENV','CURRENT_USER')  AS current_user,       SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS current_schema,       SYS_CONTEXT('USERENV','CON_NAME')      AS con_nameFROM dual;SELECT USER AS sql_user FROM dual;

For an ordinary session these values are often identical, which is why the distinction is easy to miss. Stored definer-rights code, proxy/application identity mechanisms, and explicit CURRENT_SCHEMA changes can make the differences operationally important.

2. Ownership is visible in the data dictionary

Objects belong to a schema owner. The USER_ views describe objects owned by the current user, ALL_ views describe objects accessible to the current user, and appropriately privileged administrators can use DBA_ views for database-wide inventory. Do not infer ownership from an application's unqualified SQL text.

sql · inventory ServiceHub ownership and grants
SELECT owner, object_name, object_typeFROM   all_objectsWHERE  owner = 'SERVICEHUB_OWNER'AND    object_name IN ('SERVICE_REGIONS','TECHNICIANS','WORK_ORDERS')ORDER BY object_name;SELECT owner, table_name, grantee, privilegeFROM   all_tab_privsWHERE  owner = 'SERVICEHUB_OWNER'AND    grantee = 'SERVICEHUB_APP'ORDER BY table_name, privilege;

The first query proves who owns the objects; the second proves which object privileges have been granted. Neither query says which name an application happens to use.

3. Name resolution and Oracle namespaces

Unquoted identifiers are normalized by Oracle, so work_orders, WORK_ORDERS, and Work_Orders normally resolve to the same unquoted name. Quoted identifiers preserve case and punctuation and must then be referenced exactly, including quotes. Quoted mixed-case names are legal but impose permanent quoting obligations on SQL, tools, migrations, and ORMs, so they should be deliberate rather than decorative.

Oracle also has namespaces. Tables, views, sequences, private synonyms, packages, standalone procedures/functions, user-defined types, and operators share a schema namespace; indexes and constraints have separate namespaces. This is why a table and index can share a name, while a table and sequence in the same schema cannot.

Reference Resolution idea
SERVICEHUB_OWNER.WORK_ORDERS Explicit owner + object; no synonym lookup is required.
WORK_ORDERS Search the current schema namespace first, then applicable synonym resolution.
"Work_Orders" Exact quoted identifier; different from unquoted WORK_ORDERS.
PUBLIC synonym Fallback convenience namespace; still requires privilege on the target.

4. Synonyms are aliases, not authorization

A private synonym is a schema object owned by one schema. A public synonym is visible through the public synonym namespace. Both can hide an owner or location from application SQL, but neither grants access to its target. Authorization is still evaluated against the underlying object privileges. Public synonyms also enlarge the global naming surface and can mask ownership assumptions, so they are not a default least-privilege pattern.

sql · temporary private synonym for the runtime user
-- As a PDB administrator, only for this disposable lab:GRANT CREATE SYNONYM TO servicehub_app;-- Connect as SERVICEHUB_APP to FREEPDB1:CREATE SYNONYM work_orders_api FOR servicehub_owner.work_orders;SELECT synonym_name, table_owner, table_nameFROM   user_synonymsWHERE  synonym_name = 'WORK_ORDERS_API';SELECT COUNT(*) FROM work_orders_api;-- Cleanup after the exercise:DROP SYNONYM work_orders_api;

The final query succeeds only because Chapter 01 granted SELECT on the underlying table. The synonym changes naming convenience, not authority. After the exercise, the PDB administrator can revoke CREATE SYNONYM again if it is not part of the intended runtime design.

5. Deliberately wrong approach: CURRENT_SCHEMA as a privilege shortcut

Connect as SERVICEHUB_APP and first revoke a lab-only privilege on a disposable owner table or use an owner object to which the runtime user has not been granted access. Changing the current schema does not make the runtime session the owner.

sql · failure and diagnosis
-- As SERVICEHUB_OWNER:CREATE TABLE ownership_probe (probe_id NUMBER PRIMARY KEY);-- As SERVICEHUB_APP:ALTER SESSION SET CURRENT_SCHEMA = servicehub_owner;SELECT SYS_CONTEXT('USERENV','SESSION_USER')   AS session_user,       SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS current_schemaFROM dual;SELECT * FROM ownership_probe;-- Expected: ORA-00942 table or view does not exist (no SELECT privilege).-- Safe repair, as SERVICEHUB_OWNER:GRANT SELECT ON ownership_probe TO servicehub_app;-- Re-run as SERVICEHUB_APP; then cleanup as owner:-- DROP TABLE ownership_probe PURGE;

The important evidence is that SESSION_USER remains SERVICEHUB_APP. The correct repair is an explicit object privilege (or a governed API/view), not a session-name-resolution trick and certainly not a broad SELECT ANY TABLE grant.

6. Hands-on lab: build an ownership and namespace evidence card

Using the existing Free lab, capture one evidence card that another operator could use without guessing. Record the PDB, session user, current schema, the owner of the three ServiceHub base tables, runtime grants, and any private synonyms. Then temporarily set CURRENT_SCHEMA to SERVICEHUB_OWNER and prove that identity remains unchanged.

sql · evidence card
SELECT SYS_CONTEXT('USERENV','CON_NAME') AS con_name,       SYS_CONTEXT('USERENV','SESSION_USER') AS session_user,       SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS current_schemaFROM dual;SELECT owner, object_name, object_typeFROM all_objectsWHERE owner = 'SERVICEHUB_OWNER'AND object_name IN ('SERVICE_REGIONS','TECHNICIANS','WORK_ORDERS')ORDER BY object_name;SELECT owner, table_name, grantee, privilegeFROM all_tab_privsWHERE owner = 'SERVICEHUB_OWNER'AND grantee = 'SERVICEHUB_APP'ORDER BY table_name, privilege;SELECT synonym_name, table_owner, table_nameFROM user_synonymsORDER BY synonym_name;

Verification: you should be able to point to separate evidence for identity, name resolution, ownership, and privilege. If one query is unavailable because your runtime identity cannot see a dictionary view, record that limitation instead of escalating privilege solely for convenience.

7. Production judgment

Prefer explicit ownership and narrow grants as architectural facts. Use synonyms only when they provide a deliberate compatibility or location-transparency boundary, not to hide an unclear privilege model. Treat public synonyms as shared global names that require governance. Avoid quoted mixed-case object names unless interoperability requirements justify the ongoing quoting cost. For deployment tooling, always qualify administrative DDL with the intended owner and verify the current PDB before executing it.

No special 26ai option or management pack is required for these semantics. The key prerequisites are ordinary schema/object privileges in the correct PDB. The lesson does not change COMPATIBLE or initialization parameters.

8. Summary and next step

Oracle ties a user closely to its same-named schema, while session identity, current schema, object ownership, name resolution, synonyms, and privileges remain distinct mechanisms. You can now explain why changing CURRENT_SCHEMA does not grant access and why a synonym cannot replace authorization. Lesson 2 moves from object names to the type system that gives each column its storage and comparison semantics.

Check your understanding

  1. Why can CURRENT_SCHEMA differ from SESSION_USER?
  2. Does a synonym grant SELECT on its target table?
  3. Why is "Work_Orders" riskier operationally than unquoted WORK_ORDERS?
  4. Can a table and an index in one schema have the same name?
  5. What is the safe repair when changing CURRENT_SCHEMA still gives ORA-00942?
Review the answers

CURRENT_SCHEMA controls the default schema used for name resolution; SESSION_USER identifies the authenticated session user. Changing one does not log in as the other.

No. A synonym is an alias. The session still needs the appropriate privilege on the underlying object.

Quoted identifiers preserve case and must be referenced exactly, which increases migration, tooling, and ORM compatibility obligations.

Yes. Tables and indexes use different namespaces. A table and sequence cannot share a name because those object types share a namespace.

Grant the specific required object privilege or expose an approved API/view; do not escalate to broad ANY privileges merely to make unqualified SQL work.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.