oracle TRIM RTRIM LTRIM 性能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4141763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TRIM RTRIM LTRIM Performance
提问by Pratik
I am only required to do RTRIM()
in some part of query but if i do TRIM() will that affect performance.
我只需要RTRIM()
在查询的某些部分做,但如果我做 TRIM() 会影响性能。
Is Trim()
Slower/Faster/Exactly same(NOT even has negligible difference)
compared to RTRIM()
AND LTRIM()
?
Trim()
与RTRIM()
AND相比是否更慢/更快/完全相同(甚至没有可以忽略的差异)LTRIM()
?
This is with respect to Oracle 10g ONLY.
这仅适用于 Oracle 10g。
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 ?
但是在 SQL Server 2005 的情况下,我们是否有函数/方法 'x()' 以便它可以替换RTRIM(LTRIM(' blah.. blah.. '))
为单个函数?
I simply mean of having "single" function for doing the same functionality what both RTRIM()
AND LTRIM()
does.
我只是想拥有“单一”功能来执行与RTRIM()
AND相同的功能LTRIM()
。
采纳答案by Jeffrey Kemp
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:
在最坏的情况下,差异高达 0.000128 百分之一秒:
Baseline: 0
LTRIM: 113
RTRIM: 103
TRIM: 8
Baseline: 0
LTRIM: 136
RTRIM: 133
TRIM: 8
回答by Jeffrey Kemp
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.
性能差异通常是无法检测到的,尤其是在从表中获取数据的查询中。选择适合您的要求。
回答by Ed Harper
The question is irrelevant for SQL Server, since it implements LTRIM
and RTRIM
but not TRIM
.
这个问题与 SQL Server 无关,因为它实现了LTRIM
andRTRIM
但不是TRIM
.
See the list of SQL 2005 string functions.
请参阅SQL 2005 字符串函数列表。
回答by Saif Khan
I've never seen anything like a benchmark on the Trims in SQL Server. I've used it a lot and do find some minor performance when dealing with lots of data...minor performance.
我从来没有见过像 SQL Server 中的 Trims 的基准测试。我已经使用了很多,并且在处理大量数据时确实发现了一些次要性能......次要性能。