0

我有一个如下程序:

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但无法获得正确的语法,如何做到这一点?

4

1 回答 1

0

如果集合类型是在 中声明的schema level,它可以被使用SQL statements或动态地使用。所以请执行以下步骤来完成这项工作。

  1. 创建或替换类型 list_of_names 作为对象(emp_index NUMBER);

  2. 创建或替换类型 list_of_names_t 是 list_of_names 的表;

  3. 创建您的匿名块,如下所示:

    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;
    
于 2013-01-09T08:53:47.770 回答