Database Functions
The library supplies implementations for several common database functions. We do not try to implement a large set of functions. Rather, we supply some common functions as examples and make it relatively easy to write your own implementations of functions you might want to use that are not supplied by the library. See the page “Extending the Library” for information about how to write your own functions.
The supplied functions are all in the org.mybatis.dynamic.sql.select.function
package. In addition, there are static methods in the SqlBuilder
to access all functions.
In the following table…
- “Function Class” is implementing class in the
org.mybatis.dynamic.sql.select.function
package - “Example” shows the static method from the
SqlBuilder
class - “Rendered Result” shows the rendered SQL fragment generated by the function
Function Class | Example | Rendered Result |
---|---|---|
Add | add(column1, column2, constant(55)) | column1 + column2 + 55 |
Concatenate | concatenate(stringConstant("Name: ", column1) | 'Name: ' || column1 |
Divide | divide(column1, column2, constant(55)) | column1 / column2 / 55 |
Lower | lower(column1) | lower(column1) |
Multiply | multiply(column1, column2, constant(55)) | column1 * column2 * 55 |
OperatorFunction | applyOperator(“^”, column1, column2) | column1 ^ column2 |
Substring | substring(column1, 5, 7) | substring(column1, 5, 7) |
Subtract | subtract(column1, column2, constant(55)) | column1 - column2 - 55 |
Upper | upper(column1) | upper(column1) |
Note especially the OperatorFunction
- you can use this function to easily implement operators supported by your database. For example, MySQL supports a number of bitwise operators that can be easily implemented with this function.