Octet Length
Definition
The octetLength
method allows you to add the OCTET_LENGTH
function to the query. The OCTET_LENGTH
function is used to count the number of bytes in a specified string.
There are 2 ways to call this method:
1. Calling from a KColumn
or a KTableColumn
The only one method available to use this functionality calling from a KColumn
or a KTableColumn
is:
octetLength()
: It does not receive any parameters. TheKColumn
orKTableColumn
that invokes the method will be the one supplied to theOCTET_LENGTH
function.
Example
Java code:
k
.select(
APP_USER.EMAIL.octetLength()
)
.from(APP_USER)
.multiple();
SQL generated:
SELECT
OCTET_LENGTH(au.email)
FROM app_user au
Parameters:
- None
2. Calling from the KFunction
class
The methods available to use this functionality calling from the KFunction
class are:
octetLength(KColumn kColumn)
: Receives aKColumn
or aKTableColumn
which will be supplied to theOCTET_LENGTH
function.octetLength(KValTextField kValTextField)
: Receives aKValTextField
which will be supplied to theOCTET_LENGTH
function.
To use this way, you need to import the static functions as follows:
import static com.myzlab.k.KFunction.*;
Example: (KColumn)
Java code:
k
.select(
octetLength(APP_USER.EMAIL)
)
.from(APP_USER)
.multiple();
SQL generated:
SELECT
OCTET_LENGTH(au.email)
FROM app_user au
Parameters:
- None
Example: (KValTextField)
Java code:
k
.select(
octetLength(val("A short text"))
)
.single();
SQL generated:
SELECT OCTET_LENGTH(?1)
Parameters:
- ?1: "A short text"