简体   繁体   English

Oracle:将子选择转换为流水线函数?

[英]Oracle: Translate subselect into pipelined function?

How do I generically translate a subselect into a pipelined function call? 我一般如何将子选择转换为流水线函数调用?

For example how would I translate this: 例如,我将如何翻译:

select id, stuff from t1 where id in (select unique id from kw where k = 'foo')

to this: 对此:

select id, stuff from t1 where id in (select id from table(has_kw('foo'))

Writing the pipelined table function is relatively straightforward 编写流水线表函数相对简单

CREATE TYPE num_tbl AS TABLE OF NUMBER;

CREATE FUNCTION has_kw( p_k IN VARCHAR2 )
  RETURN num_tbl
  PIPELINED
IS
BEGIN
  FOR i IN (SELECT DISTINCT id FROM kw WHERE k = p_k)
  LOOP
    PIPE ROW( i.id );
  END LOOP;
  RETURN;
END;

Now, I'm not sure that it would really make a whole lot of sense to use a pipeliend table function here. 现在,我不确定在这里使用pipeliend表函数是否真的有意义。 But perhaps your actual use case is more complicated and a pipelined table function would be more appropriate. 但是,也许您的实际用例更加复杂,而流水线表函数会更合适。

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

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