学习oracle第一天的个人记录

学习oracle数据库第一天的记录,仅为了个人学习方便查找

因为之前学过SQLServerMySQL, 所以学习oracle感觉很轻松,都是一些大同小异的内容。

主要记录的点有两个,一个是关于 not in 1,2,null;一个是关于层次查询

1.Not in (null)

现象:之前没有考虑过这个问题,当我们用如下SQL语句查询时

Select  * form user where name not in( tom, jack, null);

查询的结果一定为空,即使user表中有除了tomjack这两货之外的其他人。

 

资料:发现只要有null参与的算术运算或者逻辑运算,其结果都是false

即:  select * from user where name = null;

或者  select * from user where name=null;

其结果都是返回false,所以查到的结果也是空集

 

猜想:对于not  in ‘tom’, ‘jack’,null

      可能内部实现是这样的

        Select * from user where name !=’tom’;

        Select * from user where name !=’jack’;

        Select * from user where name !=null;(根据资料返回false,查询结果为空集)

     再把三个结果∩起来

 

所以有一个空集,结果就一定为空集

2.层次查询

对于oracle记录的第二个点时层次查询,之前在学习其他数据库的时候,没有学习到这个层次查询,通过伪列level,实现比自连接效率要高的查询算法,附两张图记录

 学习oracle第一天的个人记录

                      图1   查询语句

学习oracle第一天的个人记录

                                  图2   查询分析(level为树的层次)