Sumit Sundriyal
Sumit Sundriyal

Reputation: 835

How to convert oracle RAW data type (saved as string) to java String?

I have a string stored in RAW data type in oracle and want to convert it into a java String.

Upvotes: 0

Views: 7261

Answers (2)

Sumit Sundriyal
Sumit Sundriyal

Reputation: 835

Following Spring JPA Repository code.
@Query(value = "select cryptFun.encrypt(:str) from dual", nativeQuery = true)
public byte[] findEncryptedToken(@Param("str") String token);

cryptFun.encrypt(str) function in the above query returns RAW data type.

Below is the Java conversion:

byte[] rawDataTypeBytes = repository.findEncryptedStr("1111111111111111");
String token = DatatypeConverter.printHexBinary(rawDataTypeBytes);

Upvotes: 0

Number945
Number945

Reputation: 4940

You can use rawtohex in your sql query itself. Example : SELCECT RAWTOHEX(SOME_ID) FROM TABLE

You can even extract your data as raw only and at API level convert it to string. When I say API level, I mean if you are using jdbc , spring-jdbc , spring data etc.

Upvotes: 1

Related Questions