我有一个如下程序:
SET serveroutput ON
DECLARE
TYPE list_of_names_t
IS TABLE OF emp.emp_index%TYPE;
ignoreIndexes LIST_OF_NAMES_T := List_of_names_t();
BEGIN
-- Logic here which fills the values in the collection ignoreIndexes and considerIndexes
-- Line XX
END;
在第XX行,我想添加以下行
SELECT * FROM emp WHERE emp_index NOT IN ignoreIndexes
但是无法获得正确的语法,如何做到这一点?
答案 0 :(得分:0)
如果集合类型是在schema level
声明的,则可以在SQL statements
中动态使用,也可以动态使用。请执行以下步骤以使其正常工作。
创建或替换类型list_of_names AS OBJECT(emp_index NUMBER);
创建或替换类型list_of_names_t是list_of_names;
创建您的匿名块,如下所示:
SET serveroutput ON
DECLARE
ignoreIndexes LIST_OF_NAMES_T := List_of_names_t();
emp_cur SYS_REFCURSOR;
BEGIN
-- Populate the collection with some data
SELECT list_of_names(LEVEL)
BULK COLLECT INTO ignoreIndexes
FROM dual CONNECT BY LEVEL<21;
OPEN emp_cur FOR
SELECT *
FROM EMP e
WHERE NOT EXISTS(SELECT 1
FROM table(ignoreIndexes) tt
WHERE tt.emp_index = e.emp_index
);
END;