使用 ADO.NET 获取 Oracle 包中过程的存储过程元数据

发布于 2024-09-02 03:51:04 字数 380 浏览 5 评论 0原文

我正在尝试使用标准 ADO.NET API - DbConnection.GetSchema 调用获取 Oracle 包中声明的过程的存储过程元数据(过程名称、参数类型、参数名称等)。我正在使用 ODP 驱动程序。

我看到该包列在“Packages”和“PackageBodies”元数据集合中。过程参数出现在“Arguments”和“ProcedureParameters”集合中。我没有找到通过包元数据获取过程信息的方法。即使该过程没有任何参数,“ProcedureParameters”集合中也会有该过程的一行。

我的问题:要获取过程元数据,我是否必须查询“ProcedureParameters”集合并搜索具有所需包名称的条目?然后我可以根据参数信息构建过程元数据。有没有更短或更快的方法来获取相同的信息?

I am trying to obtain the stored procedure metadata (procedure name,parameter types,parameter names etc) for a procedure declared within an Oracle package, using the standard ADO.NET API - DbConnection.GetSchema call. I am using the ODP driver.

I see that the Package is listed in the 'Packages' and 'PackageBodies' metadata collections. The procedure parameter appears in the 'Arguments' and 'ProcedureParameters' collections. I do not see a way to get to the procedure information via the package metadata. Even if the procedure does not have any parameters there is a row in the 'ProcedureParameters' collection for this procedure.

My question: To obtain the procedure metadata do I have to query the 'ProcedureParameters' collection and search for an entry with the required package name? I can then construct the procedure metadata based on the parameter information. Is there a shorter or quicker way to obtain the same information?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

输什么也不输骨气 2024-09-09 03:51:04

我不确定如何使用 ADO.NET 获得此信息,但您可以直接查询数据库来获取此信息,如下所示:

SELECT *
  FROM SYS.DBA_PROCEDURES
  WHERE OBJECT_TYPE = 'PACKAGE' AND
        OBJECT_NAME = '<your package name here>' AND
        PROCEDURE_NAME IS NOT NULL;

运行上述查询后,您将获得一个结果集,其中包括事物,PROCEDURE_NAME。给定包名称和 PROCEDURE_NAME,您可以使用以下查询查找参数信息:

SELECT *
  FROM SYS.ALL_ARGUMENTS
  WHERE PACKAGE_NAME = '<your package name here>' AND
        OBJECT_NAME = '<PROCEDURE_NAME from query above>';

分享并享受。

I'm not sure how you'd get this using ADO.NET, but you can directly query the database to get this information as follows:

SELECT *
  FROM SYS.DBA_PROCEDURES
  WHERE OBJECT_TYPE = 'PACKAGE' AND
        OBJECT_NAME = '<your package name here>' AND
        PROCEDURE_NAME IS NOT NULL;

Once you've run the above query you'll have a result set which has, among other things, the PROCEDURE_NAME. Given the package name and the PROCEDURE_NAME, you can find parameter info using the following query:

SELECT *
  FROM SYS.ALL_ARGUMENTS
  WHERE PACKAGE_NAME = '<your package name here>' AND
        OBJECT_NAME = '<PROCEDURE_NAME from query above>';

Share and enjoy.

风月客 2024-09-09 03:51:04

在 Bob 的帮助下,我使用以下查询来获取包中定义的存储过程的列表。

SELECT a.OBJECT_NAME,p.PROCEDURE_NAME FROM SYS.ALL_OBJECTS a, SYS.ALL_PROCEDURES p WHERE a.OBJECT_NAME = p.OBJECT_NAME AND a.OBJECT_TYPE = 'PACKAGE' AND a.OWNER = '" + ownerName + "' AND p.PROCEDURE_NAME IS NOT NULL"

这将返回特定用户的所有存储过程。然后我可以使用“ProcedureParameters”集合来获取它们的参数信息。

注意:不要查询 SYS.DBA_PROCEDURES 表。用于执行查询的用户凭据可能不具有该表的“选择”权限。

With help from Bob I've used the following query to obtain a list of stored procedures defined within a package.

SELECT a.OBJECT_NAME,p.PROCEDURE_NAME FROM SYS.ALL_OBJECTS a, SYS.ALL_PROCEDURES p WHERE a.OBJECT_NAME = p.OBJECT_NAME AND a.OBJECT_TYPE = 'PACKAGE' AND a.OWNER = '" + ownerName + "' AND p.PROCEDURE_NAME IS NOT NULL"

This returns all stored procedures for a particular user. I can then use the 'ProcedureParameters' collection to obtain the parameter information for them.

NOTE: Do not query the SYS.DBA_PROCEDURES table. The user credentials you use to execute the query might not have 'select' privileges on that table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文