Sql高级篇

2015/02/01 Oracle

Sql高级篇

select into 和 insert into select两种表复制语句

  1. CT:CREATE TABLE <NEW TABLE> AS SELECT * FROM <EXISTS TABLE> :要求目标表不存在,因为在插入时会自动创建表,并将查询表中指定字段数据复制到新建的表中
  2. is:insert into table2(f1,f2,..) select v1,v2,..from table2:要求目标表table2必须存在,由于目标表table2已经存在,所以我们除了插入源表table1的字段外,还可以插入常量

    MERGE用法

    MERGE INTO 用法:

    merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not macthed then insert into a(字段1,字段2……)values(值1,值2……)

    递归函数

    START WITH CONNECT BY 是oracle提供的递归查询(分层查询)函数,非常的好用,我们在进行递归遍历树形结构的时候可以使用。 start with(从某个节点id开始) connect by prior(子节点id和父节点pid直接的关系需要) 形如:select *from emp start with empno =7369 connect by prior mgr=empno;(父节点=子节点,向上查询,反之向下查下)

     可以添加where
     可以指定多个起始节点查询。
     可以进行排序
    

分析函数 #1.

over 函数
over partition by 组合
over partition by order by 组合
row_number函数
rollup函数
cube函数
grouping函数

Search

    Table of Contents