今天碰到oracle三个函数trim、trunc、decode,将体会记录下来,以供日后查阅方便。
今天碰到oracle三个函数trim、trunc、decode,将体会记录下来,,以供日后查阅方便。
1.trim函数:用于出去字符串行首和行尾的空格。
select trim(' yichangzyh ') trim e.g.
from dual;
trim e.g.
yichangzyh
2.trunc函数:截断函数。
select trunc(sysdate) 截取到当天,
trunc(sysdate,'year') 截取到年第一天,
trunc(sysdate,'month') 截取到月第一天,
trunc(sysdate,'day') 截取到周第一天,
trunc(sysdate,'hh24') 截取到小时(0分0秒),
trunc(sysdate,'mi') 截取到分钟(0秒)
from dual;
截取到当天, 截取到年第一天, 截取到月第一天, 截取到周第一天, 截取到小时(0分0秒), 截取到分钟(0秒)
2013-2-20, 2013-1-1, 2013-2-1, 2013-2-17, 2013-2-20 17:00:00, 2013-2-20 17:02:00
3.decode函数:条件判断。
decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)
该函数的含义如下:
if 条件=值1 then
return(翻译值1)
elsif 条件=值2 then
return(翻译值2)
......
elsif 条件=值n then
return(翻译值n)
else
return(缺省值)
end if