【Oracle】sqlplus小技巧
在sql*plus工具中,会有一个buffer(缓存),这个buffer中只能存放一条sql语句(不管这条sql语句多少行),buffer中会存放着我们最近一次执行过的一条sql语句。 L或者l //大写或小写都可以list,显示buffer中存放的sql语句 spool spool.sql //将接下来的操作记录在spool.sql文件中直到spool off 如下操作 SQL> select * from dual
2 where 1=1
3 ;
D
-
X
SQL> l
1 select * from dual
2 where 1=1
3*
SQL> 2 where null = 1
SQL> l
1 select * from dual
2 where null = 1
3*
SQL> /
未选定行
SQL>
2 where null = null
SQL> /
未选定行
顺便一提的是null 同任何数值计算结果既不是true,也不是false。(参考[1]) 如果表中的字段有可能为空,可以使用“decode(column,:bind_variable,1) = 1”或者 SQL> select * from dual
2 where decode(null,null,1) = 1
3 /
D
-
X
此外,我又做了如下测试 SQL> select decode(null,null,1) from dual;
DECODE(NULL,NULL,1) -------------------
1
SQL> select decode(null,2,1) ---------------- SQL> select * from dual;
D
-
X
SQL> select * from dual where decode(null,2,1)=1;
未选定行
SQL> select decode(null,1,0) from dual;
DECODE(NULL,0) ------------------
0
参考资料 (1)Oracle_Database_9i10g11g编程艺术深入数据库体系结构第2版181页,锁定问题,6.2.2悲观锁定 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |