The Oracle DUAL Table
dual表是和Oracle数据字典一起创建的。它实际上只包含dummy这一个column,并且只有一条记录,这条记录的值是X。
1SQL> desc dual;
2Name Type Nullable Default Comments
3----- ----------- -------- ------- --------
4DUMMY VARCHAR2(1) Y
5
6SQL> select * from dual;
7
8DUMMY
9-----
10X
dual表的owner是SYS,但所有用户都可以访问它。Although it is possible to delete the one record, or insert additional records, one really should not do that!.
Next,我们来看一下dual表都有哪些作用。
--Query current date/time
SQL> select sysdate from dual;
SYSDATE
-----------
2/06/2011 3
SQL> select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') systime from dual;
SYSTIME
-------------------
2011-06-02 03:58:47
--Used as a calculator
SQL> select 1+2 from dual;
1+2
----------
3
--Query the current user
SQL> select user from dual;
USER
------------------------------
OPS$GLOBAL
--Query sequence
SQL> create sequence seq increment by 2 start with 1;
Sequence created
SQL> select seq.nextval from dual;
NEXTVAL
----------
1
SQL> select seq.nextval from dual;
NEXTVAL
----------
3
SQL> select seq.currval from dual;
CURRVAL
----------
3
posted on 2011-06-02 12:08 时间给了够幸福的结局 阅读(942) 评论(4) 编辑 收藏 举报