Sub topic 8
Verifying Your Environment with a Few Queries
This chapter assumes you know basic SELECT, INSERT, and CREATE TABLE statements. You should also have access to one Oracle practice environment: a local 26ai Free container, an Always Free Autonomous Database, or FreeSQL in a browser.
A connection can succeed while still pointing to the wrong database, pluggable database, schema, or service. Verification queries make those details visible before you create tables or run a longer script.
What to verify
Check these facts:
- The database and container you reached.
- The user that owns your session.
- The current schema used for unqualified object names.
- The database version and release.
- Whether your user can create and query objects.
- Whether changes survive a commit and a new connection.
Oracle uses a multitenant model. A container database, or CDB, can contain one or more pluggable databases, or PDBs. A PDB is the database area where application objects normally live. For a local Free installation, FREEPDB1 is the usual practice PDB. Autonomous Database and FreeSQL hide much of this administration, but the same session checks still help.
Inspect the current session
Run this query in the SQL worksheet, SQL*Plus, SQLcl, or another Oracle client:
SELECT
sys_context('USERENV', 'DB_NAME') AS database_name,
sys_context('USERENV', 'CON_NAME') AS container_name,
sys_context('USERENV', 'SERVICE_NAME') AS service_name,
sys_context('USERENV', 'SESSION_USER') AS session_user,
sys_context('USERENV', 'CURRENT_SCHEMA') AS current_schema
FROM dual;SYS_CONTEXT returns information about the current session. DUAL is Oracle's built-in one-row table, so it is useful when you want to evaluate expressions without reading application data.
For a local connection such as localhost:1521/FREEPDB1, the container should normally be FREEPDB1. The session user should be the account you used to connect. If you connected as SYS, the session user will be SYS, even if the current schema has been changed separately.
The service name identifies the connection endpoint. It is especially useful when a host exposes several services that lead to different containers.
flowchart TD
A[Client connects with host, port, and service] --> B[Oracle listener]
B --> C[Database service]
C --> D[Container or PDB]
D --> E[Session user and current schema]
E --> F[SQL statements resolve to objects]Check the database version
Use this query to identify the server release:
SELECT banner
FROM v$version
WHERE banner LIKE 'Oracle Database%';This view is commonly readable by ordinary users. If your account cannot query it, use the simpler product context instead:
SELECT
sys_context('USERENV', 'DB_NAME') AS database_name,
sys_context('USERENV', 'CON_NAME') AS container_name
FROM dual;The version check tells you what Oracle features and syntax may be available. It does not prove that your account has permission to use every feature. Privileges are checked separately when you perform an operation.
Test object creation and data changes
A small table test checks DDL, or data definition language, and DML, or data manipulation language. DDL creates database objects. DML inserts, updates, deletes, or reads rows.
Run the following as your development user:
CREATE TABLE practice_note (
id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
body VARCHAR2(200) NOT NULL
);
INSERT INTO practice_note (body)
VALUES ('Hello from my practice database');
COMMIT;
SELECT id, body
FROM practice_note
ORDER BY id;The CREATE TABLE statement tests your ability to create an object. The INSERT tests your ability to add data. COMMIT makes the transaction permanent within the database. The final query confirms that the row can be read.
To confirm which schema owns the table, query the data dictionary:
SELECT owner, object_name, object_type
FROM user_objects
WHERE object_name = 'PRACTICE_NOTE';USER_OBJECTS lists objects owned by the current user. Oracle stores unquoted object names in uppercase, which is why the filter uses 'PRACTICE_NOTE'.
If the table already exists, either query it or remove it before repeating the test:
DROP TABLE practice_note PURGE;Use PURGE only for a disposable practice table. It skips the recycle bin and makes recovery harder.
Common verification errors
| Symptom | Likely cause | What to check |
|---|---|---|
| `ORA-00942: table or view does not exist` | The table is in another schema or was never created | Check `CURRENT_SCHEMA` and `USER_OBJECTS` |
| `ORA-01031: insufficient privileges` | The account lacks a required privilege | Connect with the intended development user and review its grants |
| `ORA-01950: no privileges on tablespace` | The user has no space quota | Grant a quota to the user or use the environment's supported setup |
| `ORA-00001: unique constraint violated` | The test inserted a duplicate key | Query existing rows before inserting again |
| `ORA-00955: name is already used` | The test table already exists | Query it or drop the disposable table |
Exercise
Exercise
Your session query reports CON_NAME = CDB$ROOT, but you expected to work in FREEPDB1. What should you check first?
Show answer
Check the connection's service name. Reconnect using the FREEPDB1 service, such as localhost:1521/FREEPDB1, then run the session query again.