简体   繁体   English

Oracle跳过了嵌套的PIPELINED函数

[英]Nested PIPELINED function is skipped by Oracle

I'll post a trivial example, which actually works, just to get an approximate picture of what I'm trying to achieve: 我将发布一个简单的示例,该示例实际上是有效的,只是为了大致了解我要实现的目标:

Here is the 'inner' function which takes the data from some table, called test_tab : 这是“内部”函数,该函数从某个表中获取数据,该表称为test_tab

create or replace function test_inner RETURN num_typ PIPELINED
IS
BEGIN
  FOR cur in (
    SELECT x FROM test_tab
  )
  LOOP
    PIPE ROW(cur.x);
  END LOOP;
END;
/

Here is the 'outer' function which uses the result of inner function and transforms them appropriately: 这是“外部”函数,它使用inner函数的结果并对它们进行适当的转换:

create or replace function test_outer RETURN num_typ PIPELINED
IS
BEGIN
  FOR x IN (
    SELECT * FROM table(test_inner())
  )
  LOOP
    PIPE ROW(x.column_value * 2);
  END LOOP;
END;
/

And here is how I use it: 这是我的用法:

begin
  execute immediate 'insert into test_tab(x) values(1)';
  execute immediate 'insert into test_tab(x) values(2)';
  execute immediate 'insert into test_tab(x) values(3)';

  FOR x IN (
    select * from table(test_outer())
  ) LOOP  
    DBMS_OUTPUT.put_line(x.column_value);
  END LOOP;  
end;
/

The problem is that test_inner function seems to be ignored by Oracle. 问题是test_inner函数似乎被Oracle忽略了。 When it is called separately, it 'sees' the data inserted prior to its execution. 当单独调用它时,它“看到”在执行之前插入的数据。 But when it's called as a part of test_outer it doesn't return any data, or maybe doesn't get called at all. 但是当它作为test_outer的一部分被调用时,它不会返回任何数据,或者根本不会被调用。

Like I said, the above example will work. 就像我说的那样,上面的示例将起作用。 But my case is a little bit more complex, so I can't post it entirely. 但是我的情况有点复杂,所以我不能完全发表。

The test case you have posted does not reproduce the problem you claim to be seeing. 您发布的测试用例无法重现您声称看到的问题。 So it is not a test case. 因此,这不是测试用例。

@AlexPoole has provided you with some other ideas. @AlexPoole还为您提供了其他一些想法。 Basically there is nothing further we can do unless you can post a better test case, given that you cannot post the entire things (and we don't want to go through hundreds of lines of somebody else's shonky code - I for one get enough of that debugging my own stuff). 基本上,除非您不能发布更好的测试用例,否则我们将无能为力,因为您无法发布全部内容(而且我们不想遍历数百行其他人的拙劣代码-我只想得到足够多的内容)调试我自己的东西)。

Producing a poor test case has not been a waste of time. 产生一个不良的测试案例并没有浪费时间。 At least you can rule out certain things: it's nothing to do with one pipelined function calling another. 至少您可以排除某些情况:与一个管道函数调用另一个无关。 So it's clearly something in your specific implementation. 因此,这显然是您特定实现中的东西。 Perhaps not in the internal function logic, but how they are called, the data they work with or some other part of the infrastructure. 也许不是内部函数逻辑中的内容,而是它们的调用方式,与它们一起使用的数据或基础结构的其他部分。

All you can do is analyse the individual parts. 您所要做的就是分析各个部分。 Start with the core component, and build out, adding other components until you find the bit which breaks. 从核心组件开始,然后进行扩展,添加其他组件,直到发现有问题的地方。 Yes this is a tedious chore. 是的,这是一件繁琐的工作。 But from your comments it sounds like you're quite a way through this process already. 但是从您的评论看来,您已经很完整地完成了此过程。


I'm marking this CW as it isn't an answer to the question, just an extended comment. 我将其标记为CW,因为它不是问题的答案,只是扩展的注释。

Your both pipelined functions in fact are syntactic wrong: you are missing RETURN 实际上,这两个流水线函数在语法上都是错误的:您缺少RETURN

See docs 查看文件

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

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