如何在Oracle中正确定义日期类型的数组?

如何在Oracle中正确定义日期类型的数组?,oracle,types,oracle-sqldeveloper,Oracle,Types,Oracle Sqldeveloper,我想将字符串数组转换为日期类型数组。但我不确定我的日期数组是否定义正确。找不到任何有关如何定义或创建日期类型数组的示例 这就是我声明字符串数组和日期类型数组的方式 create or replace TYPE array_collection IS table OF VARCHAR2(50) --string array is working absolutely fine so dw about that create or replace type date_array is table

我想将字符串数组转换为日期类型数组。但我不确定我的日期数组是否定义正确。找不到任何有关如何定义或创建日期类型数组的示例

这就是我声明字符串数组和日期类型数组的方式

create or replace TYPE array_collection IS table OF VARCHAR2(50) 
--string array is working absolutely fine so dw about that

create or replace type date_array is table of date;
--here i don't if I've defined this array correctly
我的转换数组过程:

create or replace procedure convert_arr(
dat_ar in array_collection,perdate_arr out date_array)
as
begin
perdate_arr:=new date_array();
perdate_arr.extend(dat_ar.count);
for i in 1..dat_ar.count loop
perdate_arr(i):=to_date(dat_ar(i), 'yyyy-mm-dd');
end loop;
end convert_arr;
--compiles perfectly
正在调用匿名块:

set serveroutput on
declare 
--l_dat array_collection;
--l_darray date_array;
l_dat array_collection:=array_collection();
l_darray date_array:=date_array();
begin
l_dat := array_collection('2011-01-01','2011-04-01','2011-05-01');
--l_dat.extend(3);
-- l_dat(1):= to_date(2019-07-08);
-- l_dat(2):= to_date(2019-07-09);
-- l_dat(3):= to_date(2019-06-02);

convert_arr(dat_ar=>l_dat,perdate_arr=>l_darray);
dbms_output.put_line('Number of array:' || l_dat.count);
for i in 1..l_dat.count loop
dbms_output.put_line('Date ' || i || ':' || to_char(l_dat(i),'dd/mm/yyyy'));
end loop;
end;
此块给我一个错误:

Error report -
ORA-01861: literal does not match format string
ORA-06512: at line 9
01861. 00000 -  "literal does not match format string"
*Cause:    Literals in the input must be the same length as literals in
           the format string (with the exception of leading whitespace).  If the
           "FX" modifier has been toggled on, the literal must match exactly,
           with no extra whitespace.
*Action:   Correct the format string to match the literal.

尝试更改格式,但没有帮助。任何帮助都将不胜感激。谢谢你

既然
l\u darray
是你的日期数组,那么就通过它来循环显示,而不是
l\u dat

set serveroutput on
declare 
--l_dat array_collection;
--l_darray date_array;
l_dat array_collection:=array_collection();
l_darray date_array:=date_array();
begin
l_dat := array_collection('2011-01-01','2011-04-01','2011-05-01');
--l_dat.extend(3);
-- l_dat(1):= to_date(2019-07-08);
-- l_dat(2):= to_date(2019-07-09);
-- l_dat(3):= to_date(2019-06-02);

convert_arr(dat_ar=>l_dat,perdate_arr=>l_darray);
dbms_output.put_line('Number of array:' || l_darray.count);
for i in 1..l_darray.count loop
dbms_output.put_line('Date ' || i || ':' || to_char(l_darray(i),'dd/mm/yyyy'));
end loop;
end;
/
结果

Number of array:3
Date 1:01/01/2011
Date 2:01/04/2011
Date 3:01/05/2011


PL/SQL procedure successfully completed.

你确定你发布了最终版本吗?在第17行,即
DBMS\u输出
行,您的代码对我来说失败了。这意味着主代码正在工作,只有显示部分出现故障。将
l_dat(i)
更改为
l_darray(i)
为我修复了它。哦,天哪,我显然没有注意到这一点。非常感谢您的回复。