最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

Oracle把一个表中的数据插入到另外一个表中

来源:动视网 责编:小采 时间:2020-11-09 11:43:00
文档

Oracle把一个表中的数据插入到另外一个表中

Oracle把一个表中的数据插入到另外一个表中:1.在oracle中可以用下面两种:01: create table newtable as select * from oldtable;//用于复制前未创建新表newtable不存 1.在Oracle中可以用下面两种: 01: create table newtable as select * from oldtab
推荐度:
导读Oracle把一个表中的数据插入到另外一个表中:1.在oracle中可以用下面两种:01: create table newtable as select * from oldtable;//用于复制前未创建新表newtable不存 1.在Oracle中可以用下面两种: 01: create table newtable as select * from oldtab


1.在oracle中可以用下面两种:01: create table newtable as select * from oldtable;//用于复制前未创建新表newtable不存

1.在Oracle中可以用下面两种:

01:
create table newtable as select * from oldtable;//用于复制前未创建新表newtable不存在的情况
02:
insert into newtable select * from oldtable;//已经创建了新表newtable 的情况

注意:第一种方式只是复制了表结构,,但是主键什么的并没有复制进去,所以用的时候要小心在意。

2.如果想简单快速的复制表结构,而不需要oldtable里面的数据,可以用下面的语句:

create table newtable as select * from oldtable where 1=2;(把数据过滤掉)

3.如过newtable 和oldtable的表结构不同,可以使用下面的方式:

create table newtable as select s.c1,s.c2 from oldtable s;

4.如果想重新命名newtable的列名:

在oracle中:

create table newtable(id,name1) as select s.c1,s.c2 from oldtable s;

或者

create table newtable as select s.c1 ,s.c2 from oldtable s;

在mysql中恐怕只能用第二种方式了。

5.如果是只需要把一部分的oldtable中的数据添加到newtable中。可以这样:

create table newtable as (select * from oldtable where ...);//加where过滤条件

6.最常见的情况是id列新表中要用,并且和旧表中的不同,使用下面的语句就可以了(我们可以重新建一个sequence)

create table yang(id,name) as select hibernate_sequence.nextval,t.ename from emp t;

7.要注意,导出表的时候不能用select...into语句。

文档

Oracle把一个表中的数据插入到另外一个表中

Oracle把一个表中的数据插入到另外一个表中:1.在oracle中可以用下面两种:01: create table newtable as select * from oldtable;//用于复制前未创建新表newtable不存 1.在Oracle中可以用下面两种: 01: create table newtable as select * from oldtab
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top