简体   繁体   English

Oracle-将存储过程复制到远程数据库

[英]Oracle - copying stored procedures to remote database

An assignment I have as part of my pl/sql studies requires me to create a remote database connection and copy down all my tables to it from local, and then also copy my other objects that reference data, so my views and triggers etc. 作为我的pl / sql学习的一部分,我需要进行的一项作业是创建一个远程数据库连接,并从本地将所有表复制到该表中,然后还复制其他引用数据的对象,因此我的视图和触发器也是如此。

The idea is that at the remote end, the views etc should reference the local tables provided the local database is online, and if it is not, then they should reference the tables stored on the remote database. 想法是,在远程端,如果本地数据库在线,则视图等应引用本地表;如果本地数据库不在线,则它们应引用存储在远程数据库中的表。

So I've created a connection, and a script that creates the tables at the remote end. 因此,我创建了一个连接,并创建了一个在远端创建表的脚本。

I've also made a pl/sql block to create all the views and triggers at the remote end, whereby a simple select query is run against the local database to check if it is online, if it is online then a series of execute immediate statements creates the views etc with reference to table_name@local, and if it isn't online the block skips to the exception section, where a similar series of execute immediate statements creates the same views but referencing the remote tables. 我还制作了一个pl / sql块来在远程端创建所有视图和触发器,从而对本地数据库运行一个简单的select查询,以检查它是否在线,是否在线,然后执行一系列立即执行。语句创建引用table_name @ local的视图等,如果不在线,则该块跳至异常部分,在该段中类似的一系列execute立即语句创建相同的视图,但引用远程表。

OK so this is where I become unsure. 好的,这就是我不确定的地方。 I have a package that contains a few procedures and a function, and I'm not sure what's the best way to create that at the remote end so that it behaves in a similar way in terms of where it picks up its reference tables from. 我有一个包含一些过程和函数的程序包,但我不确定在远程端创建该程序包的最佳方法是什么,以便它在从何处获取其引用表的行为类似。

Is it simply a case of enclosing the whole package-creating block within an 'execute immediate', in the same way as I did for the views, or should I create two different packages and call them something like pack1 and pack1_remote? 这仅仅是将整个程序包创建块包含在“立即执行”中的一种情况,就像我对视图所做的一样,还是应该创建两个不同的程序包并命名为pack1和pack1_remote之类的东西?

Or is there as I suspect a more efficient method of achieving the goal? 还是我怀疑有更有效的方法实现目标?

cheers! 干杯!

This is absolutely not how any reasonable person in the real world would design a system. 这绝对不是现实世界中任何有理智的人设计系统的方式。 Suggesting something like what I suggest here in the real world will, in the best case, get you laughed out of the room. 在最好的情况下,建议像我在现实世界中建议的那样会使您大笑。

The least insane approach I could envision would be to have two different schemas. 我可以设想的最疯狂的方法是拥有两个不同的模式。 Schema 1 would own the tables. 模式1将拥有这些表。 Schema 2 would own the code. 模式2将拥有代码。 At install time, create synonyms for every object that schema 2 needs to reference. 在安装时,为模式2需要引用的每个对象创建同义词。 If the remote database is available when the code is installed, create synonyms that refer to objects in the remote database. 如果在安装代码后远程数据库可用,则创建引用远程数据库中对象的同义词。 Otherwise, create synonyms that refer to objects in the local database. 否则,请创建引用本地数据库中对象的同义词。 That lets you create a single set of objects without using dynamic SQL by creating an extra layer of indirection between your code and your tables. 这样,您可以通过在代码和表之间创建额外的间接层来创建一组对象,而无需使用动态SQL。

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

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