I am using jooq's DSL.select in my Java code, I have scenario where I need to determine the index from a string.
Used DSL.substring("hello123",6,1)
to get the desired index value as string, but no method supporting in DSL to convert it to a number.
Example:
DSL.select(
COL1,
COL2,
COL3,
DSL.substring("Test123456"),
1,
DSL.substring("hello123",6,1))
.from(TABLE)
the nested substring need to be converted into number
Converting strings to numbers
Use the
CAST
expression:As always, this is assuming the following static import:
Mixing
Field<?>
expressions with bind valuesYou've mixed your
Field<?>
expression with a bind value1
in yourSELECT
clause. There's no such convenience overload forSELECT
(there would be too many permutations), so you'll have to wrap the bind value explicitly using:See also: How do I create a Field<T> from a value T in jOOQ, explicitly?