select 'abc' abc,1 def;
它不适用于Oracle.为什么我们需要从Oracle中选择DUAL? sql的ISO / ANSI标准是否需要SELECT语句的FROM子句?
编辑:
Per Bacon Bit的答案,似乎是sql标准所要求的.
所以实际上,因为名称DUAL是如此用词不当,如果我要创建一个表并将其命名为ATOM或ONE,例如create table one(atom int); ..选择’abc’abc,1 def FROM one; – 与SELECT … FROM DUAL相比,是否存在性能损失?
SELECT [ DISTINCT | ALL ] {Column expression [ AS name ]} [,... ] | * FROM <Table reference> [ {,<Table reference>} ... ] [ WHERE search condition ] [ GROUP BY Columns [ HAVING condition ] ] [ORDER BY {col_name | expr | position} [ASC | DESC],...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [INTO OUTFILE 'file_name' export_options | INTO DUMPFILE 'file_name' | INTO var_name [,var_name]] [FOR UPDATE | LOCK IN SHARE MODE]
在实际使用中,程序员和DBA经常发现除了操作表中的数据或操作表和数据结构之外,还可以执行其他操作.这种类型的东西在很大程度上超出了sql标准的范围,sql标准关注的是数据特性而不是特定实现的细节.无论我们是想运行SELECT getdate()还是SELECT 1或SELECT DB_NAME()(或者您的方言更喜欢),我们实际上并不想要表中的数据.
Oracle选择使用具有以下有效定义的虚拟表来解决标准和实现差异:
CREATE TABLE DUAL ( DUMMY CHAR(1) ) INSERT INTO DUAL (DUMMY) VALUES ('X')
其他RDBMS实质上假设如果没有指定FROM,则使用伪表.
history of the DUAL table在维基百科上:
The DUAL table was created by Charles 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.原始的DUAL表中有两行(因此它的名字),但是随后它只有一排.