Oracle包或函数处于无效状态

时间:2013-05-12 13:30:33

标签: sql oracle plsql cursor

尝试创建基于pl / sql游标的函数以从oracle数据库返回详细信息。

相关表格MEETING包含列 MEETING_ID:number(10),TIME:timestamp(4),TITLE:varchar(20)

CREATE OR REPLACE FUNCTION GetMeeting
                    (meetingnumber MEETING.MEETING_ID%TYPE)
RETURN VARCHAR
IS
    CURSOR current_meeting(meetingnumber MEETING.MEETING_ID%TYPE)
    IS
        SELECT TITLE, TIME
        FROM MEETING
        WHERE MEETING_ID = meetingnumber;

    r_meeting current_meeting%ROWTYPE;
BEGIN
    OPEN current_meeting(meetingnumber);

    FETCH current_meeting INTO r_meeting;

    IF current_meeting%NOTFOUND THEN
        r_meeting.TITLE := 'UNKNOWN APPOINTMENT';
        END IF;

        CLOSE current_meeting;

        RETURN r_meeting.TITLE;
    END;


SELECT GetMeeting (27) name
FROM MEETING;

该函数似乎编译好 - 但是当被调用时抛出

  

ORA-06575:包或函数GETMEETING处于无效状态

3 个答案:

答案 0 :(得分:1)

也许这对你更有效:

create or replace function
  getmeeting(
    meeting_id number)
return
  varchar
is
  meeting_title meeting.title%Type;
begin
  select title
  into   meeting_title
  from   meeting
  where  meeting_id = getmeeting.meeting_id;

  return meeting_title;
exception
  when NO_DATA_FOUND then
     return 'UNKNOWN APPOINTMENT';
end;
/

未检查语法。

答案 1 :(得分:0)

由列标识符'TIME'生成错误,它是一个SQL关键字;执行时触发运行时错误。

当删除'TIME'时,代码很遗憾地返回NULL

答案 2 :(得分:0)

没有足够的事实要知道,但我会研究某种形式的循环依赖。

select * 
  from user_dependencies 
 where referenced_name = 'GETMEETING' 
   and referenced_type = 'FUNCTION';

避免循环依赖的最佳方法是使用只在主体中引用其他包的包。避免使用独立的函数和过程对象。