使用Oracle选择进入 [英] SELECT INTO using Oracle

查看:105
本文介绍了使用Oracle选择进入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Oracle进行SELECT INTO.我的查询是:

I'm trying to do a SELECT INTO using Oracle. My query is:

SELECT * INTO new_table FROM old_table;

但是出现以下错误:

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

有什么想法吗?

上述的标准行为应与我最初的想法相同: 但是,Oracle在自己的SQL方言中完全不同地实现了它. 插入时的Oracle文档...选择

The Standard behavior of the above should be as I originally thought: However Oracle implemented it totally differently in their own dialect of SQL Oracle Docs on Insert ... Select

推荐答案

如果NEW_TABLE已经存在,则...

If NEW_TABLE already exists then ...

insert into new_table 
select * from old_table
/

如果要基于OLD_TABLE中的记录创建NEW_TABLE ...

If you want to create NEW_TABLE based on the records in OLD_TABLE ...

create table new_table as 
select * from old_table
/

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

If the purpose is to create a new but empty table then use a WHERE clause with a condition which can never be true:

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

请记住,CREATE TABLE ... AS SELECT仅创建一个与源表具有相同投影的表.新表没有原始表可能具有的任何约束,触发器或索引.那些仍然必须手动添加(如果需要).

Remember that CREATE TABLE ... AS SELECT creates only a table with the same projection as the source table. The new table does not have any constraints, triggers or indexes which the original table might have. Those still have to be added manually (if they are required).

这篇关于使用Oracle选择进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆