Oracle_dual???

版权声明:_____________________不积跬步,无以至千里;不积小流,无以成江海。(转载若侵权,联系删除) https://blog.csdn.net/icecoola_/article/details/84875202

Selecting from the DUAL Table

DUAL is a table automatically created by Oracle Database along with the data dictionary. DUAL is in the schema of the user SYS but is accessible by the name DUAL to all users. It has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value X. Selecting from the DUAL table is useful for computing a constant expression with the SELECT statement. Because DUAL has only one row, the constant is returned only once. Alternatively, you can select a constant, pseudocolumn, or expression from any table, but the value will be returned as many times as there are rows in the table. Please refer to “SQL Functions” for many examples of selecting a constant value from DUAL.


伪表
dual表就是oracle与数据字典自动创建的一张表,这张表是一个单行单列的表,
这个表只有1列:DUMMY,数据类型为VERCHAR2(1),dual表中只有一个数据’X’,
Oracle有内部逻辑保证dual表中永远只有一条数据。
dual表主要是用来选择系统变量或是求一个表达式的值。

demo

select * from dual;
select 'Hello '||'World' from dual;
select concat('Hello ','World') from dual;
select concat('010-','88888888')||'转23' 联系方式 from dual;

select 1+2 result from dual;
select 999*999 from dual;

SELECT sysdate FROM dual;
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') 时间 from dual;

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]
  

猜你喜欢

转载自blog.csdn.net/icecoola_/article/details/84875202