Oracle中的date日期型:
select sysdate from 任意表名 显示当前系统时间
转换函数
一:
to_date()函数
to_date('05/30/08 13:30:30','mm/dd/yy hh24:mi:ss');
二
to_number()
三
to_char()
1. 日期-》字符
to_char(Date);
to_char(Date,’yyyy-mm-dd’);
2. 数字-》字符
to_char(number,’format’);
to_char(12345,678901,’$99,999.0000’);结果$12.345.6789
数字模式符:
格式符 说明
9 代表一位数字
0 代表一位数字,强制显示0
$ 放置一个美元符
L 放置一个本地货币符
. 小数点
, 千位指示符
通用函数
一:NVL()函数
NVL(exp1,exp2)//如果exp1的值为null,则返回exp2的值
二:NVL2()函数
NVL2(exp1,exp2,exp3)
如果exp1的值不为null,则返回exp2的值,否则返回exp3的值
三:NULLIF()函数
nullif(exp1,exp2)
如果exp1与exp2的值相等则返回null,否则返回exp1的值
四:COALESCE()函数
coalesce(exp1,exp2,…)
依次考察各参数,遇到非null值即停止并返回该值。如果没有遇到返回null
五:CASE表达式
case exp
when config_exp1 then return_exp1
when config_exp2 then return_exp2
when config_exp3 then return_exp3
else else_exp
end
六:DECODE()函数
类似CASE();
Decode(exp,
config_exp1,return_exp1,
config_exp2,return_exp2,
config_exp3,return_exp3,
else_exp)
select sysdate from 任意表名 显示当前系统时间
转换函数
一:
to_date()函数
to_date('05/30/08 13:30:30','mm/dd/yy hh24:mi:ss');
二
to_number()
三
to_char()
1. 日期-》字符
to_char(Date);
to_char(Date,’yyyy-mm-dd’);
2. 数字-》字符
to_char(number,’format’);
to_char(12345,678901,’$99,999.0000’);结果$12.345.6789
数字模式符:
格式符 说明
9 代表一位数字
0 代表一位数字,强制显示0
$ 放置一个美元符
L 放置一个本地货币符
. 小数点
, 千位指示符
通用函数
一:NVL()函数
NVL(exp1,exp2)//如果exp1的值为null,则返回exp2的值
二:NVL2()函数
NVL2(exp1,exp2,exp3)
如果exp1的值不为null,则返回exp2的值,否则返回exp3的值
三:NULLIF()函数
nullif(exp1,exp2)
如果exp1与exp2的值相等则返回null,否则返回exp1的值
四:COALESCE()函数
coalesce(exp1,exp2,…)
依次考察各参数,遇到非null值即停止并返回该值。如果没有遇到返回null
五:CASE表达式
case exp
when config_exp1 then return_exp1
when config_exp2 then return_exp2
when config_exp3 then return_exp3
else else_exp
end
六:DECODE()函数
类似CASE();
Decode(exp,
config_exp1,return_exp1,
config_exp2,return_exp2,
config_exp3,return_exp3,
else_exp)
本文介绍了Oracle数据库中处理日期的技巧,包括如何使用to_date、to_number和to_char函数进行日期格式转换,并详细解释了NVL、NVL2、NULLIF及COALESCE等通用函数的功能与用法。

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



