我如何一般地将子选择转换为流水线函数调用?
例如,我将如何翻译:
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'))
我如何一般地将子选择转换为流水线函数调用?
例如,我将如何翻译:
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'))
编写流水线表函数相对简单
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;
现在,我不确定在这里使用管道表函数是否真的很有意义。但也许您的实际用例更复杂,流水线表函数会更合适。