• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Kevin Cheng's Yard
电脑是我的老婆,编程是我的灵魂,代码是我的语言,按键是我在歌唱。
https://github.com/surfsky/
博客园    首页    新随笔    联系   管理    订阅  订阅

oracle 和 sqlserver sql语句的差别

select创建表
    oracle: create table table2 as (select * from table1);
    sqlserver: select * into table2 from table1;


递归查询
    oracle: connect by
        select ... from <TableName>
        where <Conditional-1>
        start with <Conditional-2>
        connect by <Conditional-3>
    sqlserver: cte
        ;with cte(id, name, pid, lvl) as
        (
            select t.*, 0 lvl from t where pid=0
            union all
            select t.*, cte.lvl+1 lvl from t, cte where t.pid = cte.id
        )
        select
            case
                when lvl=0 then name
                else REPLICATE(' ', lvl) + '└' + name
            end,
            id,
            pid
        from cte
        ;

正则
    oracel: regexp_substr, regexp_like, regexp_instr, regexp_replace, regexp_count
    sqlserver: 木有

子查询
    oracle:     select * from (select * from table1);
    sqlserver: select * from (select * from table1) t;

组内排序(一致)
    oracle: row_number() over (partition by ... order by ...)
    sqlserver: row_number() over (partition by .. order by ...)


查询结果插入(一致)
    insert into table1(col1, col2, col3) select col1, col2, col3 from table2;

转载请注明出处:http://surfsky.cnblogs.com 

posted @ 2012-11-27 23:05  surfsky  阅读(1021)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3