提交 d5dbc2a3 authored 作者: Thomas Mueller's avatar Thomas Mueller

REPLACE: if any parameter is null, the result is null.

上级 3f04419e
...@@ -2756,6 +2756,7 @@ REGEXP_REPLACE(inputString, regexString, replacementString) ...@@ -2756,6 +2756,7 @@ REGEXP_REPLACE(inputString, regexString, replacementString)
"," ","
Replaces each substring that matches a regular expression. Replaces each substring that matches a regular expression.
For details, see the Java String.replaceAll() method. For details, see the Java String.replaceAll() method.
If any parameter is null, the result is null.
"," ","
REGEXP_REPLACE('Hello World', ' +', ' ') REGEXP_REPLACE('Hello World', ' +', ' ')
" "
...@@ -2773,6 +2774,7 @@ REPLACE(string, searchString [, replacementString]) ...@@ -2773,6 +2774,7 @@ REPLACE(string, searchString [, replacementString])
"," ","
Replaces all occurrences of a search string in a text with another string. Replaces all occurrences of a search string in a text with another string.
If no replacement is specified, the search string is removed from the original string. If no replacement is specified, the search string is removed from the original string.
If any parameter is null, the result is null.
"," ","
REPLACE(NAME, ' ') REPLACE(NAME, ' ')
" "
......
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Queries with DISTINCT and ORDER BY will now use the index on ORDER BY if possible. <ul><li>H2 Console: the built-in commands are now documented.
</li><li>REPLACE: if any parameter is null, the result is null.
</li><li>Queries with DISTINCT and ORDER BY will now use the index on ORDER BY if possible.
This is specially important for queries used inside IN(SELECT ...). This is specially important for queries used inside IN(SELECT ...).
</li><li>The new statement EXPLAIN ANALYZE executes the statement, </li><li>The new statement EXPLAIN ANALYZE executes the statement,
and displays the query plan with the actual row scan count for each table. and displays the query plan with the actual row scan count for each table.
......
...@@ -220,7 +220,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -220,7 +220,7 @@ public class Function extends Expression implements FunctionCall {
addFunction("OCTET_LENGTH", OCTET_LENGTH, 1, Value.LONG); addFunction("OCTET_LENGTH", OCTET_LENGTH, 1, Value.LONG);
addFunction("RAWTOHEX", RAWTOHEX, 1, Value.STRING); addFunction("RAWTOHEX", RAWTOHEX, 1, Value.STRING);
addFunction("REPEAT", REPEAT, 2, Value.STRING); addFunction("REPEAT", REPEAT, 2, Value.STRING);
addFunctionWithNull("REPLACE", REPLACE, VAR_ARGS, Value.STRING); addFunction("REPLACE", REPLACE, VAR_ARGS, Value.STRING);
addFunction("RIGHT", RIGHT, 2, Value.STRING); addFunction("RIGHT", RIGHT, 2, Value.STRING);
addFunction("RTRIM", RTRIM, VAR_ARGS, Value.STRING); addFunction("RTRIM", RTRIM, VAR_ARGS, Value.STRING);
addFunction("SOUNDEX", SOUNDEX, 1, Value.STRING); addFunction("SOUNDEX", SOUNDEX, 1, Value.STRING);
...@@ -945,9 +945,9 @@ public class Function extends Expression implements FunctionCall { ...@@ -945,9 +945,9 @@ public class Function extends Expression implements FunctionCall {
break; break;
} }
case REPLACE: { case REPLACE: {
String s0 = v0 == ValueNull.INSTANCE ? "" : v0.getString(); String s0 = v0.getString();
String s1 = v1 == ValueNull.INSTANCE ? "" : v1.getString(); String s1 = v1.getString();
String s2 = (v2 == null || v2 == ValueNull.INSTANCE) ? "" : v2.getString(); String s2 = (v2 == null) ? "" : v2.getString();
result = ValueString.get(replace(s0, s1, s2)); result = ValueString.get(replace(s0, s1, s2));
break; break;
} }
...@@ -1313,7 +1313,10 @@ public class Function extends Expression implements FunctionCall { ...@@ -1313,7 +1313,10 @@ public class Function extends Expression implements FunctionCall {
} }
private static String replace(String s, String replace, String with) { private static String replace(String s, String replace, String with) {
if (replace == null || replace.length() == 0) { if (s == null || replace == null || with == null) {
return null;
}
if (replace.length() == 0) {
// avoid out of memory // avoid out of memory
return s; return s;
} }
......
...@@ -8825,9 +8825,9 @@ select repeat(null, null) en, repeat('Ho', 2) abcehoho , repeat('abc', 0) ee fro ...@@ -8825,9 +8825,9 @@ select repeat(null, null) en, repeat('Ho', 2) abcehoho , repeat('abc', 0) ee fro
> rows: 1 > rows: 1
select replace(null, null) en, replace(null, null, null) en1 from test; select replace(null, null) en, replace(null, null, null) en1 from test;
> EN EN1 > EN EN1
> -- --- > ---- ----
> > null null
> rows: 1 > rows: 1
select replace('abchihihi', 'i', 'o') abcehohoho, replace('that is tom', 'i') abcethstom from test; select replace('abchihihi', 'i', 'o') abcehohoho, replace('that is tom', 'i') abcethstom from test;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论