Skip to content
Advertisement

Kotlin CLOB to String

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:

 @Query(nativeQuery = true, value = "SELECT GETIDSSTATUS() FROM DUAL")
 Clob getIdsStatus();

Conversion to String:

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:

@Query("select getidstatus() from dual")
fun getIdStatus(): Clob

And then you can write smomething like this:

val idsStatus = dbMonRepository.getIdStatus()
val idsStatusStr = idsStatus.getSubstring(1, Math.toIntExact(idsStatus.length)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement