I am only required to do RTRIM()
in some part of query but if i do TRIM() will that affect performance.
Is Trim()
Slower/Faster/Exactly same(NOT even has negligible difference)
compared to RTRIM()
AND LTRIM()
?
This is with respect to Oracle 10g ONLY.
But in case of SQL Server 2005,
Do we have function / method 'x()' such that it can replace RTRIM(LTRIM(' blah.. blah.. '))
to a single function ?
I simply mean of having "single" function for doing the same functionality what both RTRIM()
AND LTRIM()
does.
TRIM has one advantage over LTRIM and RTRIM — it can remove a single character from both ends of the string. LTRIM and RTRIM operate on only one end of the string.
SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string.
Returns a Variant (String) containing a copy of a specified string without leading spaces (LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim). Syntax. LTrim ( string )
In LTrim() function a string will be pass as a parameter and it will return the string with no leading spaces. 2. RTrim() Function : It works same like LTrim() function but it will remove all trailing spaces from a string.
Based on this rough test there is a small difference:
DECLARE
n PLS_INTEGER := DBMS_UTILITY.get_time;
s1 VARCHAR2(32767);
s2 VARCHAR2(32767);
BEGIN
s1 := 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: 0
LTRIM: 113
RTRIM: 103
TRIM: 8
Baseline: 0
LTRIM: 136
RTRIM: 133
TRIM: 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With