提交 4509a848 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved Oracle compatibility for NVL2. Thanks again to litailang for the patch.

上级 056c7d4e
......@@ -3602,6 +3602,7 @@ NULLIF(A, B)
NVL2(testValue, aValue, bValue)
","
If the test value is null, then 'b' is returned. Otherwise, 'a' is returned.
The data type of the returned value is the data type of 'a' if this is a text type.
","
NVL2(X, 'not null', 'null')
"
......
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>CSVREAD now supports the option 'preserveWhitespace'.
<ul><li>Improved Oracle compatibility for NVL2. Thanks again to litailang for the patch.
</li><li>CSVREAD now supports the option 'preserveWhitespace'.
</li><li>Recursive queries with many rows could throw an IndexOutOfBoundsException.
</li><li>The auto-server mode can't be combined with an in-memory database.
This invalid combination wasn't detected so far.
......
......@@ -1704,12 +1704,27 @@ public class Function extends Expression implements FunctionCall {
break;
}
case CASEWHEN:
case NVL2:
t = Value.getHigherOrder(args[1].getType(), args[2].getType());
p = Math.max(args[1].getPrecision(), args[2].getPrecision());
d = Math.max(args[1].getDisplaySize(), args[2].getDisplaySize());
s = Math.max(args[1].getScale(), args[2].getScale());
break;
case NVL2:
switch (args[1].getType()) {
case Value.STRING:
case Value.CLOB:
case Value.STRING_FIXED:
case Value.STRING_IGNORECASE:
t = args[1].getType();
break;
default:
t = Value.getHigherOrder(args[1].getType(), args[2].getType());
break;
}
p = Math.max(args[1].getPrecision(), args[2].getPrecision());
d = Math.max(args[1].getDisplaySize(), args[2].getDisplaySize());
s = Math.max(args[1].getScale(), args[2].getScale());
break;
case CAST:
case CONVERT:
case TRUNCATE_VALUE:
......
......@@ -115,6 +115,13 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals(ErrorCode.DATA_CONVERSION_ERROR_1, e.getErrorCode());
}
// nvl2 should return expr2's datatype, if expr2 is character data.
rs = stat.executeQuery("SELECT NVL2(1, 'test', 123), 'test' FROM dual");
rs.next();
actual = rs.getString(1);
assertEquals("test", actual);
assertEquals(rs.getMetaData().getColumnType(2), rs.getMetaData().getColumnType(1));
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论