← Users & Privileges
Oracle · Users & Privileges

How to get the CREATE USER DDL for all users in Oracle

Extract the basic CREATE USER DDL for every Oracle user using DBMS_METADATA and spool it to a file.

Tested on11g12c18c19c21c23ai26ai

Dump the CREATE USER statement for every user in DBA_USERS to a local file (ddl_users.sql). This is the basic user-creation DDL only — for a full user recreation script including quotas, roles, and privileges, use get-user-ddl per user.

SET HEADING OFF
SET ECHO OFF
SET PAGES 2000
SET LONG 99999
SET LINES 2000
SET TRIMSPOOL ON

SPOOL ddl_users.sql

SELECT DBMS_METADATA.GET_DDL('USER', username)
FROM   dba_users;

SPOOL OFF
usersddldbms_metadata