oracle Oracle中的双表是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/73751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the dual table in Oracle?
提问by Brian G
I've heard people referring to this table and was not sure what it was about.
我听说有人提到这张桌子,但不确定它是关于什么的。
采纳答案by Sean McMains
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:
这是一种带有单个记录的虚拟表,用于在您实际上对数据不感兴趣时进行选择,而是希望在 select 语句中获得某些系统函数的结果:
e.g. select sysdate from dual;
例如 select sysdate from dual;
回答by mfx
It is a dummy table with one element in it. It is useful because Oracle doesn't allow statements like
它是一个包含一个元素的虚拟表。这很有用,因为 Oracle 不允许像这样的语句
SELECT 3+4
You can work around this restriction by writing
您可以通过编写解决此限制
SELECT 3+4 FROM DUAL
instead.
反而。
回答by Ivan Bosnic
From Wikipedia
来自维基百科
History
历史
The DUAL table was created by Chuck Weiss of Oracle corporation to provide a table for joining in internal views:
DUAL 表由 Oracle 公司的 Chuck Weiss 创建,用于提供用于加入内部视图的表:
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
我创建了 DUAL 表作为 Oracle 数据字典中的基础对象。它本身并不意味着被看到,而是在预期被查询的视图中使用。这个想法是您可以对 DUAL 表执行 JOIN 并在结果中为表中的每一行创建两行。然后,通过使用 GROUP BY,可以汇总结果连接以显示 DATA 盘区和 INDEX 盘区的存储量。名称 DUAL 似乎适合仅从一个行创建一对行的过程。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.
从上面可能不明显,但原始 DUAL 表中有两行(因此得名)。现在它只有一排。
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.
DUAL 最初是一个表,数据库引擎在选择 DUAL 时会对该表执行磁盘 IO。这个磁盘 IO 通常是逻辑 IO(不涉及物理磁盘访问),因为磁盘块通常已经缓存在内存中。这导致针对 DUAL 表的大量逻辑 IO。
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.
Oracle 数据库的更高版本已进行了优化,即使 DUAL 表仍然实际存在,该数据库也不再对 DUAL 表执行物理或逻辑 IO。
回答by Jorge Ferreira
I think this wikipedia article may help clarify.
我认为这篇维基百科文章可能有助于澄清。
http://en.wikipedia.org/wiki/DUAL_table
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"
DUAL 表是一个特殊的单行表,默认情况下存在于所有 Oracle 数据库安装中。它适用于选择伪列,例如 SYSDATE 或 USER 表有一个名为 DUMMY 的单个 VARCHAR2(1) 列,其值为“X”
回答by Martin08
It's the special table in Oracle. I often use it for calculations or checking system variables. For example:
它是 Oracle 中的特殊表。我经常用它来计算或检查系统变量。例如:
Select 2*4 from dual
prints out the result of the calculationSelect sysdate from dual
prints the server current date.
Select 2*4 from dual
打印出计算结果Select sysdate from dual
打印服务器当前日期。
回答by Martin08
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.
一种可以针对它运行命令并返回结果的伪表,例如 sysdate。还可以帮助您检查 Oracle 是否已启动并检查 sql 语法等。
回答by AB01
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.
Oracle 中只有 1 行和 1 列的实用程序表。它用于执行许多算术运算,通常可用于需要生成已知输出的地方。
SELECT * FROM dual;
SELECT * FROM 双;
will give a single row, with a single column named "DUMMY" and a value of "X" as shown here:
将给出一行,其中有一列名为“DUMMY”,值为“X”,如下所示:
DUMMY ----- X
DUMMY ----- X
回答by Venkataramesh Kommoju
More Facts about the DUAL....
关于 DUAL 的更多事实......
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1562813956388
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
在这里完成了激动人心的实验,以及汤姆更激动人心的解释
回答by 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
DUAL 表是一个特殊的单行表,默认情况下存在于所有 Oracle 数据库安装中。它适用于选择 SYSDATE 或 USER 等伪列
The table has a single VARCHAR2(1) column called DUMMY that has a value of "X"
该表有一个名为 DUMMY 的 VARCHAR2(1) 列,其值为“X”
You can read all about it in http://en.wikipedia.org/wiki/DUAL_table
您可以在http://en.wikipedia.org/wiki/DUAL_table 中阅读所有相关信息
回答by steevc
DUAL is necessary in PL/SQL development for using functions that are only available in SQL
DUAL 在 PL/SQL 开发中是必需的,以使用仅在 SQL 中可用的函数
e.g.
例如
DECLARE
x XMLTYPE;
BEGIN
SELECT xmlelement("hhh", 'stuff')
INTO x
FROM dual;
END;