zoukankan      html  css  js  c++  java
  • oracle 与sql server 部分内置函数替换

    1,trunc--convert

     oracle: select trunc(sysdate) from dual   输出:2016/5/24

     sql server:select CONVERT(varchar(100), GETDATE(), 111) 输出:2016/05/24

    2,to_char--datename

    oracle:select to_char(sysdate,'day')  from dual; 输出星期二

    sql server:Select datename(weekday, getdate());输出星期二

    3 ROWNUM--SQL server行号

    oracle:select ROWNUM from dual

    sql server:select row_number()over(order by userid )as ROWNUM,*from Table

    4 trunc--Convert--ROUND

    oracle:select trunc(123.4586743,5) from dual 输出:123.45867

    sql server:select  Convert(decimal(18,5),123.4586743) 输出123.45867

    sql server:select ROUND(123.4586743,5)输出123.4586700

    5 select 值若空则为null/或0

    isnull(列名,0)
    coalesce(列名,0)
    select  m.entitycount, isnull(n.allcount,0), isnull(n.fixtime,0),coalesce(n.fixcount,0)  from table,
    *测出来的数据后三行没有列名暂时没有解决

    6 取三十天的时间

    oracle:

    SELECT (TRUNC(sysdate - 30) + (ROWNUM - 1)) as rq
    FROM dual
    CONNECT BY ROWNUM <= TRUNC(sysdate) - TRUNC(sysdate-30) + 1;

    sql server:

    select CONVERT(varchar(100), dateadd(dd,number,getdate()-30), 111) AS date
    from master..spt_values
    where type='p' and dateadd(dd,number,getdate()-30)<=getdate()

    输出

  • 相关阅读:
    二分查找算法
    http协议。会话控制cookie、session
    154. Find Minimum in Rotated Sorted Array II
    8. String to Integer (atoi)
    528. Random Pick with Weight
    415. Add Strings
    158. Read N Characters Given Read4 II
    157. Read N Characters Given Read4
    19. Remove Nth Node From End of List
    29. Divide Two Integers
  • 原文地址:https://www.cnblogs.com/wangboke/p/5524412.html
Copyright © 2011-2022 走看看