【问题标题】:Boolean arithmetics in plsqlplsql中的布尔算术
【发布时间】:2012-05-28 09:12:08
【问题描述】:

我有一组 pl/sql 函数,都返回布尔类型。
我从另一个 pl/sql 函数中一一调用这些函数。我想“累积”结果并从该函数返回。

例如:

  v_res  boolean;
  v_res2 boolean := true;
begin
  v_res := f1('aa');
  if v_res = false then
    v_res2 := false;
  end if;

  v_res := f2('aa');
  if v_res = false then
    v_res2 := false;
  end if;

  -- some other calls to other functions

  return v_res2;
end;

我想知道,我可以在 pl/sql 中进行布尔运算吗?
我的意思是这样的:

  v_res boolean := true;
begin
  v_res := v_res * f1('aa');
  v_res := v_res * f2('aa');
  -- more calls to functions
  return v_res;
end;

我试过了:

v_res := v_res * false;

v_res := v_res and false;

但似乎唯一可行的是将布尔值转换为 int(我尝试使用 sys.diutil.bool_to_int),这感觉不对...

【问题讨论】:

  • v_res * false - 你对这种奇怪的表达有什么期望?
  • 你最后一次尝试成功:v_res := v_res and f1('aa');
  • @TonyAndrews,你说得对!我不知道上次检查时发生了什么...
  • @zerkms,我希望它在“C”中是错误的。

标签: oracle plsql


【解决方案1】:
begin
  return f1('aa')
     and f2('aa')
     ... etc. ...
     ;
end;

【讨论】:

    猜你喜欢
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2013-04-15
    相关资源
    最近更新 更多