Oracle查询优化改写2.0 第三章 操作多个表

------------------------------------------------------------------chapter3操作多个表------------------------------------------------------------------

目录:

3.1 union all 与空字符串

3.2 union 与 or

3.3 union 与 去重

3.4 组合相关的行(两个表中的字段,两种写法:join 和 from a,b表的写法)

3.5 in ,exists 和 inner join 

3.6 inner join ,left join ,right join和 full join解析

3.7 外连接与过滤条件

3.8 自关联

3.9 not in, not exists 和 left join 

3.10 检测两个表中的数据及对应数据的条数是否相等

3.11 聚集与内连接

彩蛋插入:日常索引的创建与检测

  --创建索引    create index bill_m  on qj_qp.sunneng_x_income2020(bill_month);

索引结构:create index 索引名称 on 表名(表中的某个字段)
  --查询索引状态是否有效  select status,t.* from user_indexes t where table_name='QY_TMP_NEW_ADDR';
  --                      select * from user_ind_columns where index_name='IDX_ADDR';

--3.1union all 与 空字符串
union all 通常用于合并多个数据集,oracle中常把空字符串当做null处理
select sysdate from dual where '' is null;--2020/11/3 15:23:28
空字符串与null并不等价
select 1 as id from dual union all select '' from dual;--ora-01790表达式必须具有与对应表达式相同的数据类型
空字符串:varchar2 类型           null:任何类型  【两者不等价】
--3.2union 与 or
当在条件中有or时,经常会改写为union
建立两个索引
create index idx_emp_empno on emp(empno);
create index idx_emp_ename on emp(ename);
select empno,ename from emp where empno=7788 or ename='SCOTT'

更改为 union all,则结果是错的(数据重复)
select empno,ename from emp where empno=7788
union all
select empno,ename from emp where e

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值