Hitachi

Hitachi Advanced Database SQL Reference


8.6.3 LENGTH

Returns the number of characters in the target character string.

Organization of this subsection

(1) Specification format

scalar-function-LENGTH ::= LENGTH(target-data)
 
  target-data ::= value-expression

(2) Explanation of specification format

target-data:

Specifies the data whose length in characters is to be counted.

The following rules apply:

  • Specify the target data in the form of a value expression. For details about value expressions, see 7.20 Value expression.

  • Specify CHAR or VARCHAR type data for the target data.

  • You cannot specify a dynamic parameter by itself for the target data.

(3) Rules

  1. The data type of the execution result is the INTEGER type.

  2. The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).

  3. If the target data has the null value, the execution result will be a null value.

  4. If the actual length of the target data is 0 bytes or 0 characters, the execution result will be 0.

(4) Example

Example:

Determine the number of characters in the data in columns C1 and C2 from table T1.

In this case, the character encoding being used is Unicode (UTF-8).

SELECT LENGTH("C1"),LENGTH("C2") FROM "T1"

[Figure]

In the above example, each space is counted as one character.