How to use BOOLEAN type in SELECT statement

后端 未结 10 1376
鱼传尺愫
鱼传尺愫 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 02:15

    With Oracle 12, you can use the WITH clause to declare your auxiliary functions. I'm assuming your get_something function returns varchar2:

    with
      function get_something_(name varchar2, ignore_notfound number)
      return varchar2 
      is
      begin
        -- Actual function call here
        return get_something(name, not ignore_notfound = 0);
      end get_something_;
    
      -- Call auxiliary function instead of actual function
    select get_something_('NAME', 1) from dual;
    

    Of course, you could have also stored your auxiliary function somewhere in the schema as shown in this answer, but by using WITH, you don't have any external dependencies just to run this query. I've blogged about this technique more in detail here.

提交回复
热议问题