从 oracle 函数返回布尔值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41799473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:11:58  来源:igfitidea点击:

Return boolean value from oracle function

oraclefunctionboolean

提问by ashish

Trying to return value from function

试图从函数返回值

create or replace function compairenumber(num1 in number,num2 in number)
return boolean is
begin
if num1 < num2 then
return true;
else 
return false;
end if;
end;

when i'm giving query select compairenumber(5,10) from dual its not returning true or false.

当我给出查询 select compairenumber(5,10) from dual 时,它不返回 true 或 false。

回答by mathguy

Boolean values can only be used in other PL/SQL code, notin Oracle SQL. If you want a function whose return value is available in a select ... from dualthen you will need to define the function to return varchar2with the return values 'true'and 'false'respectively (or 'T'and 'F', or return number, with the values 1 and 0).

布尔值只能在其他 PL/SQL 代码中使用,不能在 Oracle SQL 中使用。如果您想要一个返回值在 a 中可用的函数,select ... from dual那么您需要定义函数以分别varchar2返回返回值'true''false'(或'T''F',或返回数字,值为 1 和 0)。

As sad as this is, Oracle SQL does not support the Boolean data type (although the programming language PL/SQL does).

令人遗憾的是,Oracle SQL 不支持布尔数据类型(尽管编程语言 PL/SQL 支持)。

回答by ashish

use return varchar2

使用返回 varchar2

create or replace function compairenumber(num1 in number, num2 in number)
  return varchar2 is
begin
  if num1 < num2 then
    return 'TRUE';
  else
    return 'FALSE';
  end if;
end;


select CASE
         WHEN compairenumber(5, 10) = 'TRUE' THEN
          'OK'
         ELSE
          'NOT'
       END
  from dual