How to use BOOLEAN type in SELECT statement

后端 未结 10 1346
鱼传尺愫
鱼传尺愫 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条回答
  • 2020-11-29 02:32

    PL/SQL is complaining that TRUE is not a valid identifier, or variable. Set up a local variable, set it to TRUE, and pass it into the get_something function.

    0 讨论(0)
  • 2020-11-29 02:34

    The BOOLEAN data type is a PL/SQL data type. Oracle does not provide an equivalent SQL data type (...) you can create a wrapper function which maps a SQL type to the BOOLEAN type.

    Check this: http://forums.datadirect.com/ddforums/thread.jspa?threadID=1771&tstart=0&messageID=5284

    0 讨论(0)
  • 2020-11-29 02:37

    You can build a wrapper function like this:

    function get_something(name in varchar2,
                       ignore_notfound in varchar2) return varchar2
    is
    begin
        return get_something (name, (upper(ignore_notfound) = 'TRUE') );
    end;
    

    then call:

    select get_something('NAME', 'TRUE') from dual;
    

    It's up to you what the valid values of ignore_notfound are in your version, I have assumed 'TRUE' means TRUE and anything else means FALSE.

    0 讨论(0)
  • 2020-11-29 02:38

    You can definitely get Boolean value from a SELECT query, you just can't use a Boolean data-type.

    You can represent a Boolean with 1/0.

    CASE WHEN (10 > 0) THEN 1  ELSE 0 END (It can be used in SELECT QUERY)
    
    SELECT CASE WHEN (10 > 0) THEN 1  ELSE 0 END AS MY_BOOLEAN_COLUMN
      FROM DUAL
    

    Returns, 1 (in Hibernate/Mybatis/etc 1 is true). Otherwise, you can get printable Boolean values from a SELECT.

    SELECT CASE WHEN (10 > 0) THEN 'true' ELSE 'false' END AS MY_BOOLEAN_COLUMN
     FROM DUAL
    

    This returns the string 'true'.

    0 讨论(0)
提交回复
热议问题