oracle中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.

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值