当函数和过程 body/ddl 位于包中时,如何读取它们?
任务:
将包中的所有函数和过程移至当前 Oracle 模式。 (你可以想象一个你可能需要的情况,如果没有的话——把它当作一个挑战!)
问题:
当函数/过程“主体”在包中时,我如何读取它们?我知道我可以使用 all_source
、dba_source
等来获取包体行,但这意味着我必须解析所有这些行/字符串 - 它应该是更简单的方法。不是吗?
TASK:
Move all the functions and procedures in packages to the current Oracle schema. (you can imagine a case when you could need that, if not - take it like a challenge!)
QUESTION:
How can I read the functions/procedure "body" while they are in the package? I know that I can use all_source
, dba_source
and others to get the package body lines, but this means that I have to parse all those rows/strings - it should be an easier way. Isn't it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以使用 Toad,它会做得很好。
另外,请查看
DBMS_METADATA 包
,特别是GET_DDL
过程。希望有帮助。
If you have access to Toad, it does this very well.
Also, look at
DBMS_METADATA package
, specifically, theGET_DDL
procedure.Hope that helps.
为什么你需要这个?
您是否只是想执行函数和过程,就好像它们是在您的架构中定义的一样?如果是这样,则调用者的权限可能有帮助。
你这样做是为了测试吗?如果是这样,请看一下这个答案:有没有办法访问私有 plsql 过程以进行测试?(摘要:使用条件编译可选择将函数和过程公开)
如果您确实需要将包分解为您需要的函数和过程要做如果您想 100% 准确,请手动进行。
仅阅读源代码并尝试自动执行会存在许多潜在问题。包变量、类型、初始化、安全性(每个函数都可以是公共的吗?)、过程中的过程、重复名称、包装源等又如何呢?
Why exactly do you need this?
Are you just trying to execute the functions and procedures as if they were defined in your schema? If so, then invoker's rights may help.
Are you doing this for testing? If so, take a look at this answer: Is there a way to access private plsql procedures for testing purposes? (summary: use conditional compilation to optionally make functions and procedures public)
If you really need to break the packages down to functions and procedures you'll need to do it manually if you want to be 100% accurate.
There are many potential problems with just reading the source and trying to do it automatically. What about package variables, types, initialization, security (can every function be public?), procedures within procedures, duplicate names, wrapped source, etc.