[Hint] Convert BOOLEAN to numeric.

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
  

Poston Mon, 14 Nov 2005 12:44 pm

This function DIUTIL.BOOL_TO_INT receives a Boolean value and returns in numeric.

Code: Select all
SQL> set serveroutput on
SQL> declare v boolean;
  2  begin
  3    v := true;
  4    dbms_output.put_line( 'True  retorna '||sys.diutil.bool_to_int(v) );
  5    v := false;
  6    dbms_output.put_line( 'False retorna '||sys.diutil.bool_to_int(v) );
  7  end;
  8  /
True  retorna 1
False retorna 0

PL/SQL procedure successfully completed.

SQL>
works for comparisons:
Code: Select all
SQL> begin
  2    dbms_output.put_line( sys.diutil.bool_to_int(1=1) );
  3    dbms_output.put_line( sys.diutil.bool_to_int(1=2) );
  4  end;
  5  /
1
0

PL/SQL procedure successfully completed.

SQL>
Unfortunately, does not work inside a SQL directly:
Code: Select all
SQL> select sys.diutil.bool_to_int(1=1) from dual;
select sys.diutil.bool_to_int(1=1) from dual
                               *
ERROR at line 1:
ORA-00907: missing right parenthesis


SQL> select sys.diutil.bool_to_int(true) from dual;
select sys.diutil.bool_to_int(true) from dual
                              *
ERROR at line 1:
ORA-00904: invalid column name
dr_gori
Location: Portland, OR USA

Thomas F. G

Você já respondeu a dúvida de alguém hoje?
http://glufke.net/oracle/search.php?search_id=unanswered


  • See also
    Replies
    Views
    Last Post

Return to PL/SQL

Who is online

Users browsing this forum: No registered users and 4 guests