zoukankan      html  css  js  c++  java
  • ORACLE自增函数,一般函数

    1.UNIX时间与普通时间互相转换

    1.ORACLE先创建函数方法,再直接使用,MySQL直接使用方法UNIX_TIMESTAMP,FROM_UNIXTIME

    oracle_to_unix(create_date)
    create or replace function oracle_to_unix(in_date in date) return number is
    begin
      return((in_date - to_date('19700101', 'yyyymmdd')) * 86400 -
             to_number(substr(tz_offset(sessiontimezone), 1, 3)) * 3600);
    end oracle_to_unix;
    unix_to_oracle(create_date)
    create or replace function unix_to_oracle(in_number number) return date is
    begin
      return (to_date('19700101','yyyymmdd') + in_number/86400
      + to_number(substr(tz_offset(sessiontimezone),1,3))/24);
    end unix_to_oracle;
    Exp:
    SELECT *
      FROM (SELECT mobile,
                   /*UNIX_TIMESTAMP(create_date) as create_date,*/
                   /*to_timestamp(create_date, 'yyyy-mm-dd hh24:mi:ss') as create_date,*/
                   /*to_timestamp(create_date) as create_date,*/
                   oracle_to_unix(create_date)  as create_date,
                   code,
                   code_status,
                   uuid
            /*top (1)*/
              FROM R_CHECK_CODE
             WHERE code_status = '0'
               and mobile = '138******'
            /*and rownum<=1*/
             order by create_date desc) s
     where rownum <= 1

    2.显示数据数量限制

    MYSQL:

       select * from tbl limit 100;

    ORACLE:

      select * from tbl where rownum<=100;

    SQL SERVER:

      select top 100 * from tbl

    3.小数取整

    ORACLE:取整函数trunc():

      trunc(12.354),返回值12

      trunc(12.354,1),返回值12.3

      trunc(12.354,-1),返回值10

    MYSQL:数值处理函数floor与round

      floor:函数只返回整数部分,小数部分舍弃。

      round:函数四舍五入,大于0.5的部分进位,不到则舍弃。与floor不同。

    4.获取当前时间

    ORACLE:sysdate  加括号容易出现错误:缺少逗号

    MySQL:sysdate()

  • 相关阅读:
    一文搞懂字符集
    机器视觉之eVision
    PID调节
    激光切割质量主要影响因素
    155. 最小栈
    111.二叉树最小深度
    110. 平衡二叉树
    108.将有序数组转换为二叉搜索树
    107. 二叉树的层次遍历 II
    104. 二叉树的最大深度
  • 原文地址:https://www.cnblogs.com/xuhai/p/9180523.html
Copyright © 2011-2022 走看看