Oracle® TimesTen In-Memory Database SQL Reference Release 11.2.1 Part Number E13070-03 |
|
|
View PDF |
The RTRIM function removes from the right end of Expression1
all of the characters contained in Expression2
. TimesTen scans Expression1
backwards from its last character and removes all characters that appear in Expression2
until reaching a character not in Expression2
and then returns the result.
SQL syntax
RTRIM (Expression1 [,Expression2])
Parameters
RTRIM has the parameters:
Parameter | Description |
---|---|
Expression1 |
The CHAR, VARCHAR2, NCHAR or NVARCHAR2 operand or column to be trimmed. If Expression1 is a character literal, then enclose it in quotes. |
Expression2 |
Optional expression used for trimming Expression1 . If Expression2 is a character literal, then enclose it in single quotes. If you do not specify Expression2 , it defaults to a single blank. Operand or column can be of type CHAR,VARCHAR2, NCHAR, or NVARCHAR2. |
Description
If Expression1
is of type CHAR or VARCHAR2, the data type returned is VARCHAR2. If Expression1
is of type NCHAR or NVARCHAR2, the data type returned is NVARCHAR2. The returned data type length is equal to the data type length of Expression1
.
If Expression1
is a data type defined with CHAR length semantics, the returned length is expressed in CHAR length semantics.
If either Expression1
or Expression2
is NULL, the result is NULL.
You can specify TT_CHAR, TT_VARCHAR, TT_NCHAR, and TT_NVARCHAR for Expression1
and Expression2
. If Expression1
is of type TT_CHAR or TT_VARCHAR, the data type returned is TT_VARCHAR. If Expression1
is of type TT_NCHAR or TT_NVARCHAR, the data type returned is TT_NVARCHAR.
If Expression1
is of type CHAR or VARCHAR2 and Expression2
is of type NCHAR or NVARCHAR2, then Expression2
is demoted to CHAR or VARCHAR2 before RTRIM is invoked. The conversion of Expression2
could be lost. If the trim character of Expression2
is not in the database character set, then the query may produce unexpected results.
For CHAR, VARCHAR2, NCHAR, and NVARCHAR2 types:
If all the characters in Expression1
are removed by the RTRIM function, then the result is NULL.
For TT_CHAR, TT_VARCHAR, TT_NCHAR and TT_NVARCHAR types:
If all the characters in Expression1
are removed by the RTRIM function, then the result is the empty string.
Examples
The following example trims the trailing spaces from col1
in table rtrimtest
.
Command> CREATE TABLE rtrimtest (col1 VARCHAR2 (25)); Command> INSERT INTO rtrimtest VALUES ('abc '); 1 row inserted. Command> SELECT * FROM rtrimtest; < abc > 1 row found. Command> SELECT RTRIM (col1) FROM rtrimtest; < abc > 1 row found.
Call the RTRIM function to remove right-most 'x' and 'y' from string. RTRIM removes individual occurrences of 'x' and 'y' not pattern 'xy'.
Command> SELECT RTRIM ('RTRIM Examplexxxyyyxyxy', 'xy') FROM dual; < RTRIM Example > 1 row found.
Call RTRIM to remove all characters from Expression1
. In the first example, the data type is CHAR, so NULL is returned. In the second example, the data type is TT_CHAR, so the empty string is returned.
Command> CREATE TABLE rtrimtest (col1 CHAR (4), col2 TT_CHAR (4)); Command> INSERT INTO rtrimtest VALUES ('BBBA', 'BBBA'); 1 row inserted. Command> SELECT RTRIM (col1, 'AB') FROM rtrimtest; < <NULL> > 1 row found. Command> SELECT RTRIM (col2, 'AB') FROM rtrimtest; < > 1 row found.