create or replace function id_is_good(empid in number) return boolean
as
v_id number;
begin
select count(*) into v_id from scott.emp e where e.empno=empid;
return 1=v_id;
exception
when others then
return false;
end id_is_good;----------------------------------------------------------------------SQL> select system.id_is_good(7369) from dual;
select system.id_is_good(7369) from dual
ORA-06552: PL/SQL: Statement ignored
ORA-06553: PLS-382: 表达式类型错误
as
v_id number;
begin
select count(*) into v_id from scott.emp e where e.empno=empid;
return 1=v_id;
exception
when others then
return false;
end id_is_good;----------------------------------------------------------------------SQL> select system.id_is_good(7369) from dual;
select system.id_is_good(7369) from dual
ORA-06552: PL/SQL: Statement ignored
ORA-06553: PLS-382: 表达式类型错误
这个函数返回的是boolean型
布尔型在pl/sql中能正常使用,但在sql中不行
改为if nvl(v_id,0)>0 then
return true;
else
return false;
end if;
即使这样改了,你的select system.id_is_good(7369) from dual;也会报错
因为表boolean不可能从select语句中返回
返回的是0或者1,不是true以及false