oracle 数据库方面总结

本文介绍了几种使用SQL语句提高数据库插入效率的方法,包括无条件和带条件的INSERT ALL语句,以及使用CONNECT BY实现树状结构数据的查询。这些技巧有助于改善数据处理流程并提升系统性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

插入效率提升方法

  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子句为可选项,用来标识哪个节点作为查找树型结构的根节点。若该子句被省略,则表示所有满足查询条件的行作为根节点。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值