无法从数组中删除元素

时间:2018-06-01 09:41:18

标签: oracle plsql varray

PLS-00306:调用' DELETE'

时参数的数量或类型错误
create or replace PACKAGE BODY MYPACKAGE AS

    PROCEDURE LeaveDates4 
    (
        I_STDATE  IN  DATE,
        I_ENDDATE IN  DATE,
        O_DATES   OUT DateArray 
    )
    AS 
        n INTEGER := LEAST( I_ENDDATE - I_STDATE, 29 );
        just_date DATE;
        H_dates DateArray;
        --cursor cur_holidates is select HOLIDAY_DATE from TSL_HOLIDAYLIST;
        x number;
    BEGIN
        select count(*) into x from TSL_HOLIDAYLIST;

        O_DATES := DateArray();
        H_dates := DateArray();
        O_DATES.EXTEND( n + 1 );
        --  h_dates.extend;
        dbms_output.put_line(n);
        dbms_output.put_line(x);

        FOR i IN 0 .. n LOOP
            O_DATES(i+1) := I_STDATE + i;
            dbms_output.put_line(I_STDATE + i);
        END LOOP;

        for cur in (select HOLIDAY_DATE from TSL_HOLIDAYLIST)
        loop
            h_dates.extend;
            h_dates(h_dates.last):= cur.HOLIDAY_DATE;
        end loop;

        FOR i IN h_DATES.first..h_DATES.last LOOP             
            dbms_output.put_line(h_DATES(i)||i);
        END LOOP;

        for i in O_DATES.first..O_DATES.last LOOP      
            FOR j IN h_DATES.first..h_DATES.last LOOP  
                if o_dates(i)=h_dates(j)
                    then o_dates.delete(i);  -- PLS-00306 error here
                end if;
            end loop;
        end loop;
    END LeaveDates4;

END MYPACKAGE;

以上代码失败,o_dates.delete(i);出现错误 我想从o_dates中删除日期,如果它存在于h_dates中。 我得到的错误是:

PLS-00306: wrong number or types of arguments in call to 'DELETE'

1 个答案:

答案 0 :(得分:2)

您无法从varray的中间删除元素。

PL/SQL Language Reference: PL/SQL Collections and Records: DELETE Collection Method

更简单的示例,定义varray和嵌套表集合:

create or replace type date_varray as varray(3) of date;

create or replace type date_ntab as table of date;

现在声明每种类型的集合并尝试从中删除元素。

嵌套表:

declare
    my_ntable date_ntab := date_ntab(sysdate -1, sysdate, sysdate +1);
begin
    my_ntable.delete(2);
end;

PL/SQL procedure successfully completed.

VARRAY:

declare
    my_varray date_varray := date_varray(sysdate -1, sysdate, sysdate +1);
begin
    my_varray.delete(2);
end;

    my_varray.delete(2);
    *
ERROR at line 4:
ORA-06550: line 4, column 5:
PLS-00306: wrong number or types of arguments in call to 'DELETE'
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored