1.rownum:rownum是一个伪列,需要在数据取出来后,rownum才会有值,因此在分页查找时,需要进行嵌套查询。

select sal,ename from
(select rownum as rn,sal,ename from
(select sal,ename from emp where sal is not null order by sal) x
where rownum<10)
where rn>6

采用分析函数也是可以实现一次嵌套

select rn,ename,sal from
(select rownum() over(order by sal) as rn,sal,ename where sal is not null ) x
where rn between 6 and 10

但是由于分析函数的影响,有些索引可能失效,建议大家采用第一种写法。

隔行返回数据,对伪列求余即可,MOD(rn,X)

2.Merge:高效的表更新处理

Merge inot test a
using
(select rowid as rid,nbr*100+rownum() over(partition by nbr order by rowid) as nnbr from test) b
on(a.rowid=b.rid)
when matched then
update set a.nbr = b.nnbr;

大家猜猜 test表扫描了几次?????

3.将表中某些列,排列组合去重

step1:列转行

select * from test unpivot(b2 for b3 in(t1,t2,t3)

unpivot行列转置非常牛逼的一个方法

step2:按照值排序并合并

with x1 as
(select * from test unpivot(b2 for b3 in(t1,t2,t3)),
select id,listagg(b2,',') within group (order by b2) as b
from x1
group by id;

listagg实现分组后,值排序后,值按逗号拼接

step3:去除重复

with x1 as
(select * from test unpivot(b2 for b3 in(t1,t2,t3)),
x2 as
( select id,listagg(b2,',') within group (order by b2) as b
from x1
group by id)
select id,b,row_number() over(partition by b order by id) as sn from x2

最新文章

  1. 【PKU1001】Exponentiation(高精度乘法)
  2. 打开Excel的报错,提示:不能使用对象链接和嵌入
  3. 分治法避免定义多个递归函数,应该使用ResultType
  4. 安装ss
  5. IOS 二维码生成
  6. LinuxC 文件与目录 打印文件操作错误信息
  7. STM32F05x加入RDP(LV1)后,Segger无法Unlock的解决办法
  8. 对 JDBC 做一个轻量封装,待完善。。。
  9. 自我理解foreach工作原理
  10. vim note(4)
  11. Linux进程间通信(九)---综合实验之有名管道通信实验
  12. HTML day03表格与表单
  13. luogu P1250 种树
  14. Python3 tkinter基础 Text image 文本框中插入图片
  15. CS131&amp;Cousera图像处理学习笔记 - L5边缘
  16. BeEF介绍
  17. BZOJ3738 [Ontak2013]Kapitał 【扩展Lucas】
  18. Apache Spark探秘:利用Intellij IDEA构建开发环境
  19. ngular6开发不完全笔记(二)-- 管道
  20. Gym - 101334C 3514 无向仙人掌

热门文章

  1. (转)用JMX监测JVM的运行参数
  2. Raft协议详解-leader发送心跳代码go
  3. 利用socket模块检查端口存活并邮件警报
  4. 笔记整理--Linux守护进程
  5. H5的新应用-指定视频的播放进度
  6. C语言隐式强制类型转换
  7. ACboy needs your help again!
  8. 谷歌浏览器web开发教程之开始篇:使用sublime
  9. Ansible4:Ad-hoc与命令执行模块【转】
  10. laravel路由使用【总结】