create or replace function huifunction(i_user_id in number) return varchar2 is
m_result varchar2(40);begin begin ---勿忘 select deptname into m_result from dept where id=i_user_id; exception when others then m_result:='出错'; end; return (m_result);end huifunction;
----另一种实现方法
create or replace function huifunction2(i_user_id in number,o_err out varchar) return varchar2 is
m_result varchar2(40); m_count number;begin m_result:=''; select count(0) into m_count from dept where id=i_user_id; if m_count>0 then select deptname into m_result from dept where id=i_user_id; else o_err:='出错'; end if; return (m_result);end huifunction2;