gpt4 book ai didi

sql - ORACLE SQL CAST IN CASE 语句

转载 作者:行者123 更新时间:2023-12-02 03:35:21 24 4
gpt4 key购买 nike

有没有办法在 CASE 语句中将 CAST 转换为 INTEGER?

CASE 
WHEN SV.END_DATE IS NOT NULL THEN SV.END_DATE - SV.START_DATE
ELSE 0
END AS DAYDIFF

最佳答案

是的,你可以 cast不带小数部分的数字数据类型的值:

CASE 
WHEN SV.END_DATE IS NOT NULL THEN
CAST(SV.END_DATE - SV.START_DATE AS NUMBER(38))
ELSE 0
END AS DAYDIFF

或者你可以truncate the result ,它还会去除值的小数部分:

CASE 
WHEN SV.END_DATE IS NOT NULL THEN
TRUNC(SV.END_DATE - SV.START_DATE)
ELSE 0
END AS DAYDIFF

关于sql - ORACLE SQL CAST IN CASE 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50395415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com