在Oracle表单PL / SQL布尔变量评价 [英] Evaluation of PL/SQL boolean variables in Oracle Forms

查看:215
本文介绍了在Oracle表单PL / SQL布尔变量评价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假如我有在Oracle表一个PL / SQL块中的布尔变量:

Suppose I have a BOOLEAN variable within a PL/SQL block in an Oracle Form:

DECLARE
  is_viewable BOOLEAN;
BEGIN
  is_viewable := ...;

  IF NOT is_viewable THEN
    raise_my_error(); // pseudo-code
  END IF;
END;

通过这个code几次调试器步进后,我已经确定, raise_my_error() 绝不会被调用。为了澄清:


  • raise_my_error()确实不可以被调用,如果 is_viewable = TRUE

  • raise_my_error()确实不可以被调用,如果 is_viewable = FALSE

  • raise_my_error() does not get called if is_viewable = TRUE
  • raise_my_error() does not get called if is_viewable = FALSE

最初的测试表明,这种行为仅限于PL / SQL code运行的Oracle Forms中,并直接在数据库中没有PL / SQL code运行(虽然我可能是错的)。

Initial tests suggest that this behavior is limited to PL/SQL code run within Oracle Forms and not PL/SQL code run directly within the database (although I could be wrong).

我可以明确地比较 is_viewable FALSE 解决这个问题

I can get around this by explicitly comparing is_viewable to FALSE:

IF is_viewable = FALSE THEN
  raise_my_error();
END IF;

我仍然好奇,为什么不is_viewable 从不计算 TRUE

更新:看来,我的调试器没有显示正确的价值观,这个问题已不再有效。比较遗憾的是混乱。

Update: It appears that my debugger wasn't showing correct values and that this question is no longer valid. Sorry about that confusion.

推荐答案

我们可以在sqlplus测试此看到在每个3的情况下会发生什么(真,假,空):

We can test this in SQLPlus to see what happens in each of the 3 situations (true, false, null):

set serveroutput on

declare
  true_value boolean := true;
  false_value boolean := false;
  null_value boolean;
begin

    if not true_value then  --Should not pass
      dbms_output.put_line('True Value');
    end if;

    if not false_value then --Should pass
      dbms_output.put_line('False Value');
    end if;

    if null_value is null then --Just to make sure it is null
      dbms_output.put_line('Null Value is Null');
    end if;

    if not null_value then --Should not pass
      dbms_output.put_line('Null Value');
    end if;
end;
/

主要生产:

SQL> set serveroutput on
SQL>
SQL> declare
  2    true_value boolean := true;
  3    false_value boolean := false;
  4    null_value boolean;
  5  begin
  6
  7      if not true_value then  --Should not pass
  8        dbms_output.put_line('True Value');
  9      end if;
 10
 11      if not false_value then --Should pass
 12        dbms_output.put_line('False Value');
 13      end if;
 14
 15      if null_value is null then --Just to make sure it is null
 16        dbms_output.put_line('Null Value is Null');
 17      end if;
 18
 19      if not null_value then --Should not pass
 20        dbms_output.put_line('Null Value');
 21      end if;
 22  end;
 23  /
False Value
Null Value is Null

PL/SQL procedure successfully completed.

SQL>

这样就可以产生你期望的输出是如果该值进入条件的唯一可能code路径是假的。如果这是你所看到的不是预期或则别的东西必须在程序或副作用发生。

So the only possible code path that can produce your expected output is if the value going into the conditional is false. If that is not what you are seeing or expecting then something else must be happening in your procedure or as a side effect.

这篇关于在Oracle表单PL / SQL布尔变量评价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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