Salvadore Rina
Salvadore Rina

Reputation: 609

how to get the query used for creating a table in Oracle

I'm new to Oracle and learning about tables using the HR db, i wanted to ask does there exist any command to view the query used to create the predefined tables? (I am not talking about the Desc/ribe command). Thanks in advance

Upvotes: 1

Views: 1358

Answers (2)

thatjeffsmith
thatjeffsmith

Reputation: 22467

There is a client-side command, if you're using SQLcl or SQL Developer

ddl *table_name*

enter image description here

I talk more about it here

Upvotes: 1

GMB
GMB

Reputation: 222682

You can use the getddl() function from the dbms_metadata package.

As an example, the following query gives you the DDL for table mytable in schema HR:

select dbms_metadata.get_ddl('TABLE','MYTABLE','HR') from dual;

If you want the information for all tables in the HR schema at once, you can do:

select table_name, dbms_metadata.get_ddl('TABLE', table_name, owner) 
from all_tables 
where owner = 'HR';

Upvotes: 3

Related Questions