一个值根据某个规则以另一种形式展现可用decode()方法,
decode(columnname,值1,翻译值1,值2,翻译值2,……缺省值)
举例:
表Test_user:
1、单个decode的使用
对所有用户类型为1的用户进行启用,用户类型不为1的,已被激活的启用,未被激活的禁用:
update test_user t set t.is_available=decode(t.user_type,'1','1',t.is_actived),t.is_actived=decode(t.user_type,'1','1',t.is_actived);
运行后结果:
2、decode()函数的嵌套使用
1中的sql语句也可以像下面这么写:下面这么写逻辑性更强
update test_user t set t.is_available=decode(t.user_type,'1','1',decode(t.is_actived,'0','0','1')),t.is_actived=decode(t.user_type,'1','1',t.is_actived);
本文详细介绍了SQL中的DECODE函数使用方法,包括单个DECODE函数的应用及嵌套使用技巧,帮助读者更好地理解并掌握该函数的功能。
1549

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



