简体   繁体   English

Oracle PL / SQL:复制数据库对象

[英]Oracle PL/SQL : Replicating Database objects

I need replicate database objects from one database to another database. 我需要将数据库对象从一个数据库复制到另一个数据库。 For tables I can do it by 对于桌子我可以做到

CREATE TABLE TBL_USERS AS SELECT * FROM TBL_USERS@DBLINK;

which will copy both the table structure and data. 这将同时复制表结构和数据。

Is there similar way to copy Materialized Views with its underlying SQL codes and procedures/packages? 是否有类似的方法来复制具有其基础SQL代码和过程/包的实例化视图?

Thanks in advance. 提前致谢。

The short answer to this is: No, you cannot replicate PL/SQL procedure, views, trigger, tables, etc. via PL/SQL. 对此的简短答案是:不,您无法通过PL / SQL复制PL / SQL过程,视图,触发器,表等。

There might be tricks around some of this but not everything will replicated. 可能有一些技巧,但并非所有技巧都会复制。 What you describe above is a simple DDL using a Database Link to replicate data. 上面描述的是使用数据库链接复制数据的简单DDL。 It's not PL/SQL as such and it only replicates the table structure and data set itself. 它不是PL / SQL本身,它仅复制表结构和数据集本身。 No constraints, indexes, trigger nor any security properties such as grants are replicated. 不复制约束,索引,触发器或任何安全属性(例如授予)。 There are several ways in Oracle to replicate database objects across multiple databases, one of them being Data Pump Export and Data Pump Import : Oracle中有多种方法可以跨多个数据库复制数据库对象,其中一种是Data Pump ExportData Pump Import

Source DB "GV11202" 源数据库“ GV11202”

SQL> select directory_path from all_directories where directory_name = 'DATA_PUMP_DIR';

DIRECTORY_PATH
--------------------------------------------------------------------------------
/u01/app/oracle/admin/GV11202/dpdump/

bash$ expdp system/system@GV11202 DIRECTORY=DATA_PUMP_DIR DUMPFILE=export.dmp SCHEMAS=test

Target DB "GVENZL" 目标数据库“ GVENZL”

SQL> select directory_path from all_directories where directory_name = 'DATA_PUMP_DIR';

DIRECTORY_PATH
--------------------------------------------------------------------------------
/u01/app/oracle/admin/GVENZL/dpdump/

bash$ cp /u01/app/oracle/admin/GV11202/dpdump/export.dmp /u01/app/oracle/admin/GVENZL/dpdump/

bash$ impdp system/system@GVENZL DIRECTORY=DATA_PUMP_DIR DUMPFILE=export.dmp

Import dump file - as there is only the test schema within the dump file, I can just plainly import the schema with all its objects. 导入转储文件-由于转储文件中只有测试架构,因此我可以简单地将架构及其所有对象导入。 However, if you import into an existing schema where tables might already exist, have a look at the TABLE_EXISTS_ACTION 但是,如果导入表可能已经存在的现有模式,请查看TABLE_EXISTS_ACTION

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM