1、数字函数
1)、mod(m,n)该函数用于返回取得两个数字相除后的余数,如果数字为0,则返回结果为m。
(2)、round(n,[m]该函数用于取得四舍五入运算,如果省略m,则四舍五入至整数位;如果m是负数,则四舍五入到小数点前m位;如果m是正数,则四舍五入到小数点后m位。
(3)、trunc(n,[m])该函数用于截取数字,如果省略m,则将数字n的小数部门截取;如果m为正数,则将数字n截取至小数点后的第m位,如果m为负数,则将数字n截取小数点的前m为。
示例如下:
select mod(10,4)
from dual;
select round(101234.567,-4)
from dual;
select round(101.234567,4)
from dual;
select trunc(101234.457,2)
from dual;
select trunc(101234.457,-2)
from dual;
2、日期函数
(1)、round(d,[fmt])该函数用于返回日期时间的四舍五入结果,如果fmt指定年度,则7月1日为分割线;如果fmt指定月,则16日为分割线;如果fmt指定为天,则中午12:00为分割线。
(2)、trunc(d,[fmt])该函数用于截取日期时间数据,如果fmt指定年度,则结果为本年度的1月1日,如果fmt指定月,则结果为本月1日。
示例如下:
select round(sysdate,'yyyy') from
dual;
select round(sysdate,'mm') from
dual;
select round(sysdate,'dd') from
dual;
select trunc(sysdate,'yyyy') from
dual;
select trunc(sysdate,'mm') from
dual;
select trunc(sysdate,'dd') from
dual;
3、转换函数
(1)、to_char(date,fmt)该函数用于将日期类型转换为字符串类型,其中fmt用于指定日期格式。
(2)、to_date(char,fmt)该函数用于将符合特定日期格式的字符串转变为date类型的值。
(3)、to_number(char)该函数用于将符合特定数字格式的字符串转换为数字类型。
示例如下:
select to_date('2009-3-1','yyyy-mm-dd')
from dual;
select to_char(sysdate,'YYYY-MM-DD
HH24:MI:SS') from dual;
select to_number('10.123') from
dual;
4、其他单行函数
(1)、decode(expr,search1,result1[,search2,result2,...],default)该函数用于返回匹配于特定表达式结果,如果search1匹配与expr,则返回结果result1,如果search2匹配expr,则返回结果result2,以此类推,如果没有任何匹配关系,则返回默认default。
示例如下:
select name,decode(age,'bb21',id*10,'bb22',id*20,1000)
as decodee from cip_temps;
注意:decode函数和case表达式的用法基本相似,但是case表达式可以多个条件进行判断,从而返回结果。
示例如下:
select name,case when
(
(age='bb21' and
address='cc21')
or (age='bb22' and
address='cc22')
or (age='bb23' and
address='cc23')
) then 1 else
0 end as cases from
cip_temps