create or replace FUNCTION f_empLever(v_hire_date1 in number)
return number
as
v_rank number;
v_Hire_date number;
begin
SELECT to_char(hire_date,'yyyy') into v_Hire_date
FROM empcopy where to_char(hire_date,'yyyy')=v_hire_date1;
--select department_id into e_id from empcopy;
if v_Hire_date<=2003 then
v_rank:=3;
elsif v_Hire_date<=2005 and v_Hire_date>2003 then
v_rank:=2;
else
v_rank:=3;
end if;
dbms_output.put_line('作業時長等級級別為:'||v_rank);
return v_rank;
exception
when no_data_found then
dbms_output.put_line('您輸入的年份錯誤!:');
end;
uj5u.com熱心網友回復:
貼子發重了?uj5u.com熱心網友回復:
不是這游標怎么添加上去?我添加后輸入2003,結果還是報錯
錯誤報告 -
ORA-01422: 實際回傳的行數超出請求的行數
ORA-06512: 在 line 5
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested
uj5u.com熱心網友回復:
FROM empcopy where to_char(hire_date,'yyyy')=v_hire_date1;
-- 加這個條件
AND rownum = 1
uj5u.com熱心網友回復:
謝謝哈,,,可是為什么不用游標檢索多行資料呢?uj5u.com熱心網友回復:
想用游標加上這個函式解決多行資料檢索的問題
uj5u.com熱心網友回復:
符合的記錄是多行,可以用游標回圈處理,這沒有問題,但是你的回傳值呢?只能回傳一個,回傳哪一行的記錄呢uj5u.com熱心網友回復:
回傳多個值的函式,只能用管道化函式,百度搜索下用法轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/94916.html
標籤:開發
上一篇:存盤程序例外后觸發觸發器
下一篇:代碼問題
