1

How to use user defined function as boolean expression ?

For example function REGEXP_LIKE() used as boolean expression, right?

... WHERE REGEXP_LIKE() ...

But how to make such for user defined function? When my function returns BOOLEAN type and then, when I call this function, I got error because pure SQL can't use BOOLEAN type.

P.S.

So, I do this: my function returns VARCHAR2 type: that is 'TRUE' or 'FALSE' and then in SQL I use: ... WHERE my_function() = 'TRUE' ...

This is right way for simulate boolean type? or exists more better solutions ?

1 Answer 1

1

No. This can be confusing in Oracle but SQL does NOT know boolean datatype, although it deals with boolean expressions. Unlike procedural PL/SQL where boolean datatype can be used.

In Oracle SQL and PL/SQL are evaluated by different engines. These engines use similar datatypes, but not the same.

Sign up to request clarification or add additional context in comments.

4 Comments

So, in SQL, simulating boolean type using varchar, that is: WHERE my_function() = 'TRUE' is a normal way ?
Yes. You can even create your own "operator" in Oracle. But even operator work the same way.
Maybe when you return a NUMBER instead of VARCHAR2 from your function it will be a little bit faster.
@Ivan I'd go for return type NUMBER instead of VARCHAR2 - simpler and cleaner IMO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.