http://hi.baidu.com/honglovejia/blog/item/97961b34f2ad213a5bb5f590.html
经常在程序里看到“select sysdate from dual;”
查了一下关于DUAL表的资料:
1. Dual 是什么?
select object_name ,object_type from dba_objects where object_name =\'DUAL\'
结果:
OWNER OBJECT_NAME OBJECT_TYPE
----------- ------------------- ------------------
SYS DUAL TABLE
PUBLIC DUAL SYNONYM
可以看出 DUAL是 SYS用户的一个TABLE.
2. 它有那些FIELD?
SQL> desc dual
Name Type Nullable Default Comments
----- ----------- -------- ------- --------
DUMMY VARCHAR2(1) Y
它只有一个 DUMMY Field.
3. DUAL 能做什么?
3.1 查找当天日期
SQL> select sysdate from dual;
SYSDATE
-----------
2004-4-13
3.2 查找当前日期的当月第一天
SQL> select trunc(sysdate,\'MONTH\') from dual;
TRUNC(SYSDATE,\'MONTH\')
----------------------
2004-4-1
3.3 查找当前日期的当月最后一天
SQL> select trunc(last_day(sysdate)) from dual;
TRUNC(LAST_DAY(SYSDATE))
------------------------
2004-4-30
4. DUAL奇妙现象
插入一条数据
SQL> insert into sys.dual values (\'V\');
1 row inserted
SQL> commit;
Commit complete
查看记录数
SQL> select count(1) from dual;
COUNT(1)
----------
2
查询记录
SQL> select * from dual;
DUMMY
-----
X
V
删除记录
SQL> delete from dual;
1 row deleted
--- 呵呵,各位看官,为什么我这样删除只能删除一条记录呢? 刚才不是查找出2条吗?
再次查询记录
SQL> select * from dual;
DUMMY
-----
V
呵呵,删除的记录不是我开始插入的记录.为什么???
关于这个现象,Oracle 解释是: DUAL should ALWAYS have 1 and only 1 row !!!
5.Dual的另一应用
Dual has another use when you try to test if you are connected with the DB remotely by JDBC in your AS such as Weblogic. This is a common table for any schema.
原先我取系统时间,向来是select sysdate from 随便某个表,
想想也会有些隐患,
如果该表被删除了,会出异常的。
今后也要专业一点,
select sysdate from dual! ^_^
分享到:
相关推荐
Oracle Database 21c 是最新的版本;...oracle-database-ee-21c-1.0-1.ol8文件分割成 三个 压缩包,必须集齐 三个 文件后才能一起解压一起使用: Oracle Database 21c (oracle-database-ee-21c-1.0-1.ol8.part3.rar) ...
oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
tableau10.0-oracle-driver-x64.msi,tableau开发oracle必须包
oracle-rdbms-server-11gR2-preinstall-1.0-4.el7.x86_64.rpm
oracle-database-server-12cR2-preinstall-1.0-3.el7.x86_64.rpm
flink-sql-connector-oracle-cdc 2.5-SNAPSHOT
Oracle Database Server 12cR2 Preinstall 是一个专为在x86_64架构的Linux系统上安装Oracle数据库12c Release 2 (12.2)而设计的预配置软件包。这个预安装包的主要目的是简化Oracle数据库服务器的安装流程,预先配置...
c3p0-oracle-thin-extras-0.9.2.1
oracle-database-preinstall-19c-1.0-2.el7.x86_64 .rpm,这是linux版本的,win请勿下载
cx_Oracle-5.1.3-11g.win-amd64-py2.7.exe Python 2.7 lib for Oracle 11g.
cx_Oracle-5.1-11g.win32-py2.5.msi,用于连接oracle数据库
cx_Oracle-5.2.1-11g-py27-1.x86_64.rpm
c3p0-oracle-thin-extras-0.9.1.2.jarc3p0-oracle-thin-extras-0.9.1.2.jarc3p0-oracle-thin-extras-0.9.1.2.jar
oracle11g-client-win-64客户端安装包
python连接oracle Python没有自带oracle驱动,cx_Oracle可以实现Python访问oracle的目的,如果要访问Oracle,首先要下载安装cx_Oracle
dm8-oracle-jdbc16-wrapper.jar
oracle12c 官方预安装检测包 使用说明https://blog.csdn.net/ljunjie82/article/details/42201473
exp system/oracle owner=oracle file='/tmp/oracle-table-20130509.dmp' log='/tmp/oracle-table-20130509.log'; 导入用户oracle下的表: imp system/oracle file='/tmp/oracle-table-20130509.dmp' log='/...
安装oracleasmlib需要的系统安装包,涵盖linux6 和 linux7,kmod-oracleasm-2.0.8-5.el6_7.x86_64.rpm,kmod-oracleasm-2.0.8-13.el6_8.x86_64.rpm,kmod-oracleasm-2.0.8-15.el7.x86_64.rpm,kmod-oracleasm-2.0.8-...
oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-basiclite-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-jdbc-...