Oracle和MySQL中都有一张名称为dual的虚拟表,但是两者之前的区别呢?
在MySQL中,对dual表时怎么解释的:
DUAL is purely for the convenience of people who require that all SELECT statements should have FROM and possibly other clauses.
纯粹是为了满足select ... from...这一习惯问题,mysql会忽略对该表的引用。
区别:
select * from dual;
mysql会出错: 1096 - No tables used,
oracle 会返回列:“DUMMY”,其值为“X”, 行为和只有一行记录的普通表是一样的!
select express [from dual];
mysql总是作为返回该表达式值的普通select语句执行,返回一行记录的结果集,from dual 对mysql来说根本就是摆设!
select 1 + 1;
select 1 + 1 from dual;
前面这两句sql语句执行的结果是一样的。
oracle里该句必须有from dual;否则报错!
ORA-00923: FROM keyword not found where expected
select express from dual where 0=2; mysq 和 oracle的行为一致:该句就如同你认为的正常表那样——会先计算where的条件,再行计算express;这里的where条件会决定expres是否会返回!
select 1 + 1 from dual where 0 = 2;
此时无论是Oracle还是MySQL都不可以省略from dual.