返回布尔值的函数在“表达式类型错误"时失败 [英] Function returning boolean fails on "expression is of wrong type"

查看:31
本文介绍了返回布尔值的函数在“表达式类型错误"时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 

推荐答案

Pure SQL 不识别布尔类型,尽管 PL/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆