Function returning boolean fails on “expression is of wrong type”

前端 未结 3 1650
离开以前
离开以前 2021-01-11 10:35

I am using oracle 11g and I just cant under stand where my problem is. I have made much more difficult stuff but I fail in this simple thing for the last 5 hr :

Thi

相关标签:
3条回答
  • 2021-01-11 10:47

    Pure SQL does not recognize a boolean type, although PL/SQL does. So your query does not know what datatype this function is returning..

    The function works, so you could in another pl/sql block use

    declare
    myvar boolean;
    begin
       myvar := compt_tree_profile_q.legal_user(1,1);
    end;
    

    But you can't use this function in a pure select statement.

    0 讨论(0)
  • 2021-01-11 10:50

    Your function returns a boolean. This datatype is known to PL/SQL, but you are using a SQL query. SQL doesn't know how to handle booleans and says "expression is of wrong type".

    Regards,
    Rob.

    0 讨论(0)
  • 2021-01-11 11:10

    Given that you are calling this within SQL, you could use the built-in SIGN function instead of rolling your own.

    The function will return -1, 0 or 1, depending on the sign of the parameter (negative, zero or positive respectively).

    Here's how you would use it:

    SIGN(level_existance*types_with_impel)
    

    And how you would work it into a CASE statement:

    SELECT CASE WHEN (SIGN(level_existance*types_with_impel) = 1)
                THEN 'TRUE'
                ELSE 'FALSE'
           END legal_user
    FROM ...
    

    In this case, I'm just returning a string ('TRUE' or 'FALSE'), but you can return anything that's valid within your SELECT statement (a column, SYSDATE, etc).

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