How can I get the create table command which is used to create a table in oracle 11g so that I can copy the command and run it in another database? Please help.
3 Answers
select dbms_metadata.get_ddl('TABLE', 'YOUR_TABLE_NAME_GOES_HERE')
from dual;
1 Comment
Yogamurthy
This query worked. you saved me from a 4 hour search.
Try to spool the output of the below query,
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
FROM USER_TABLES u;
Like,
set pagesize 0
set long 90000
set feedback off
set echo off
spool schema.sql
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
FROM USER_TABLES u WHERE TABLE_NAME = '<your_table>';
spool off;
Reference: http://www.dba-oracle.com/oracle_tips_dbms_metadata.htm
Comments
Please use the below Query
select dbms_metadata.get_ddl('TABLE','YOUR_TABLE_NAME','YOUR_SCHEMA_NAME') from dual;
if you use SQL Developer, select the table name , and right click to choose Open Declaration and then Click SQL tab on the window that opens!

1 Comment
Yogamurthy
nice info to add to this question