代码之家  ›  专栏  ›  技术社区  ›  Robert Gould

选择使用Oracle

  •  119
  • Robert Gould  · 技术社区  · 16 年前

    SELECT * INTO new_table FROM old_table;
    

    但我得到以下错误:

    SQL Error: ORA-00905: missing keyword
    00905. 00000 -  "missing keyword"
    

    有什么问题吗?


    然而,Oracle在自己的SQL方言中实现了完全不同的方法 Oracle Docs on Insert ... Select

    3 回复  |  直到 9 年前
        1
  •  296
  •   APC    6 年前

    如果新的表已经存在,那么。。。

    insert into new_table 
    select * from old_table
    /
    

    如果要基于旧\u表中的记录创建新的\u表。。。

    create table new_table as 
    select * from old_table
    /
    

    如果目的是创建一个新的空表,则使用WHERE子句,条件永远不能为true:

    create table new_table as 
    select * from old_table
    where 1 = 2
    /
    

    记住创建表。。。因为SELECT只创建一个与源表具有相同投影的表。新表没有原始表可能具有的任何约束、触发器或索引。这些仍然需要手动添加(如果需要)。

        2
  •  33
  •   wallyk    16 年前

    select into 在pl/sql中用于将变量设置为字段值。相反,使用

    create table new_table as select * from old_table
    
        3
  •  5
  •   Scott Keith    12 年前

    create table new_table_name 
    as
    select column_name,[more columns] from Existed_table;
    

    例子:

    create table dept
    as
    select empno, ename from emp;
    

    如果表已存在:

    insert into new_tablename select columns_list from Existed_table;