Introduction to the use of dual tables in Oracle and the use of oracledual tables
Dual is a virtual table used to form the select syntax rule. oracle ensures that there will always be only one record in dual. We can use it to do a lot of things, as shown below:
1. view the current user. You can execute the following statement select user from dual in SQL Plus;
2. Used to call system functions
Select to_char (sysdate, 'yyyy-mm-dd hh24: mi: ss') from dual; -- get the current system time
Select SYS_CONTEXT ('userenv', 'terminal') from dual; -- get the host name
Select SYS_CONTEXT ('userenv', 'language') from dual; -- get the current locale
Select dbms_random.random from dual; -- obtain a random number
3. Obtain the next or current value of the sequence. Use the following statement.
Select your_sequence.nextval from dual; -- Obtain the next value of the sequence your_sequence
Select your_sequence.currval from dual; -- get the current value of the sequence your_sequence
4. You can use the calculator select 7*9 from dual;
------
In Oracle, the dual table is a "mysterious" table. Many online users have tested this table. This table has only one row and one column, in fact, this table is the same as other tables in the system. You can perform insert, update, and delete operations as well as drop operations. But do not perform the drop table operation, otherwise the system will not be available, the Database cannot start, will report the Database startup crashes with ORA-1092 error. In this case, do not be confused. You can perform the following steps to restore. You can use the sys user to log on.
SQL> create pfile = 'd: pfile. bak 'from spfile
SQL> shutdown immediate
Add the last entry to the d: pfile. bak file:
Replication_dependency_tracking = FALSE
Restart the database:
SQL> startup pfile = 'd: pfile. bak'
SQL> create table "sys". "DUAL"
[An error occurred while processing this directive]
=====
DUAL? What's mysterious? If you want to get the time of the ORACLE system, you can simply type a line of SQL? To learn more ....
SQL> select sysdate from dual;
SYSDATE
---------
28-SEP-03
Haha, it is indeed very convenient to use DUAL. But do you know what the DUAL is and what special behavior it has? Let's take a look. First, let's figure out what DUAL is:
SQL> connect system/manager
Connected.
SQL> select owner, object_name, object_type from dba_objects where object_name like '% DUAL %'; OWNER OBJECT_NAME OBJECT_TYPE
-------------------------------------------
SYS DUAL TABLE PUBLIC DUAL SYNONYM
The original DUAL is a table in SYS schema and is then used by other database users in public synonym mode.
Let's look at its structure:
SQL> desc dual Name Null? Type
-----------------------------------------------------------------------------
DUMMY VARCHAR2 (1)
SQL>
There is only one empty COLUMN named DUMMY.
Query the data in the table:
SQL> select dummy from dual;
DUMMY
----------
X
Oh, there is only one record. The DUMMY value is 'x'. It's normal. It's no surprise. Well, there's something amazing coming up!
Insert a record:
SQL> connect sys as sysdba
Connected.
SQL> insert into dual values ('y ');
1 row created.
SQL> commit;
Commit complete.
SQL> select count (*) from dual;
COUNT (*)
----------
2
So far, everything works. But when we query records again, something strange happened.
SQL> select * from dual;
DUMMY
----------
X
The record just inserted is not displayed! The DUAL table has two records, but only one record is displayed!
Try to delete the file. Click "delete" to delete all files!
SQL> delete from dual;/* try to delete all records without restrictions */
1 row deleted.
SQL> commit;
Commit complete.
Haha, only one record is deleted,
SQL> select * from dual;
DUMMY
----------
Y
Why? Does SQL syntax not work for DUAL? With this question,
I have queried some official ORACLE documents. ORACLE performed some internal operations on the DUAL table to ensure that only one record is returned in the DUAL table. of course, this write operation is invisible. it seems that ORACLE is an infinite mystery!