File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
documentation/src/main/asciidoc/querylanguage
hibernate-core/src/main/java/org/hibernate/dialect Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -576,6 +576,7 @@ The following special functions make it possible to discover or narrow expressio
576576| `cast()` | Narrow a basic type | `cast(x as Type)` | ✔
577577| `str()` | Cast to a string | `str(x)` | ✖
578578| `ordinal()` | Get the ordinal value of an enum | `ordinal(x)` | ✖
579+ | `string()` | Get the string-valued name of an enum | `string(x)` | ✖
579580|===
580581
581582Let's see what these functions do.
@@ -647,16 +648,17 @@ select str(id) from Order
647648
648649[[function-ordinal]]
649650[discrete]
650- ===== Extracting the ordinal value of an enum
651+ ===== Extracting the ordinal value or name of an enum
651652
652- The function `ordinal(x)` extracts the ordinal value of an enum.
653- It supports both enum fields mapped as `ORDINAL` and `STRING`.
653+ The function `ordinal(x)` extracts the ordinal value of an enum, and the function `string(x)` extracts the name of the enum value as a string.
654654
655655[source, hql]
656656----
657- select ordinal(p.type) from Phone p
657+ select ordinal(p.type), string(p.type) from Phone p
658658----
659659
660+ Both functions work with enum fields mapped as `ORDINAL` and with enum fields mapped as `STRING`.
661+
660662[[functions-null]]
661663==== Functions for working with null values
662664
Original file line number Diff line number Diff line change @@ -1028,6 +1028,11 @@ public int ordinal() {
10281028 * <li> <code>ifnull(arg0, arg1)</code> - synonym of <code>coalesce(a, b)</code>
10291029 * </ul>
10301030 *
1031+ * <ul>
1032+ * <li> <code>ordinal(arg)</code>
1033+ * <li> <code>string(arg)</code>
1034+ * </ul>
1035+ *
10311036 * Finally, the following functions are defined as abbreviations for
10321037 * <code>extract()</code>, and desugared by the parser:
10331038 *
You can’t perform that action at this time.
0 commit comments