How to use BOOLEAN type in SELECT statement

后端 未结 10 1363
鱼传尺愫
鱼传尺愫 2020-11-29 01:43

I have a PL/SQL function with BOOLEAN in parameter:

function get_something(name in varchar2, ignore_notfound in boolean);

This function is

10条回答
  •  Happy的楠姐
    2020-11-29 02:29

    Compile this in your database and start using boolean statements in your querys.

    note: the function get's a varchar2 param, so be sure to wrap any "strings" in your statement. It will return 1 for true and 0 for false;

    select bool('''abc''<''bfg''') from dual;
    
    CREATE OR REPLACE function bool(p_str in varchar2) return varchar2 
     is
     begin
    
     execute immediate ' begin if '||P_str||' then
              :v_res :=  1;
           else
              :v_res :=  0;
           end if; end;' using out v_res;
    
           return v_res;
    
     exception 
      when others then 
        return '"'||p_str||'" is not a boolean expr.';
     end;
    /
    

提交回复
热议问题