大家帮看一看,以下在sql/Plus中调试的语句错在哪里?
SQL>
1 create or replace function check_id
2 (departmentid in char(3))
3 return number
4 as
5 num number;
6 begin
7 if exists(select xh from xs where xh=departmentid) then
8 num:=0;
9 else
10 num:=1;
11 end if;
12 return num;
13* end check_id;
SQL> /警告: 创建的函数带有编译错误。
SQL>
1 create or replace function check_id
2 (departmentid in char(3))
3 return number
4 as
5 num number;
6 begin
7 if exists(select xh from xs where xh=departmentid) then
8 num:=0;
9 else
10 num:=1;
11 end if;
12 return num;
13* end check_id;
SQL> /警告: 创建的函数带有编译错误。
SQL>
1 create or replace function check_id
2 (departmentid in char(3))
3 return number;
4 as
5 num number;
6 begin
Select Count(1) Into num From xs where xh=departmentid;
7 --if exists(select xh from xs where xh=departmentid) then
8 --num:=0;
9 --else
10 --num:=1;
11 --end if;
12 --return num;
Rerurn 1-Sign(num);
13* end check_id;
SQL> /
(departmentid in char
(3))2.exists语句不能直接用在PLSQL中,只能用在sql中,可以像kenwstar一样的修改。