oracle nvl,nvl2, nullif,以及类型强转函数cast
2023-04-18 15:51:54 时间
参考博客
https://www.cnblogs.com/xielong/p/9285147.html
官方文档 OLD:https://docs.oracle.com/database/121/SQLRF/functions131.htm#SQLRF00684
SELECT 0 AS t1 , 1 AS t2, 1.123456 AS t3, NULL AS t4, round((1234.123456- null )*100/nvl(0.1,1),2) t5, nvl(round((1234.123456 - 0 )*100/nullif(10,1),2), 1.123456) t6 , CAST (nvl(round((1234.123456 - 0 )*100/nullif(10,1),2), 1.123456) AS NUMBER(9,2)) t7, --NVL(expr1,expr2),若expr1为null, 返回expr2; 不为null,返回expr1。 注意:两者类型要一致 nvl(null, 0.1234) AS t8, --NVL2 (expr1, expr2, expr3),若expr1不为NULL,返回expr2 ;为NULL,返回expr3。注意:expr2 和expr3 类型不同的话,expr3 会转换为expr2 的类型 nvl2(0,1,2) AS t10, --NULL .NULLIF (expr1, expr2),若expr1和expr2相等,返回NULL;不相等,等返回expr1 nullif(1.123,1.123) AS t9 FROM upcenter.stk_basic_info WHERE rownum<=10;
--NVL(expr1,expr2),若expr1为null, 返回expr2; 不为null,返回expr1。 注意:两者类型要一致
nvl(null, 0.1234) AS t8,
--NVL2 (expr1, expr2, expr3),若expr1不为NULL,返回expr2 ;为NULL,返回expr3。注意:expr2 和expr3 类型不同的话,expr3 会转换为expr2 的类型
nvl2(0,1,2) AS t10,
--NULL .NULLIF (expr1, expr2),若expr1和expr2相等,返回NULL;不相等,等返回expr1
nullif(1.123,1.123) AS t9
这里T6返回的类型是Number(38,0) 但是结果却打印的是浮点数。oracle 此处返回的数据类型是不可靠的。
所以,遇到这种数据类型不可靠的情况,需要强制指定 数据类型。
使用 cast as
相关文章
- linux下MongoDB的使用教程
- ps闪退是什么原因
- linux下如何关闭mongodb服务
- 免费代理IP – 免费HTTP代理IP_SOCKS5代理服务器_优质IP代理2022/12/02 14:15:03
- postgresql乱码怎么办
- linux如何卸载postgresql
- postgresql是否支持json类型
- hadoop是什么
- 如何查看是否安装postgresql
- postgresql启动不了如何解决
- postgresql服务启动报错1053怎么解决
- postgresql怎么启动服务
- 怎样删除postgresql
- postgresql安装错误的原因是什么
- postgresql服务怎么安装启动
- 怎么判断postgresql是否存在
- postgresql启动不了怎么解决
- 如何彻底卸载postgresql
- linux下如何查看是否安装postgresql
- linux下postgresql怎么启动