Oracle中dual表的用途介绍
dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录。我们可以用它来做很多事情,如下:查看当前
dual是一个虚拟表,用来构成select的语法规则,,Oracle保证dual里面永远只有一条记录。我们可以用它来做很多事情,如下:
1、查看当前用户,可以在 SQL Plus中执行下面语句 select user from dual;
2、用来调用系统函数
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;--获得当前系统时间
select SYS_CONTEXT('USERENV','TERMINAL') from dual;--获得主机名
select SYS_CONTEXT('USERENV','language') from dual;--获得当前 locale
select dbms_random.random from dual;--获得一个随机数
3、得到序列的下一个值或当前值,用下面语句
select your_sequence.nextval from dual;--获得序列your_sequence的下一个值
select your_sequence.currval from dual;--获得序列your_sequence的当前值
4、可以用做计算器 select 7*9 from dual;
------
Oracle系统中dual表是一个“神秘”的表,网上有很多网友都对该表进行了测试,该表只有一行一列,其实该表和系统中的其他表一样,一样可以执行插入、更新、删除操作,还可以执行drop操作。但是不要去执行drop表的操作,否则会使系统不能用,数据库起不了,会报Database startup crashes with ORA-1092错误。此时也不要慌乱,可以通过执行以下步骤来进行恢复。可以用sys用户登陆。
SQL> create pfile=’d:pfile.bak’ from spfile
SQL> shutdown immediate
在d:pfile.bak文件中最后加入一条:
replication_dependency_tracking = FALSE
重新启动数据库:
SQL> startup pfile=’d:pfile.bak’
SQL> create table “sys”.”DUAL”
[an error occurred while processing this directive]
=====
DUAL ? 有什么神秘的? 当你想得到ORACLE系统时间, 简简单单敲一行SQL 不就得了吗? 故弄玄虚….
SQL> select sysdate from dual;
SYSDATE
---------
28-SEP-03
哈哈, 确实DUAL的使用很方便. 但是大家知道DUAL倒底是什么OBJECT, 它有什么特殊的行为吗? 来,我们一起看一看. 首先搞清楚DUAL是什么OBJECT :
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
原来DUAL是属于SYS schema的一个表,然后以PUBLIC SYNONYM的方式供其他数据库USER使用.
再看看它的结构:
SQL> desc dual Name Null? Type
----------------------------------------- -------- ----------------------------
DUMMY VARCHAR2(1)
SQL>
只有一个名字叫DUMMY的字符型COLUMN .
然后查询一下表里的数据:
SQL> select dummy from dual;
DUMMY
----------
X
哦, 只有一条记录, DUMMY的值是’X’ .很正常啊,没什么奇怪嘛. 好,下面就有奇妙的东西出现了!
插入一条记录:
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
迄今为止,一切正常. 然而当我们再次查询记录时,奇怪的事情发生了
SQL> select * from dual;
DUMMY
----------
X
刚才插入的那条记录并没有显示出来 ! 明明DUAL表中有两条记录, 可就是只显示一条!
再试一下删除 ,狠一点,全删光 !
SQL> delete from dual; /*注意没有限定条件,试图删除全部记录*/
1 row deleted.
SQL> commit;
Commit complete.
哈哈,也只有一条记录被删掉,
SQL> select * from dual;
DUMMY
----------
Y
为什么会这样呢? 难道SQL的语法对DUAL不起作用吗?带着这个疑问,
我查询了一些ORACLE官方的资料. 原来ORACLE对DUAL表的操作做了一些内部处理,尽量保证DUAL表中只返回一条记录.当然这写内部操作是不可见的 . 看来ORACLE真是蕴藏着无穷的奥妙啊!
附: ORACLE关于DUAL表不同寻常特性的解释 There is internalized code that makes this happen. Code checks that ensure that a table scan of SYS.DUAL only returns one row. Svrmgrl behaviour is incorrect but this is now an obsolete product. The base issue you should always remember and keep is: DUAL table should always have 1 ROW. Dual is a normal table with one dummy column of varchar2(1). 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. If DUAL has no rows at all some applications (that use DUAL) may fail with NO_DATA_FOUND exception. If DUAL has more than 1 row then applications (that use DUAL) may fail with TOO_MANY_ROWS exception.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PrimeFactor−Innumbertheory,theprimefactorsofapositiveintegeraretheprimenumbersthatdividethatintegerexactly.Theprocessoffindingthesenumbersiscalledintegerfactorization,orprimefactorization.Example−Primefactorsof288are:288=2x2x2x2x2

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

This article recommends ten digital currency trading apps: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Poloniex. When choosing a platform, you need to consider factors such as security, liquidity, transaction fees, currency selection, user interface, customer service support and regulatory compliance, and carefully evaluate risks and never blindly follow the trend.

Reliable digital currency platforms include: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini. These exchanges have their own characteristics. Users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

This article provides Android and Apple mobile APP download methods for mainstream digital currency trading platforms such as Binance, OKX, Gate.io, Huobi Global, Coinbase, KuCoin, Kraken and Bitfinex. Whether it is an Android user or an Apple user, you can easily find the official APP download link for the corresponding platform and complete the installation according to the steps. The article provides detailed guidance on searching and downloading on their respective official websites or app stores, and provides instructions on the special steps for installing APK files on Android, so that users can download and use them quickly and easily.

The rankings of the top ten virtual currency trading platforms are: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Gemini. The ranking is based on comprehensive considerations such as platform liquidity, currency selection, security, user experience, handling fees and compliance, but is for reference only. Investment should be cautious and at your own risk.
