Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle exporting SQL of the Database structure

Tags:

sql

oracle

I want to create an sql script that can recreate a DB that I already have. I want to recreate the DB without data inside.

So is there anyway with sqlplus of exporting a DB of a user?

like image 676
Kerby82 Avatar asked Jul 07 '10 08:07

Kerby82


1 Answers

From this blog post, it looks like there is a package called dbms_metadata that can generate create table SQL. Example:

 set pagesize 0
 set long 90000
 set feedback off

 set echo off 
 spool filename.sql 
 connect username/password;
 SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
     FROM USER_TABLES u;
 SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name)
     FROM USER_INDEXES u;
 spool off;
like image 193
Andomar Avatar answered Nov 15 '22 03:11

Andomar