I have a function in Oracle that returns a CLOB. In Java I can use the following code to execute this function and fetch the result:
Oracle function definition in my Repository class:
JavaScript
x
@Query(nativeQuery = true, value = "SELECT GETIDSSTATUS() FROM DUAL")
Clob getIdsStatus();
Conversion to String:
JavaScript
Clob idsStatus = dbMonRepository.getIdsStatus();
String idsStatusStr = idsStatus.getSubString(1, Math.toIntExact(idsStatus.length()));
What’s the equivalent code in Kotlin or any other way to convert the Clob to String?
Advertisement
Answer
It’s absolutely legal use @Query annotation in your kotlin code. For exmaple like this:
JavaScript
@Query("select getidstatus() from dual")
fun getIdStatus(): Clob
And then you can write smomething like this:
JavaScript
val idsStatus = dbMonRepository.getIdStatus()
val idsStatusStr = idsStatus.getSubstring(1, Math.toIntExact(idsStatus.length)