| Lesson 10 | Oracle DESCRIBE Command |
| Objective | Use SQL*Plus (and compatible tools) to inspect object definitions, and know when to query the data dictionary or use DBMS_METADATA. |
DESCRIBE (abbrev. DESC) is a client command in SQL*Plus/SQLcl (and supported by many Oracle IDEs) that prints the structure of an object: tables, views, synonyms, sequences, types, procedures/functions, and package specs. It is not a SQL statement executed by the optimizer—it’s a convenience feature of your client.
You’ll typically pair DESC with data-dictionary queries (USER_/ALL_/DBA_* views) and, when you need full DDL, DBMS_METADATA.GET_DDL. This page shows accurate usage patterns, common pitfalls, and production-ready snippets.
-- General form
DESC[RIBE] [schema.]object[@dblink]
\-- Examples
DESC employees
DESC hr.employees
DESC user\_tab\_privs
DESC SYS.DBMS\_LOCK
DESC hr.emp\_pkg -- package spec
DESC hr.emp\_pkg.hire\_employee -- procedure/function in a package
DESC "CaseSensitiveTable" -- quoted identifiers must match case
DESC a synonym, the client resolves the target if you have privilege; otherwise you’ll see an error.SELECT on a table) to see details. For dictionary views you may need roles such as SELECT_CATALOG_ROLE.DESC is client-side; shared vs. dedicated server does not change behavior.DESC hr.employees
-- Output (typical):
-- Name Null? Type
-- -------------- -------- ----------------------------
-- EMPLOYEE_ID NOT NULL NUMBER(6)
-- FIRST_NAME VARCHAR2(20)
-- LAST_NAME NOT NULL VARCHAR2(25)
-- HIRE_DATE NOT NULL DATE
-- ...
DESC hr.emp_pkg.hire_employee
-- Shows argument names, modes (IN/OUT), and datatypes from the package spec.
DESC hr.address_t
-- Lists attributes and their datatypes.
Use dictionary views for filters, joins, and policy-safe reporting. Swap USER_ for ALL_ or DBA_ as needed.
SELECT column_id,
column_name,
data_type ||
COALESCE('(' || data_precision || ',' || data_scale || ')',
CASE WHEN data_length IS NOT NULL AND data_type LIKE '%CHAR%'
THEN '(' || data_length || ')'
END) AS data_type_fmt,
nullable
FROM user_tab_columns
WHERE table_name = 'EMPLOYEES'
ORDER BY column_id;
SELECT c.constraint_name,
LISTAGG(col.column_name, ', ') WITHIN GROUP (ORDER BY col.position) AS columns
FROM user_constraints c
JOIN user_cons_columns col
ON col.constraint_name = c.constraint_name
WHERE c.table_name = 'EMPLOYEES'
AND c.constraint_type IN ('P','U')
GROUP BY c.constraint_name;
SELECT i.index_name,
i.uniqueness,
LISTAGG(ic.column_name, ', ') WITHIN GROUP (ORDER BY ic.column_position) AS columns
FROM user_indexes i
JOIN user_ind_columns ic
ON ic.index_name = i.index_name
WHERE i.table_name = 'EMPLOYEES'
GROUP BY i.index_name, i.uniqueness;
SELECT position,
argument_name,
in_out,
data_type,
data_length,
data_precision,
data_scale
FROM all_arguments
WHERE owner = 'HR'
AND package_name = 'EMP_PKG'
AND object_name = 'HIRE_EMPLOYEE'
ORDER BY position;
SET LONG 100000
SELECT DBMS_METADATA.GET_DDL('TABLE','EMPLOYEES','HR') AS ddl
FROM dual;
If DESC name succeeds but you want to see the target:
SELECT owner, table_name
FROM all_synonyms
WHERE synonym_name = 'EMP'
AND owner IN (USER, 'PUBLIC');
For remote objects, append @dblink if your client supports it and you have privileges:
DESC hr.employees@prod_link
SPOOL describe_employees.lst
DESC hr.employees
SPOOL OFF
Use SPOOL when you need to attach results to a ticket or audit trail.
DESC HR.EMPLOYEES. Check ALL_SYNONYMS.DESC "Employee".HELP in SQL*Plus documents SQL*Plus commands (e.g., HELP SPOOL, HELP DESCRIBE), not full SQL grammar. For SQL semantics use the SQL Language Reference.DESC doesn’t show them; use the dictionary views shown above.DESC for fast inspection (columns, nullability, types).USER_/ALL_/DBA_ views for keys, indexes, grants, and arguments.DBMS_METADATA.GET_DDL for exact DDL.