ChatGPT解决这个技术问题 Extra ChatGPT

What is the dual table in Oracle?

I've heard people referring to this table and was not sure what it was about.

The best ans is here all about dual asktom.oracle.com/pls/asktom/… , people are not giving more attention to the above comment link that is why i am commenting here .. have a look at it , you wont regret

V
Vishwanath Dalvi

It's a sort of dummy table with a single record used for selecting when you're not actually interested in the data, but instead want the results of some system function in a select statement:

e.g. select sysdate from dual;

See http://www.adp-gmbh.ch/ora/misc/dual.html


V
Vishwanath Dalvi

It is a dummy table with one element in it. It is useful because Oracle doesn't allow statements like

 SELECT 3+4

You can work around this restriction by writing

 SELECT 3+4 FROM DUAL

instead.


R
Ruben Bartelink

From Wikipedia

History

The DUAL table was created by Chuck Weiss of Oracle corporation to provide a table for joining in internal views:

I created the DUAL table as an underlying object in the Oracle Data Dictionary. It was never meant to be seen itself, but instead used inside a view that was expected to be queried. The idea was that you could do a JOIN to the DUAL table and create two rows in the result for every one row in your table. Then, by using GROUP BY, the resulting join could be summarized to show the amount of storage for the DATA extent and for the INDEX extent(s). The name, DUAL, seemed apt for the process of creating a pair of rows from just one. 1

It may not be obvious from the above, but the original DUAL table had two rows in it (hence its name). Nowadays it only has one row.

Optimization

DUAL was originally a table and the database engine would perform disk IO on the table when selecting from DUAL. This disk IO was usually logical IO (not involving physical disk access) as the disk blocks were usually already cached in memory. This resulted in a large amount of logical IO against the DUAL table.

Later versions of the Oracle database have been optimized and the database no longer performs physical or logical IO on the DUAL table even though the DUAL table still actually exists.


J
Jorge Ferreira

I think this wikipedia article may help clarify.

http://en.wikipedia.org/wiki/DUAL_table

The DUAL table is a special one-row table present by default in all Oracle database installations. It is suitable for use in selecting a pseudocolumn such as SYSDATE or USER The table has a single VARCHAR2(1) column called DUMMY that has a value of "X"


R
RustyTheBoyRobot

It's the special table in Oracle. I often use it for calculations or checking system variables. For example:

Select 2*4 from dual prints out the result of the calculation

Select sysdate from dual prints the server current date.


佚名

Kind of a pseudo table you can run commands against and get back results, such as sysdate. Also helps you to check if Oracle is up and check sql syntax, etc.


N
NealWalters

A utility table in Oracle with only 1 row and 1 column. It is used to perform a number of arithmetic operations and can be used generally where one needs to generate a known output.

SELECT * FROM dual;

will give a single row, with a single column named "DUMMY" and a value of "X" as shown here:

DUMMY ----- X


S
Sakin

The DUAL table is a special one-row table present by default in all Oracle database installations. It is suitable for use in selecting a pseudocolumn such as SYSDATE or USER

The table has a single VARCHAR2(1) column called DUMMY that has a value of "X"

You can read all about it in http://en.wikipedia.org/wiki/DUAL_table


s
steevc

DUAL is necessary in PL/SQL development for using functions that are only available in SQL

e.g.

DECLARE
x XMLTYPE;
BEGIN
SELECT xmlelement("hhh", 'stuff')
INTO x
FROM dual;
END;

V
Venkataramesh Kommoju

More Facts about the DUAL....

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1562813956388

Thrilling experiments done here, and more thrilling explanations by Tom


V
Vishwa G

DUAL we mainly used for getting the next number from the sequences.

Syntax : SELECT 'sequence_name'.NEXTVAL FROM DUAL

This will return the one row one column value(NEXTVAL column name).


That's not necessary since 11g. Sequences can be used natively in PL/SQL.
N
Newton fan 01

another situation which requires select ... from dual is when we want to retrieve the code (data definition) for different database objects (like TABLE, FUNCTION, TRIGGER, PACKAGE), using the built in DBMS_METADATA.GET_DDL function:

select DBMS_METADATA.GET_DDL('TABLE','<table_name>') from DUAL;

select DBMS_METADATA.GET_DDL('FUNCTION','<function_name>') from DUAL;

in is true that nowadays the IDEs do offer the capability to view the DDL of a table, but in simpler environments like SQL Plus this can be really handy.

EDIT

a more general situation: basically, when we need to use any PL/SQL procedure inside a standard SQL statement, or when we want to call a procedure from the command line:

select my_function(<input_params>) from dual;

both recipes are taken from the book 'Oracle PL/SQL Recipes' by Josh Juneau and Matt Arena


M
Manjunatha B

The DUAL is special one row, one column table present by default in all Oracle databases. The owner of DUAL is SYS.

DUAL is a table automatically created by Oracle Database along with the data functions. It is always used to get the operating systems functions(like date, time, arithmetic expression., etc.)

SELECT SYSDATE from dual;  

佚名

It's a object to put in the from that return 1 empty row. For example: select 1 from dual; returns 1

select 21+44 from dual; returns 65

select [sequence].nextval from dual; returns the next value from the sequence.