返回oracle类型返回ora-6530错误的函数执行



我正在尝试创建以下返回Oracle对象类型的函数:

CREATE OR REPLACE FUNCTION FN_FIPERIODDATE
RETURN FIPERIODDATE is
PDS FIPERIODDATE;
begin
select  to_date('1/10/'||substr(pd.value,1,4), 'DD/MM/RRRR'),  
to_date('30/9/'||substr(pd.value,6,4), 'DD/MM/RRRR') into PDS.DATESTART, PDS.DATEEND
from parameterdetails pd inner join PROCESSPERIOD pp on pp.FIPERIODID = pd.id;

return (PDS);
end ;

以下是FIPERIODDATE类型:

CREATE TYPE FIPERIODDATE AS OBJECT (
DATESTART date,  DATEEND date
);

当我尝试执行select FN_FIPERIODDATE from dual;时,我会出现ORA-6530错误,但如果执行select FN_FIPERIODDATE.DATESTART from dual;,则会出现以下错误:

[Error] Execution (21: 8): ORA-06552: PL/SQL: Statement ignored ORA-06553: PLS-225: subprogram or cursor 'FN_FIPERIODDATE' reference is out of scope

知道吗?

缺少了很多东西。

您创建的类型不够:

SQL> create or replace type fiperioddate as object
2    (datestart date, dateend date);
3  /
Type created.
SQL> create or replace type t_fiper as table of fiperioddate;
2  /
Type created.

功能:

SQL> create or replace function fn_fiper
2    return t_fiper
3  is
4    pds t_fiper := t_fiper();
5  begin
6    select fiperioddate(trunc(sysdate), e.hiredate)
7      bulk collect into pds
8      from emp e;
9
10    return pds;
11  end;
12  /
Function created.

它有效吗?

SQL> select * from table(fn_fiper);
DATESTART  DATEEND
---------- ----------
09.10.2020 17.12.1980
09.10.2020 20.02.1981
09.10.2020 22.02.1981
09.10.2020 02.04.1981
09.10.2020 28.09.1981
09.10.2020 01.05.1981
09.10.2020 09.06.1981
09.10.2020 09.12.1982
09.10.2020 17.11.1981
09.10.2020 08.09.1981
09.10.2020 12.01.1983
09.10.2020 03.12.1981
09.10.2020 03.12.1981
09.10.2020 23.01.1982
14 rows selected.
SQL>

是的,确实如此。

最新更新