通过数据库链接调用 oracle 中的存储函数(返回用户定义类型的数组)

发布于 2024-12-02 06:51:40 字数 487 浏览 3 评论 0原文

通常,我这样调用我的函数:

SELECT * 
FROM TABLE(
  package_name.function(parameters)
)

我尝试通过数据库链接调用此函数。我的直觉是以下是正确的语法,但我还没有让它工作:

SELECT * 
FROM TABLE(
  package_name.function@DBLINK(parameters)
)

> ORA-00904: "PACKAGE_NAME"."FUNCTION": invalid identifier

我尝试移动数据库链接但没有效果。我尝试将其放在参数列表之后、最后一个括号之后、包名称之后...我还尝试了所有上述排列,包括包名称之前的架构名称。我已经没有主意了。

这是甲骨文10g。我怀疑问题可能是函数的返回类型未在我调用它的模式中定义,但我觉得如果是这种情况,我应该会收到不同的错误。

感谢您的帮助!

Normally, I call my function like so:

SELECT * 
FROM TABLE(
  package_name.function(parameters)
)

I'm trying to call this function across a database link. My intuition is that the following is the correct syntax, but I haven't gotten it to work:

SELECT * 
FROM TABLE(
  package_name.function@DBLINK(parameters)
)

> ORA-00904: "PACKAGE_NAME"."FUNCTION": invalid identifier

I've tried moving around the database link to no effect. I've tried putting it after the parameter list, after the last parenthesis, after the package name...I've also tried all of the above permutations including the schema name before the package name. I'm running out of ideas.

This is oracle 10g. I'm suspicious that the issue may be that the return type of the function is not defined in the schema in which I'm calling it, but I feel like I should be getting a different error if that were the case.

Thanks for your help!

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

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

发布评论

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

评论(1

吻安 2024-12-09 06:51:40

据我所知,您正在尝试的是正确的语法,但无论如何,正如您怀疑的那样,由于返回类型是用户定义的,因此它不会工作。

这是一个带有内置管道函数的示例。当然,在本地调用它是可行的:

SELECT * FROM TABLE(dbms_xplan.display_cursor('a',1,'ALL'));

返回:

SQL_ID: a, child number: 1 cannot be found 

通过数据库链接调用它:

SELECT * FROM TABLE(dbms_xplan.display_cursor@core('a',1,'ALL'));

失败并出现此错误:

ORA-30626: function/procedure parameters of remote object types are not supported

可能您会收到 ORA-904,因为该链接转到无法访问该包的特定模式。但无论如何,即使您在本地模式中定义了具有相同名称的相同类型,这也是行不通的,因为从 Oracle 的角度来看,它们仍然不是同一类型。

您当然可以远程查询视图,因此,如果存在一组明确定义的可能参数,您可以为每个参数组合创建一个视图,然后查询该视图,例如:

CREATE VIEW display_cursor_a_1_all AS
  SELECT * FROM TABLE(dbms_xplan.display_cursor('a',1,'ALL'))
  ;

如果可能的参数值的范围太大,您可以可以创建一个过程,在给定任何参数集的情况下动态创建所需的视图。然后,每次要执行查询时,您都会有一个两步过程:

EXECUTE  package.create_view@remote(parameters)

SELECT * FROM created_view@remote;

您必须考虑多个会话是否可以并行调用此查询,如果可以,如何防止它们互相干扰。

What you're trying is the correct syntax as far as I know, but in any case it would not work due to the return type being user-defined, as you suspect.

Here's an example with a built-in pipelined function. Calling it locally works, of course:

SELECT * FROM TABLE(dbms_xplan.display_cursor('a',1,'ALL'));

Returns:

SQL_ID: a, child number: 1 cannot be found 

Calling it over a database link:

SELECT * FROM TABLE(dbms_xplan.display_cursor@core('a',1,'ALL'));

fails with this error:

ORA-30626: function/procedure parameters of remote object types are not supported

Possibly you are getting the ORA-904 because the link goes to a specific schema that does not have access to the package. But in any case, this won't work, even if you define an identical type with the same name in your local schema, because they're still not the same type from Oracle's point of view.

You can of course query a view remotely, so if there is a well-defined set of possible parameters, you could create one view for each parameter combination and then query that, e.g.:

CREATE VIEW display_cursor_a_1_all AS
  SELECT * FROM TABLE(dbms_xplan.display_cursor('a',1,'ALL'))
  ;

If the range of possible parameter values is too large, you could create a procedure that creates the needed view dynamically given any set of parameters. Then you have a two-step process every time you want to execute the query:

EXECUTE  package.create_view@remote(parameters)

SELECT * FROM created_view@remote;

You have to then think about whether multiple sessions might call this in parallel and if so how to prevent them from stepping on each other.

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