Search code examples
oracleplsqloracle11gora-06553

Function returning boolean fails on "expression is of wrong type"


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 :

This is the function body

FUNCTION legal_user(
     level_existance  number
    ,types_with_impel number)
RETURN BOOLEAN
 IS
 v_ret_val BOOLEAN;
 BEGIN
   v_ret_val := FALSE;
   IF (level_existance*types_with_impel>0) then 
     v_ret_val := TRUE;
     DBMS_OUTPUT.PUT_LINE('true');
   else 
     DBMS_OUTPUT.PUT_LINE('false');
   END IF;       
  return v_ret_val;
END legal_user;

This is the spec :

FUNCTION legal_user(
       level_existance number
       ,types_with_impel number)
   RETURN BOOLEAN;

which does logical AND equivlant to

         A*B>0?true:false;   

The error message I am getting is

ORA-06552: PL/SQL: Statement ignored ORA-06553: PLS-382: expression is of wrong type 06552. 00000 - "PL/SQL: %s" *Cause:
*Action: Error at Line: 1 Column: 7


This is how I run it in my IDE

 SELECT compt_tree_profile_q.legal_user(1,1)
 FROM dual 

Solution

  • Pure SQL does not recognize a boolean type (until version 23c), 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.