下面的函數應該返回與特定會議的信息,存儲在會議桌上:甲骨文:函數只返回null
CREATE TABLE "MEETING"
( "MEETING_ID" NUMBER(10,0) NOT NULL ENABLE,
"TIME" TIMESTAMP (4) NOT NULL ENABLE,
"LOCATION" VARCHAR2(40),
"MAP_HREF" VARCHAR2(140),
"FK_INTEREST_ID" CHAR(4) NOT NULL ENABLE,
"ADDITIONAL_INFO" CLOB,
"PASSED" NUMBER(1,0),
"TITLE" VARCHAR2(20),
CONSTRAINT "MEETING_PK" PRIMARY KEY ("MEETING_ID") ENABLE
) ;
代碼編譯就好了,和精美的運行以及。
但是,如果會議存在,則只返回null。如果會議不存在,則正確打印「UNKNOWN APPOINTMENT」。
CREATE OR REPLACE FUNCTION GetMeeting
(meetingnumber MEETING.MEETING_ID%TYPE)
RETURN VARCHAR
IS
CURSOR current_meeting(meetingnumber MEETING.MEETING_ID%TYPE)
IS
SELECT TITLE
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) appointment
FROM MEETING;
TITLE不是強制性列。你確定你已經填入ID = 27的記錄嗎? – APC 2013-05-13 13:02:38