oracle 数据库方面总结

来源:互联网 发布:魔法咪路咪路 知乎 编辑:程序博客网 时间:2024/06/11 15:16

插入效率提升方法

  1. insert all   不带条件的
  2. into edw_int_1(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  3. values(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  4. into edw_int_2(agmt_no,agmt_sub_no,curr_period)   
  5. values(agmt_no,'1234',curr_period)   
  6. select agmt_no,agmt_sub_no,need_repay_int,curr_period from edw_int;   
  7. commit;  
  1. insert all   带条件的
  2. when curr_period=0 then    
  3. into edw_int_1(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  4. values(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  5. else  
  6. into edw_int_2(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  7. values(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  8. select agmt_no,agmt_sub_no,need_repay_int,curr_period from edw_int;   
  9. commit;  
  1. insert first   insert first-带条件 
  2. when curr_period=0 then    
  3. into edw_int_1(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  4. values(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  5. when agmt_sub_no='2104' then   
  6. into edw_int_2(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  7. values(agmt_no,agmt_sub_no,need_repay_int,curr_period)   
  8. select agmt_no,agmt_sub_no,need_repay_int,curr_period from edw_int;   
  9. commit;  


connect by  

connect by是结构化查询中用到的,其基本语法是:

1
2
3
4
select ...from tablename
startby cond1
connect by cond2
where cond3

简单说来是将一个树状结构存储在一张表里,比如一个表中存在两个字段(如emp表中的empno和mgr字段):empno, mgr那么通过表示每一条记录的mgr是谁,就可以形成一个树状结构。

用上述语法的查询可以取得这棵树的所有记录。
其中:
cond1是根结点的限定语句,当然可以放宽限定条件,以取得多个根结点,实际就是多棵树。
cond2是连接条件,其中用prior表示上一条记录,比如connect by prior id=praentid就是说上一条记录的id是本条记录的praentid,即本记录的父亲是上一条记录。
cond3是过滤条件,用于对返回的所有记录进行过滤。
prior和start with关键字是可选项
prior运算符必须放置在连接关系的两列中某一个的前面。对于节点间的父子关系,prior运算符在一侧表示父节点,在另一侧表示子节点,从而确定查找树结构是的顺序是自顶向下还是自底向上。在连接关系中,除了可以使用列名外,还允许使用列表达式。
start with子句为可选项,用来标识哪个节点作为查找树型结构的根节点。若该子句被省略,则表示所有满足查询条件的行作为根节点。



0 0
原创粉丝点击