Number型数组declare
  stmt varchar2(200);
  dept_no_array dbms_sql.Number_Table;
  c number;
  dummy number;
begin
  dept_no_array(1) := 10; dept_no_array(2) := 20;
  dept_no_array(3) := 30; dept_no_array(4) := 40;
  dept_no_array(5) := 30; dept_no_array(6) := 40;
  stmt := 'delete from emp where deptno = :dept_array';
  c := dbms_sql.open_cursor;
  dbms_sql.parse(c, stmt, dbms_sql.native);
  dbms_sql.bind_array(c, ':dept_array', dept_no_array, 1, 4);
  dummy := dbms_sql.execute(c);
  dbms_sql.close_cursor(c);   exception when others then
    if dbms_sql.is_open(c) then
      dbms_sql.close_cursor(c);
    end if;
    raise;
end;

解决方案 »

  1.   

    DECLARE
      -- Define a VARRAY type.
      TYPE Numbers IS VARRAY(20) OF NUMBER(3);  -- Declare a NULL varray.
      v_NullList Numbers;  -- This varray has 2 elements.
      v_List1 Numbers := Numbers(1, 2);  -- This varray has one element, which itself is NULL.
      v_List2 Numbers := Numbers(NULL);
    BEGIN
      IF v_NullList IS NULL THEN
        DBMS_OUTPUT.PUT_LINE('v_NullList is NULL');
      END IF;  IF v_List2(1) IS NULL THEN
        DBMS_OUTPUT.PUT_LINE('v_List2(1) is NULL');
      END IF;
    END;
      

  2.   

    使用数组一定要初始化,数组是oracle内部对象,所以可以创建它供使用CREATE OR REPLACE TYPE NameList AS
      VARRAY(20) OF VARCHAR2(30);
    /DECLARE
      -- This type is local to this block.
      TYPE DateList IS VARRAY(10) OF DATE;  -- We can create variables of both DateList and NameList here.
      v_Dates DateList;
      v_Names NameList;
    BEGIN
      NULL;
    END;
    /DECLARE
      -- Since NameList is global to PL/SQL, we can reference it in
      -- another block as well.
      v_Names2 NameList;
    BEGIN
      NULL;
    END;
    /