最近的工作与oracle数据库有关,所以拿起家里之前买的一本oracle书籍。在阅读过程中,我发现这本书有多出不准确的描述。在此记录下来,当然,我也会把一些sql命令或者sql语句记录下来,如果有人恰好也是读这本书,就直接复制即可。
更希望的时, 恰好也在看这本书的人可以和我共同记录阅读过程。
此书有配套课件,根据书本最后一页的提示可以下载(我不知道怎样上传到该页面)。
目录
目录
2. 使用ANY(任意匹配)和ALL(任意匹配), 必须使用一个单行操作符,包括=、>、<、<=、>=等
DEBUG
我参考了使用 SQL Developer 开发和调试 PL/SQL。
以下的输出内容对我的工作已经足够。
连接到数据库 ORCL1555_sys。
执行 PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
执行 PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP( '127.0.0.1', '51995' )
调试器接受了端口 51995 上的数据库连接。
源断点: PKG_DEMO.pls:11
源断点: PKG_DEMO.pls:12
当然,你也可能遇到以下问题:
连接到数据库 ORCL1555。
执行 PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
执行 PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP( '127.0.0.1', '55521' )
ORA-01031: 权限不足
ORA-06512: 在 "SYS.DBMS_DEBUG_JDWP", line 68
ORA-06512: 在 line 1
此会话需要 DEBUG CONNECT SESSION 和 DEBUG ANY PROCEDURE 用户权限。
进程已退出。
从数据库 ORCL1555 断开连接。
第7章 SELECT 高级查询
7.2 使用join关键字的连接查询
-
7.2.2 外连接查询
-
1. 左外连接
关于用(+)表示外连接,书中描述有误。
关于恰当用法,我参考了这个连接
Oracle左连接、右连接、全外连接以及(+)号用法 - 何海洋 - 博客园 (cnblogs.com)
select
*
from scott.dept d
left join scott.emp e
on d.deptno = e.deptno;
select
*
from scott.dept d,
scott.emp e
on d.deptno = e.deptno (+) ;
ORA-00933: SQL 命令未正确结束
00933. 00000 - "SQL command not properly ended"
select
*
from scott.dept d,
scott.emp e
where d.deptno = e.deptno (+) ;
- 2. 右外连接
select
distinct e.deptno , d.deptno
from scott.emp e
right join scott.dept d
on e.deptno = d.deptno
;
select
distinct e.deptno , d.deptno
from scott.emp e
,scott.dept d
where e.deptno (+) = d.deptno
;
以上语句得到同样的结果。
- 3.完全外连接
-
7.2.3 交叉连接
我没写过交叉连接,不知道交叉连接有什么优点,目前不去深究。
7.3 SELECT 查询的集合操作
7.3.1 UNION 集合运算
UNION 会去重, UNION ALL 的All顾名思义就是不去重^-^.
select
*
from scott.emp
where sal > 2000
union all
select
*
from scott.emp
where job = 'MANAGER'
order by 1;
select
*
from scott.emp
where sal > 2000
union
select
*
from scott.emp
where job = 'MANAGER'
order by 1;
如果想将union /union all 的结果集order by 一下,可以参考(50条消息) Oracle中union all、union 和order by一起使用的解决方法_luzaijx的博客-CSDN博客
7.3.2 INTERSECT 取交集
select
*
from scott.emp
where empno > 7800;
select
*
from scott.emp
where deptno = 10;
select
*
from scott.emp
where empno > 7800
intersect
select
*
from scott.emp
where deptno = 10;
create table scott.emp_2 as select * from scott.emp ;
select
*
from scott.emp
where empno > 7800
intersect
select
*
from scott.emp_2
where deptno = 10;
7.3.3 MINUS 取补集 A-B
SELECT empno, ename, job, sal FROM scott.emp
WHERE sal>2000
MINUS
SELECT empno,ename,job,sal FROM scott.emp
WHERE job= 'MANAGER';
7.4 子查询
7.4.1 子查询的类型
书本中分为以下3种,我不明白为什么要做这种分类。当我们用错的时候,执行结果会给我们报错提示。
根据子查询返回结果情况为分为3种子类型 :
1.单行子查询(仅限单列)
2.多行子查询(仅限单列)
3.多列子查询
或者 根据操作符来分,我感觉这种分类更加合理。
(1)单行操作符:包括=、>、<、>=、<=、<>、!=。
(2)多行操作符:包括ALL、ANY、IN、EXISTS
疑问:ALL,SOME 呢?
7.4.2 单行子查询
书本给出的例子如下,我觉得给出这种例子不合适。