Oracle 导出数据库结构的 SQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3193289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle exporting SQL of the Database structure
提问by Kerby82
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.
我想创建一个可以重新创建我已经拥有的数据库的 sql 脚本。我想重新创建没有数据的数据库。
So is there anyway with sqlplus of exporting a DB of a user?
那么sqlplus是否有导出用户数据库的功能?
回答by Andomar
From this blog post, it looks like there is a package called dbms_metadata
that can generate create table
SQL. Example:
从这篇博文看来,有一个叫做dbms_metadata
可以生成create table
SQL的包。例子:
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;
回答by APC
There are two basic approaches.
有两种基本方法。
The first is to export a dump file. This can be with the Datapump utility:
第一种是导出转储文件。这可以使用 Datapump 实用程序:
$ expdp apc/pw directory=data_dump_dir dumpfile=apc_20100707.dmp content=METADATA_ONLY
了解更多。
Datapump was introduced in Oracle10g. In earlier versions of the database we could use the EXP utility to do the same thing.
Datapump 是在 Oracle10g 中引入的。在数据库的早期版本中,我们可以使用 EXP 实用程序来做同样的事情。
$ exp apc/pw dumpfile=apc_20100707.dmp rows=N
To import the file we use the matching impdp
(or imp
) utilities.
要导入文件,我们使用匹配impdp
(或imp
)实用程序。
That is the OS approach. To generate actual SQL scripts we can use the built-in DBMS_METADATA package, introduced in Oracle 9i. This is a bit more work but offers much finer control over the details of the exported objects. Find out more.
这就是操作系统方法。要生成实际的 SQL 脚本,我们可以使用 Oracle 9i 中引入的内置 DBMS_METADATA 包。这需要做更多的工作,但可以更好地控制导出对象的细节。 了解更多。