Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4a961775
提交
4a961775
authored
11月 22, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Oracle compatibility: support for DECODE(...).
上级
a4f34782
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
59 行增加
和
2 行删除
+59
-2
help.csv
h2/src/docsrc/help/help.csv
+10
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+33
-2
testSimple.in.txt
h2/src/test/org/h2/test/testSimple.in.txt
+16
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
4a961775
...
@@ -3510,6 +3510,16 @@ Returns NULL otherwise.
...
@@ -3510,6 +3510,16 @@ Returns NULL otherwise.
CALL DATABASE_PATH();
CALL DATABASE_PATH();
"
"
"Functions (System)","DECODE","
DECODE(value, whenValue, thenValue,...)
","
Returns the first matching value. NULL is considered to match NULL.
If no match was found, then NULL or the last parameter (if the parameter count is even) is returned.
This function is provided for Oracle compatibility (see there for details).
","
CALL DECODE(RAND()>0.5, 0, 'Red', 1, 'Black');
"
"Functions (System)","FILE_READ","
"Functions (System)","FILE_READ","
FILE_READ(fileNameString [,encodingString])
FILE_READ(fileNameString [,encodingString])
","
","
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
4a961775
...
@@ -95,7 +95,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -95,7 +95,7 @@ public class Function extends Expression implements FunctionCall {
CASE
=
206
,
NEXTVAL
=
207
,
CURRVAL
=
208
,
ARRAY_GET
=
209
,
CSVREAD
=
210
,
CSVWRITE
=
211
,
CASE
=
206
,
NEXTVAL
=
207
,
CURRVAL
=
208
,
ARRAY_GET
=
209
,
CSVREAD
=
210
,
CSVWRITE
=
211
,
MEMORY_FREE
=
212
,
MEMORY_USED
=
213
,
LOCK_MODE
=
214
,
SCHEMA
=
215
,
SESSION_ID
=
216
,
ARRAY_LENGTH
=
217
,
MEMORY_FREE
=
212
,
MEMORY_USED
=
213
,
LOCK_MODE
=
214
,
SCHEMA
=
215
,
SESSION_ID
=
216
,
ARRAY_LENGTH
=
217
,
LINK_SCHEMA
=
218
,
GREATEST
=
219
,
LEAST
=
220
,
CANCEL_SESSION
=
221
,
SET
=
222
,
TABLE
=
223
,
TABLE_DISTINCT
=
224
,
LINK_SCHEMA
=
218
,
GREATEST
=
219
,
LEAST
=
220
,
CANCEL_SESSION
=
221
,
SET
=
222
,
TABLE
=
223
,
TABLE_DISTINCT
=
224
,
FILE_READ
=
225
,
TRANSACTION_ID
=
226
,
TRUNCATE_VALUE
=
227
,
NVL2
=
228
;
FILE_READ
=
225
,
TRANSACTION_ID
=
226
,
TRUNCATE_VALUE
=
227
,
NVL2
=
228
,
DECODE
=
229
;
public
static
final
int
ROW_NUMBER
=
300
;
public
static
final
int
ROW_NUMBER
=
300
;
...
@@ -334,6 +334,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -334,6 +334,7 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"SET"
,
SET
,
2
,
Value
.
NULL
,
false
,
false
,
false
);
addFunction
(
"SET"
,
SET
,
2
,
Value
.
NULL
,
false
,
false
,
false
);
addFunction
(
"FILE_READ"
,
FILE_READ
,
VAR_ARGS
,
Value
.
NULL
,
false
,
false
,
false
);
addFunction
(
"FILE_READ"
,
FILE_READ
,
VAR_ARGS
,
Value
.
NULL
,
false
,
false
,
false
);
addFunctionNotDeterministic
(
"TRANSACTION_ID"
,
TRANSACTION_ID
,
0
,
Value
.
STRING
);
addFunctionNotDeterministic
(
"TRANSACTION_ID"
,
TRANSACTION_ID
,
0
,
Value
.
STRING
);
addFunctionWithNull
(
"DECODE"
,
DECODE
,
VAR_ARGS
,
Value
.
NULL
);
// TableFunction
// TableFunction
addFunctionWithNull
(
"TABLE"
,
TABLE
,
VAR_ARGS
,
Value
.
RESULT_SET
);
addFunctionWithNull
(
"TABLE"
,
TABLE
,
VAR_ARGS
,
Value
.
RESULT_SET
);
...
@@ -778,6 +779,20 @@ public class Function extends Expression implements FunctionCall {
...
@@ -778,6 +779,20 @@ public class Function extends Expression implements FunctionCall {
result
=
v
.
convertTo
(
dataType
);
result
=
v
.
convertTo
(
dataType
);
break
;
break
;
}
}
case
DECODE:
{
Expression
expr
=
null
;
for
(
int
i
=
1
;
i
<
argList
.
length
-
1
;
i
+=
2
)
{
if
(
database
.
areEqual
(
v0
,
argList
[
i
].
getValue
(
session
)))
{
expr
=
argList
[
i
+
1
];
}
}
if
(
expr
==
null
&&
argList
.
length
%
2
==
0
)
{
expr
=
argList
[
argList
.
length
-
1
];
}
Value
v
=
expr
==
null
?
ValueNull
.
INSTANCE
:
expr
.
getValue
(
session
);
result
=
v
.
convertTo
(
dataType
);
break
;
}
case
NVL2:
{
case
NVL2:
{
Expression
expr
;
Expression
expr
;
if
(
v0
==
ValueNull
.
INSTANCE
)
{
if
(
v0
==
ValueNull
.
INSTANCE
)
{
...
@@ -1637,6 +1652,9 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1637,6 +1652,9 @@ public class Function extends Expression implements FunctionCall {
min
=
1
;
min
=
1
;
max
=
2
;
max
=
2
;
break
;
break
;
case
DECODE:
min
=
3
;
break
;
default
:
default
:
DbException
.
throwInternalError
(
"type="
+
info
.
type
);
DbException
.
throwInternalError
(
"type="
+
info
.
type
);
}
}
...
@@ -1692,12 +1710,24 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1692,12 +1710,24 @@ public class Function extends Expression implements FunctionCall {
case
NULLIF:
case
NULLIF:
case
COALESCE:
case
COALESCE:
case
LEAST:
case
LEAST:
case
GREATEST:
{
case
GREATEST:
case
DECODE:
{
t
=
Value
.
UNKNOWN
;
t
=
Value
.
UNKNOWN
;
s
=
0
;
s
=
0
;
p
=
0
;
p
=
0
;
d
=
0
;
d
=
0
;
int
i
=
0
;
for
(
Expression
e
:
args
)
{
for
(
Expression
e
:
args
)
{
if
(
info
.
type
==
DECODE
)
{
if
(
i
<
2
||
((
i
%
2
==
1
)
&&
(
i
!=
args
.
length
-
1
)))
{
// decode(a, b, whenB)
// decode(a, b, whenB, else)
// decode(a, b, whenB, c, whenC)
// decode(a, b, whenB, c, whenC, end)
i
++;
continue
;
}
}
if
(
e
!=
ValueExpression
.
getNull
())
{
if
(
e
!=
ValueExpression
.
getNull
())
{
int
type
=
e
.
getType
();
int
type
=
e
.
getType
();
if
(
type
!=
Value
.
UNKNOWN
&&
type
!=
Value
.
NULL
)
{
if
(
type
!=
Value
.
UNKNOWN
&&
type
!=
Value
.
NULL
)
{
...
@@ -1707,6 +1737,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1707,6 +1737,7 @@ public class Function extends Expression implements FunctionCall {
d
=
Math
.
max
(
d
,
e
.
getDisplaySize
());
d
=
Math
.
max
(
d
,
e
.
getDisplaySize
());
}
}
}
}
i
++;
}
}
if
(
t
==
Value
.
UNKNOWN
)
{
if
(
t
==
Value
.
UNKNOWN
)
{
t
=
Value
.
STRING
;
t
=
Value
.
STRING
;
...
...
h2/src/test/org/h2/test/testSimple.in.txt
浏览文件 @
4a961775
select select decode(null, null, 'a');
> a;
select select decode(1, 1, 'a');
> a;
select select decode(1, 2, 'a');
> null;
select select decode(1, 1, 'a', 'else');
> a;
select select decode(1, 2, 'a', 'else');
> else;
select decode(4.0, 2.0, 2.0, 3.0, 3.0);
> null;
select decode('3', 2.0, 2.0, 3, 3.0);
> 3.0;
select decode(4.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 9.0);
> 4.0;
select * from (select group_concat(distinct 1) from system_range(1, 3));
select * from (select group_concat(distinct 1) from system_range(1, 3));
> 1;
> 1;
select sum(mod(x, 2) = 1) from system_range(1, 10);
select sum(mod(x, 2) = 1) from system_range(1, 10);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论