从 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
Return boolean value from oracle function
提问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 dual
then you will need to define the function to return varchar2
with 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