自定义函数
create or replace function check_id
(in_departmentid in char(3))
return number
as
 num number;
begin
 select count(*) into num
 from departments
 where departmentid=in_departmentid;
 if num<>0 then
 num:=0;
 else
 num:=-1;
 end if
 return num;
end check_id;调用函数:
begin
 dbms_output.put_line(to_char(check_id('2')));
end;调用函数第二行发生错误:对象wang.check_id无效 pl/sql:Statement ignored
请问大家这是怎么回事啊?

解决方案 »

  1.   

    create   or   replace   function   check_id
    (in_departmentid   in   char)
    return   number
    as
      num   number;
    begin
      select   count(*)   into   num
      from   departments
      where   departmentid=in_departmentid;
      if   num <> 0   then
      num:=0;
      else
      num:=-1;
      end   if;
      return   num;
    end   check_id; 
      

  2.   

    in_departmentid   in   char(3)这里在em中编译报错如下:Line # = 1 Column # = 54 Error Text = PLS-00103: 出现符号 "("在需要下列之一时:
     := ) , default varying
       character large
    符号 ":=" 被替换为 "(" 后继续。这里能不能将in_departmentid的类型写成char(3)呢?如果能写应该怎样写呢?我是按照课本上写的