布尔替换共映射未提供正确的输出

时间:2019-04-22 14:25:21

标签: oracle plsql

我有一个plsql代码,其中声明了variable,但是当我更改比较运算符时,代码无法像下面定义的那样正常工作

SET SERVEROUTPUT ON;
DECLARE
    v_num1   number(10);
    v_num2     number(10);
    v_num3      number(10);
    v_num4      number(10);

    lowrec      boolean:=FALSE;
BEGIN   
    v_num3 := 34;
    v_num4:=3;

    lowrec :=(v_num3>v_num4);

    IF lowrec then
        DBMS_OUTPUT.PUT_LINE('The record is '||v_num3 ||' smaller than '||v_num4 ||' ' ||sys.diutil.bool_to_int(lowrec));
    ELSE
        DBMS_OUTPUT.PUT_LINE('The record is '||v_num3||' higher than '||v_num4 ||' '||sys.diutil.bool_to_int(lowrec));
    END IF;

END;


OUTPUT: 
The record is 34 smaller than 3 1

passed value are 34 and 3 but it is showing 34 is smaller than 3

1 个答案:

答案 0 :(得分:1)

dbms_outputIF之间交换ELSE消息

SET SERVEROUTPUT ON
DECLARE
     v_num1 NUMBER(10);
     v_num2 NUMBER(10);
     v_num3 NUMBER(10);
     v_num4 NUMBER(10);
     lowrec BOOLEAN := false;
BEGIN
     v_num3 := 34;
      v_num4 := 3;

    lowrec := (v_num3 > v_num4 );
     IF lowrec THEN dbms_output.put_line('The record is '
                               || v_num3
                               || ' higher than '
                               || v_num4
                               ||' '|| sys.diutil.bool_to_int(lowrec));
     ELSE dbms_output.put_line('The record is '
                                       || v_num3
                                       || ' smaller than '|| v_num4  --or equal to ?
                                       || ' '
                                       || sys.diutil.bool_to_int(lowrec));
     END IF;

END;
/

The record is 34 higher than 3 1

PL/SQL procedure successfully completed.