返回布尔值的函数在“表达式是错误类型"时失败. [英] Function returning boolean fails on "expression is of wrong type"
问题描述
我正在使用oracle 11g,但我无法解决问题所在. 我做了很多困难的事情,但是最近5个小时我在这个简单的事情上失败了:
I am using oracle 11g and I just cant under stand where my problem is. I have made much more difficult stuff but I fail in this simple thing for the last 5 hr :
这是功能体
FUNCTION legal_user(
level_existance number
,types_with_impel number)
RETURN BOOLEAN
IS
v_ret_val BOOLEAN;
BEGIN
v_ret_val := FALSE;
IF (level_existance*types_with_impel>0) then
v_ret_val := TRUE;
DBMS_OUTPUT.PUT_LINE('true');
else
DBMS_OUTPUT.PUT_LINE('false');
END IF;
return v_ret_val;
END legal_user;
这是规格:
FUNCTION legal_user(
level_existance number
,types_with_impel number)
RETURN BOOLEAN;
与逻辑等效
A*B>0?true:false;
我收到的错误消息是
ORA-06552:PL/SQL:语句被忽略
ORA-06553:PLS-382:表达式类型错误
06552.00000-"PL/SQL:%s"
*原因:
*行动:
行错误:1列:7
ORA-06552: PL/SQL: Statement ignored
ORA-06553: PLS-382: expression is of wrong type
06552. 00000 - "PL/SQL: %s"
*Cause:
*Action:
Error at Line: 1 Column: 7
这就是我在IDE中运行它的方式
This is how I run it in my IDE
SELECT compt_tree_profile_q.legal_user(1,1)
FROM dual
推荐答案
尽管PL/SQL可以,但是纯SQL不能识别布尔类型.因此,您的查询不知道此函数返回的数据类型.
Pure SQL does not recognize a boolean type, although PL/SQL does. So your query does not know what datatype this function is returning..
该功能有效,因此您可以在另一个pl/sql块中使用
The function works, so you could in another pl/sql block use
declare
myvar boolean;
begin
myvar := compt_tree_profile_q.legal_user(1,1);
end;
但是您不能在纯select语句中使用此功能.
But you can't use this function in a pure select statement.
这篇关于返回布尔值的函数在“表达式是错误类型"时失败.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!