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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:47:58  来源:igfitidea点击:

Oracle exporting SQL of the Database structure

sqloracle

提问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_metadatathat can generate create tableSQL. Example:

这篇博文看来,有一个叫做dbms_metadata可以生成create tableSQL的包。例子:

 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  

Find out more.

了解更多

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 包。这需要做更多的工作,但可以更好地控制导出对象的细节。 了解更多

回答by TTT

You can also use SQL Developer to create sql scripts, as described here.

您还可以使用SQL Developer创建SQL脚本,描述在这里