为什么“select * from emp as newemp;“在oracle sql中出错?[重复]

9udxz4iz  于 2023-04-05  发布在  Oracle
关注(0)|答案(1)|浏览(112)

此问题在此处已有答案

Simple SQL command not properly ended [duplicate](1个答案)
SQL Oracle LEFT JOIN and SUBQUERY error: ORA-00905: missing keyword(2个答案)
2天前关闭。
我想测试rename(p)使所有表名相同但不同,如Pnewemp(emp)。
所以我写了

select * 
from emp as newemp

在Oracle中,但它没有工作。

select empno as newempno 
from emp;

确实有效。
请给予我一些建议。

bwleehnv

bwleehnv1#

在Oracle中,

  • 表别名不支持as关键字
  • 列别名可以,但不是必需的

具有as的表别名:

SQL> select * from dept as newdept;
select * from dept as newdept
                   *
ERROR at line 1:
ORA-00933: SQL command not properly ended

不带as的表别名:

SQL> select * from dept newdept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

组合:

SQL> select deptno as dno, dname department_name from dept newdept;
                   --            ----                      -------
    column's alias with AS       without AS             table alias without AS

       DNO DEPARTMENT_NAM
---------- --------------
        10 ACCOUNTING
        20 RESEARCH
        30 SALES
        40 OPERATIONS

SQL>

相关问题