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

Oracle: Translate subselect into pipelined function?

如何将子选择一般地转换为流水线函数调用?

例如,我将如何翻译:

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

对此:

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

编写流水线 table 函数相对简单

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;

现在,我不确定在这里使用 pipeliend table 函数是否真的有意义。但也许您的实际用例更复杂,流水线 table 函数会更合适。