Dual 是 Oracle中的一個實際存在的表
SQL> select user from dual;
USER
SYSTEM
SQL> select sysdate from dual;
SYSDATE
SQL> select to_char(sysdate
TO_CHAR(SYSDATE
SQL> select
SQL> create sequence aaa increment by
SQL> select aaa
NEXTVAL
SQL> select aaa
CURRVAL
DUAL就是個一行一列的表
SQL> select owner
OWNER OBJECT_NAME OBJECT_TYPE
SYS DUAL TABLE
PUBLIC DUAL SYNONYM
SQL> desc dual
Name Type Nullable Default Comments
DUMMY VARCHAR
create table SYS
(
DUMMY VARCHAR
)
tablespace SYSTEM
pctfree
pctused
initrans
maxtrans
storage
(
initial
next
minextents
maxextents
pctincrease
);
/*
很是困惑
還有
有了創建了表
grant select on SYS
將Select 權限授予公眾
*/
SQL> select count(*) from dual;
COUNT(*)
SQL> select * from dual;
DUMMY
X
SQL> insert into dual values (
SQL> commit;
Commit complete
SQL> insert into dual values (
SQL> insert into dual values (
SQL> commit;
Commit complete
SQL> select count(*) from dual;
COUNT(*)
SQL> select * from dual;
DUMMY
X
/*
SQL> insert into dual values(
SQL> commit;
提交完成
SQL> select * from dual;
DUMMY
X
Y
SQL> select sysdate from dual;
SYSDATE
這個時候返回的是兩條記錄
select sysdate into v_sysdate from dual;
來獲取時間或者其他信息的存儲過程來說
因此
*/
SQL> truncate table dual;
Table truncated
SQL> select count(*) from dual;
COUNT(*)
SQL> select * from dual;
no rows selected
SQL> select sysdate from dual;
no rows selected
SQL> delete from dual;
SQL> select * from dual;
DUMMY
SQL> select sysdate from dual;
SYSDATE
/*
我們便取不到系統日期了
select sysdate into v_sysdate from dual;
這種方式取系統時間以及其他信息的存儲過程來說是致命的
*/
SQL> select count(*) from dual;
COUNT(*)
SQL> delete from dual;
SQL> commit;
提交完成
SQL> select count(*) from dual;
COUNT(*)
/*
附: ORACLE關於DUAL表不同尋常特性的解釋
There is internalized code that makes this happen
The base issue you should always remember and keep is: DUAL table should always have
This is basically used from several applications as a pseudo table for getting results from a select statement that use functions like sysdate or other
prebuilt or application functions
So DUAL should ALWAYS have
*/
DUAL表可以執行插入
向DUAL表插入一條記錄(僅此一條)
SQL> create pfile=
SQL> shutdown immediate
SQL> startup pfile=
SQL> create table
(
pctfree
SQL> insert into dual values(
SQL> commit;
SQL> Grant select on dual to Public;
授權成功
SQL> select * from dual;
D
X
SQL> shutdown immediate
數據庫已經關閉
已經卸載數據庫
ORACLE 例程已經關閉
SQL> startup
ORACLE 例程已經啟動
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
數據庫裝載完畢
數據庫已經打開
SQL>
From:http://tw.wingwit.com/Article/program/Oracle/201311/16665.html