TRIM RTRIM LTRIM Performance
Based on this rough test there is a small difference:
DECLAREn PLS_INTEGER := DBMS_UTILITY.get_time;s1 VARCHAR2(32767);s2 VARCHAR2(32767);BEGINs1 := LPAD('X',15000,' ') || RPAD('X',15000,' ');FOR i IN 1..1000000 LOOP NULL;END LOOP;DBMS_OUTPUT.put_line('Baseline: ' || (DBMS_UTILITY.get_time - n));n := DBMS_UTILITY.get_time;FOR i IN 1..1000000 LOOP s2 := LTRIM(s1);END LOOP;DBMS_OUTPUT.put_line('LTRIM: ' || (DBMS_UTILITY.get_time - n));n := DBMS_UTILITY.get_time;FOR i IN 1..1000000 LOOP s2 := RTRIM(s1);END LOOP;DBMS_OUTPUT.put_line('RTRIM: ' || (DBMS_UTILITY.get_time - n));n := DBMS_UTILITY.get_time;FOR i IN 1..1000000 LOOP s2 := TRIM(s1);END LOOP;DBMS_OUTPUT.put_line('TRIM: ' || (DBMS_UTILITY.get_time - n));END;
The difference amounts to up to 0.000128 hundredth's of a second in the worst case:
Baseline: 0LTRIM: 113RTRIM: 103TRIM: 8Baseline: 0LTRIM: 136RTRIM: 133TRIM: 8
The difference in performance will generally be undetectable, especially if it's within a query that gets its data from a table. Choose whichever fits your requirements.
The question is irrelevant for SQL Server, since it implements LTRIM
and RTRIM
but not TRIM
.
See the list of SQL 2005 string functions.