Hitachi

Hitachi Advanced Database SQL Reference


8.5.7 RTRIM

Removes instances of the specified characters, starting from the end of the target character string.

Proceeding from the end of the character string, it removes all character that matches any of the characters targeted for removal, stopping as soon as it encounters a character that is not targeted for removal.

Organization of this subsection

(1) Specification format

scalar-function-RTRIM ::= RTRIM(target-data[,chars-to-remove])
 
  target-data ::= value-expression
  chars-to-remove ::= value-expression

(2) Explanation of specification format

target-data:

Specifies the data from which the characters specified in chars-to-remove are to be removed.

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.

chars-to-remove:

Specifies the characters to be removed from the target data.

The following rules apply:

  • Specify chars-to-remove in the form of a value expression. For details about value expressions, see 7.20 Value expression.

  • You must specify CHAR or VARCHAR type data for chars-to-remove.

  • If chars-to-remove is omitted, its value is assumed to be a space character.

  • If a dynamic parameter is specified by itself for chars-to-remove, the assumed data type of the dynamic parameter is VARCHAR(32000).

The following examples illustrate the result of executing the scalar function RTRIM.

Examples

RTRIM('1020rst201','012') '1020rst'

[Figure]

RTRIM('aaaadatabaseaaaa','a') 'aaaadatabase'

RTRIM('aabbccdatabase','abes') 'aabbccdat'

RTRIM('[Figure]databaseΔ') '[Figure]database'

RTRIM('database','012') 'database'

Legend:

Δ: Single-byte space

(3) Rules

  1. The data type and data length of the execution result are shown in the following table.

    Table 8‒17: Data type and data length of the execution result of the scalar function RTRIM

    Data type and data length of the target data

    Data type and data length of the execution result

    CHAR(n)

    VARCHAR(n)

    VARCHAR(n)

    Legend:

    n: Maximum length of the target data

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

  3. If target-data or chars-to-remove is the null value, the execution result will be the null value.

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

  5. If all the target character string data is removed, the execution result will be data whose actual length is 0 bytes.

  6. If you specify data whose actual length is 0 bytes or 0 characters for chars-to-remove, the execution result will be the target data.

(4) Example

Example:

Remove the numeric suffix from the character string data in column C2 of table T1.

SELECT "C1",RTRIM("C2",'0123456789') FROM "T1"

[Figure]