Oracle:搜索所有存储的过程/触发器/其他数据库代码?
是否可以跨 Oracle 中的多个模式搜索所有编程对象(函数、存储过程、触发器等)?
我的代码中似乎未使用许多表,但我不想在不先检查的情况下删除它们来破坏任何内容。
Is it possible to search through all of the programmatic objects (functions, stored procedures, triggers, etc) across multiple schemas in Oracle?
There are a number of tables that appear to be unused in my code, but I don't want to break anything by removing them without checking first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可以搜索对象代码——通常使用 DBMS_METADATA 包生成对象的 DDL,然后搜索 CLOB。然而,听起来这并不是您真正想要做的。
如果您只是想弄清楚系统中的任何代码是否引用了某个表,那么您通常需要使用
DBA_DEPENDENCIES
视图(或ALL_DEPENDENCIES
或USER_DEPENDENCIES
取决于您的权限和您要查找的内容的范围)。类似的内容将向您显示依赖于
SCOTT
架构中的EMP
表的所有内容。唯一一次您想要搜索代码而不是查看
DBA_DEPENDENCIES
的情况是当您的代码正在执行动态 SQL(其中表名是硬编码的)时。但这在实践中相对不太可能。It is possible to search through object code-- you'd generally use the DBMS_METADATA package to generate the DDL for the object and then search the CLOB. However, it doesn't sound like that's actually what you want to do.
If you are just trying to figure out whether a table is referenced by any code in your system, you would generally want to use the
DBA_DEPENDENCIES
view (orALL_DEPENDENCIES
orUSER_DEPENDENCIES
depending on your privileges and the scope of what you're looking for). Something likewill show you everything that depends on the
EMP
table in theSCOTT
schema.The only time you'd want to search code rather than looking at
DBA_DEPENDENCIES
would be when you had code that was doing dynamic SQL where the table name was hard-coded. But that's relatively unlikely in practice.您可以搜索 DBA_SOURCE 视图:
You can search the DBA_SOURCE view:
在 Toad 中执行此操作,方法是选择:
搜索 =>对象搜索
Do this in Toad by selecting:
Search => Object Search
如果您有 Toad 您可以内置此操作。 (出于隐私考虑,我删除了我的架构)
If you had Toad you could do this built-in. (I removed my schemas for privacy)