Oracle Trim Function
Oracle 2013. 11. 15. 18:39TRIM
Description of the illustration trim.gif
TRIM
enables you to trim leading or trailing characters (or both) from a character string. If trim_character
or trim_source
is a character literal, then you must enclose it in single quotation marks.
If you specify
LEADING
, then Oracle Database removes any leading characters equal totrim_character
.If you specify
TRAILING
, then Oracle removes any trailing characters equal totrim_character
.If you specify
BOTH
or none of the three, then Oracle removes leading and trailing characters equal totrim_character
.If you do not specify
trim_character
, then the default value is a blank space.If you specify only
trim_source
, then Oracle removes leading and trailing blank spaces.The function returns a value with datatype
VARCHAR2
. The maximum length of the value is the length oftrim_source
.If either
trim_source
ortrim_character
is null, then theTRIM
function returns null.
Both trim_character
and trim_source
can be VARCHAR2
or any datatype that can be implicitly converted to VARCHAR2
. The string returned is of VARCHAR2
datatype if trim_source
is a character datatype and a LOB if trim_source
is a LOB datatype. The return string is in the same character set as trim_source
.
This example trims leading zeros from the hire date of the employees in the hr
schema:
SELECT employee_id, TO_CHAR(TRIM(LEADING 0 FROM hire_date)) FROM employees WHERE department_id = 60 ORDER BY employee_id; EMPLOYEE_ID TO_CHAR(T ----------- --------- 103 3-JAN-90 104 21-MAY-91 105 25-JUN-97 106 5-FEB-98 107 7-FEB-99
LTRIM
Description of the illustration ltrim.gif
LTRIM
removes from the left end of char
all of the characters contained in set
. If you do not specify set
, then it defaults to a single blank. If char
is a character literal, then you must enclose it in single quotation marks. Oracle Database begins scanning char
from its first character and removes all characters that appear in set
until reaching a character not in set
and then returns the result.
Both char
and set
can be any of the datatypes CHAR
, VARCHAR2
, NCHAR
, NVARCHAR2
, CLOB
, or NCLOB
. The string returned is of VARCHAR2
datatype if char
is a character datatype, NVARCHAR2
if char
is a national character datatype, and a LOB if char
is a LOB datatype.
Examples
The following example trims the redundant first word from a group of product names in the oe.products
table:
SELECT product_name, LTRIM(product_name, 'Monitor ') "Short Name" FROM products WHERE product_name LIKE 'Monitor%'; PRODUCT_NAME Short Name -------------------- --------------- Monitor 17/HR 17/HR Monitor 17/HR/F 17/HR/F Monitor 17/SD 17/SD Monitor 19/SD 19/SD Monitor 19/SD/M 19/SD/M Monitor 21/D 21/D Monitor 21/HR 21/HR Monitor 21/HR/M 21/HR/M Monitor 21/SD 21/SD Monitor Hinge - HD Hinge - HD Monitor Hinge - STD Hinge - STD
RTRIM
Description of the illustration rtrim.gif
RTRIM
removes from the right end of char
all of the characters that appear in set
. This function is useful for formatting the output of a query.
If you do not specify set
, then it defaults to a single blank. If char
is a character literal, then you must enclose it in single quotation marks. RTRIM
works similarly to LTRIM
.
Both char
and set
can be any of the datatypes CHAR
, VARCHAR2
, NCHAR
, NVARCHAR2
, CLOB
, or NCLOB
. The string returned is of VARCHAR2
datatype if char
is a character datatype, NVARCHAR2
if expr1
is a national character datatype, and a LOB if char
is a LOB datatype.
Examples
The following example trims all the right-most occurrences of period, slash, and equal sign from a string:
SELECT RTRIM('BROWNING: ./=./=./=./=./=.=','/=.') "RTRIM example" FROM DUAL; RTRIM exam ---------- BROWNING:
reference : Oracle® Database SQL Language Reference - Oracle11gR1
그동안 너무 RTRM과 LTRIM만 사용한듯....
'Oracle' 카테고리의 다른 글
ORA-609 Error (11.1.0.6 to 11.2.0.3) (0) | 2014.02.12 |
---|---|
Oracle 11g Enterprise Option 내용 (0) | 2014.02.12 |
Benefits and consequences of the NOLOGGING option (0) | 2013.11.01 |
Certification Information for Oracle Database on Microsoft Windows x64 (64-bit) (0) | 2013.08.29 |
[Oracle] Current Interoperability Support Situation (0) | 2013.08.29 |