sql - SQL中解码函数内部的解码函数
问题描述
下面的sql语句是什么打印出来的,请解释一下:
SELECT DECODE (2, 2, DECODE(3, 7, 2, 4, 5, 6)) FROM DUAL
我只了解解码功能,但想确保我对解码功能中的解码的回答
解决方案
它打印一个 6。
语法为 DECODE( 表达式 , 搜索 , 结果 [, 搜索 , 结果]... [, 默认] )
In your example
In the first DECODE 2 is the expression
the next 2 is what the first 2 will be compared to
the next DECODE is the result if 2 = 2
In the second DECODE 3 is the expression
It is compared to the 7 and the 4.
The results could be 2 or 5
Finally if the 3 doesn't match the 7 or the 4 then 6 is the result.
IF 2 = 2 THEN
IF 3 = 7 THEN
2
ELSIF 3 = 4 THEN
5
ELSE 6
END IF
推荐阅读
- python - 在python中有条件地更改类实例属性
- sql - 在 postgresql 中删除重复的行
- javascript - 在单击时重新插入的元素上使用Parents()
- javascript - 聊天系统的滚动条一直自动向下滚动
- reactjs - 如何使用 Context 传递 useReducer 状态?- 反应原生
- java - 有没有办法设置下拉高度的限制?或者甚至对下拉列表中显示的项目设置限制?
- perl - 在 Template Toolkit 中按值而不是键对哈希引用进行排序
- c++ - 在应用程序终止时关闭 COM 端口
- kubernetes - 有没有像 Istio 这样支持 LXC 容器的服务网格实现?
- javascript - 如果在 textarea 中输入空格,则 Make 按钮将被禁用