oracle 分页:
-- 第一种 select * from (select aed.*, row_number() over(order by aed.created_date) rw from alarm_event ae, alarm_event_detail aed where ae.id = aed.id) where rw between 10 and 15; -- 第二种 select * from (select t.*, rownum rw from (select aed.* from alarm_event ae, alarm_event_detail aed where ae.id = aed.id order by aed.created_date) t where rownum < 16) where rw >= 10;
with 关键字 (解决子句中多次引用相同的查询块,或者解决多层嵌套查询时)下面中也有使用分析函数解决分组问题。
with t1 as (select ai.accountid, lb.businesssum, lb.customerid, lb.businesstype, lb.loanterm, bp.bar_code_no, count(lb.putoutno) over(partition by ai.accountid, lb.businesssum, lb.customerid, lb.businesstype, lb.loanterm, bp.bar_code_no) ct, row_number() over(partition by ai.accountid, lb.businesssum, lb.customerid, lb.businesstype, lb.loanterm, bp.bar_code_no order by lb.customerid) rw from cfss.loan_balance lb left join cfss.account_info ai on lb.putoutno = ai.objectid and ai.accountserialno = '1' left join cfss.business_putout bp on bp.serialno = lb.putoutserialno where lb.putoutdate >= '2018/06/28' and lb.businesstype = '1702-SB-01'), t2 as (select lb.customerid, lb.normalbalance, lb.overduebalance from cfss.loan_balance lb, t1 where lb.customerid = t1.customerid and t1.ct > 1 and rw = 1 and lb.businesstype = '1702-SB-01'), t3 as (select ci.certtype, ci.certid, sum(normalbalance) + sum(overduebalance) as balance from t2, cfss.customer_info ci where t2.customerid = ci.customerid group by ci.certtype, ci.certid) select t3.*, bc.creditsum, bc.customerid from cfss.business_credit bc, t3 where bc.certtype = t3.certtype and bc.certid = t3.certid and balance > bc.creditsum;
开始 搜集统计信息。(搜集完成统计信息,可以使执行计划更优)
begin
dbms_stats.gather_table_stats(ownname => 'CFSS',
TABNAME => 'BUSINESS_PUTOUT',
cascade => true);
end;
分析和开窗函数
使用绑定变量 VS 不使用绑定变量
https://blog.csdn.net/Alen_Liu_SZ/article/details/80527834
1 不使用绑定变量
1)创建表并测试
2)查看硬解析次数以及执行次数
思考:为何只有461次?
shared_pool大小有限,无法保存每条解析过的sql,会通过LRU算法踢出冷块。
2 使用绑定变量
1)清空缓存,测试
2)查看硬解析次数以及执行次数