Decode函数的语法结构如下: decode (expression, search_1, result_1, search_2, result_2,... ., search_n, result_n, default) decode函数比较表达式和搜索字,如果匹配,返回结果;如果不匹配,返回default值;如果未定义default值,则返回空值。
示例如下:
select decode( x , 1 , ‘x is 1 ’, 2 , ‘x is 2 ’, ‘others’) from dual
当x等于1时,则返回‘x is 1’。
当x等于2时,则返回‘x is 2’。
否则,返回others’。
select id as aa,decode(id,'1','Y','2','N','3','s','sdfsd') as a from queryinfo示例如下:
select decode( x , 1 , ‘x is 1 ’, 2 , ‘x is 2 ’, ‘others’) from dual
当x等于1时,则返回‘x is 1’。
当x等于2时,则返回‘x is 2’。
否则,返回others’。
本文详细介绍了SQL中的Decode函数,包括其语法结构及使用方法。通过示例展示了如何利用该函数进行条件判断并返回相应结果。
19万+

被折叠的 条评论
为什么被折叠?



