“Boolean” parameter for Oracle stored procedure

前端 未结 2 1648
说谎
说谎 2021-01-04 04:57

I\'m aware that Oracle does not have a boolean type to use for parameters, and am currently taking in a NUMBER type which would have 1/0 for True/False (instead of the \'Y\'

2条回答
  •  忘掉有多难
    2021-01-04 05:21

    Yes and no. You can do..

    create or replace package t_bool is
      subtype t_bool_num IS PLS_INTEGER RANGE 0..1;
      function f_test (i_bool_num t_bool_num) return varchar2;
    end t_bool;
    /
    
    create or replace package body t_bool is
      function f_test (i_bool_num t_bool_num) return varchar2 is
      begin
        if i_bool_num = 0 then 
          return 'false';
        elsif i_bool_num = 1 then
          return 'true';
        elsif i_bool_num is null then
          return 'null';
        else
          return to_char(i_bool_num);
        end if;
      end;
    end t_bool;
    /
    

    The good news is that, if you do

    exec dbms_output.put_line(t_bool.f_test(5));
    

    it reports an error.

    The bad news is that if you do

    select t_bool.f_test(5) from dual;
    

    then you don't get an error

提交回复
热议问题