oracle数字函数和转换函数

来源:互联网 发布:linux sh for循环 编辑:程序博客网 时间:2024/05/22 15:18
1,取整函数(ceil 向上取整,floor 向下取整)
   select ceil(66.6) N1,floor(66.6) N2 from dual;

2, 取幂(power) 和 求平方根(sqrt)
   select power(3,2) N1,sqrt(9) N2 from dual;

3,求余
   select mod(9,5) from dual;

4,返回固定小数位数 (round:四舍五入,trunc:直接截断)
   select round(66.667,2) N1,trunc(66.667,2) N2 from dual; 

5,返回值的符号(正数返回为1,负数为-1)

   select sign(-32),sign(293) from dual;



1,to_char()[将日期和数字类型转换成字符类型]
   1) select to_char(sysdate) s1,
        to_char(sysdate,'yyyy-mm-dd') s2,
        to_char(sysdate,'yyyy') s3,
        to_char(sysdate,'yyyy-mm-dd hh12:mi:ss') s4,
        to_char(sysdate, 'hh24:mi:ss') s5,
        to_char(sysdate,'DAY') s6 
    from dual;
   2) select sal,to_char(sal,'$99999') n1,to_char(sal,'$99,999') n2 from emp

2, to_date()[将字符类型转换为日期类型] 
    insert into emp(empno,hiredate) values(8000,to_date('2004-10-10','yyyy-mm-dd'));

3, to_number() 转换为数字类型 
    select to_number(to_char(sysdate,'hh12')) from dual; //以数字显示的小时数

0 0
原创粉丝点击