javahibernatejpajpqlnamed-query

Equivalent UTL_RAW.BIT_OR in JPQL


I'm trying to make a namedquery with a result DTO where there is a field that I have to calculate using that function. Is there any equivalent?

SELECT new BitsDTO( 
UTL_RAW.BIT_OR(b.bitsA, b.bitsB) as bitsCalculated)
FROM Bits b
where b.id = ?;

Thanks.


Solution

  • If you want to call a database function in JPQL you can do it like this

    SELECT new BitsDTO(
        function("UTL_RAW.BIT_OR", b.bitsA, b.bitsB)
    )
    FROM Bits b
    where b.id = ?
    

    That way you can call any database function. The first argument is the function name.