如何将子选择一般转换为流水线函数调用?
例如,我将如何翻译:
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'))
答案 0 :(得分:4)
编写流水线表函数相对简单
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表函数真的很有意义。但也许您的实际用例更复杂,并且流水线表函数更合适。