Search code examples
sqldatabaseoracle-databaseuser-defined-functionsoracle12c

How to use a user defined function in where clause in Oracle?


I want to do something like this:

SELECT subscription from TENANT where tenant_id = (select GET_TENANTID(12345) as tenant_id from DUAL);

Here, GET_TENANTID is a user-defined function. Also, tenant_id field is a varchar2 type column.

I'm on Oracle 12c.


Solution

  • Your code should work, but why not just do:

    select subscription
    from TENANT
    where tenant_id = GET_TENANTID(12345);
    

    One assumes that the types are the same. If they are not the same, convert the number to a string.