百度
360搜索
搜狗搜索

select into和insert into的区别,select Insert into和Insert into select的区别详细介绍

本文目录一览: select into与insert into的区别

众所周知,insert into作为插入语句,用来向表插入指定数据。语法如下:
也可以插入查询的数据,通常用来做数据的转移、清洗、降维,语法如下:
这种方式要求目标表必须存在。
作为另一种复制表数据的手段,其得到的结果与上述的 insert into select 是一样。 不过select into不要求目标表存在,目标表会在查询过程中自动创建。

Oracle中insert into select和select into的区别

您好,很高兴为您解答。
insert into select可以将select 出来的N行(0到任意数)结果集复制一个新表中,select into from只能将"一行"结果复制到一个变量中。这样说吧,select into是PL/SQL language 的赋值语句。而前者是标准的SQL语句。
做一个测试看两者差别。
首先创建两个表,一个作为源表,一个作为目标表。
create table t_source( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) ); create table t_target( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) );
接着,插入测试数据
insert into t_source values(1,'测试数据1....1',sysdate-2,'N'); insert into t_source values(2,'测试数据1....2',sysdate-2,'N'); insert into t_source values(3,'测试数据1....3',sysdate-2,'N'); commit;测试insert into select 操作
insert into test2 select * from t_source where id=1; commit;测试select into 操作因为select into是一个plsql语言中的复制语句,和:=实现的目标一样。
create or replace procedure sp_sync_test is aa varchar2(100); v_record t_source%rowtype; begin select t1.testname into aa from t_source t1 where id = 1; dbms_output.put_line('普通变量 t1.testname= ' || aa); select t1.* into v_record from t_source t1 where id = 1; dbms_output.put_line('记录变量 t1.testname= ' || v_record.testname); end;
这里增加了原始类型的变量和记录类型的变量
如若满意,请点击右侧【采纳答案】,如若还有问题,请点击【追问】
希望我的回答对您有所帮助,望采纳!
~ O(∩_∩)O~
insert into ... select
是一条SQL语句。
select ... into
是PL/SQL的一条语句。
Oracle中insert into select和select into的区别:(select into 就相当于赋值语句,insert into是复制语句),在Oracle中,将一张表的数据复制到另外一个对象中。
通常会有这两种方法:insert into select 和 select into from。前者可以将select 出来的N行(0到任意数)结果集复制一个新表中,后者只能将"一行"结果复制到一个变量中。这样说吧,select into是PL/SQL language 的赋值语句。而前者是标准的SQL语句。
做一个简单测试,我们就可以很容易地看出两者的差别。
1、首先,我们创建两个表,一个作为源表,一个作为目标表;
create table t_source( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) );
create table t_target( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) );
2、接着,插入测试数据;
insert into t_source values(1,'测试数据1....1',sysdate-2,'N'); insert into t_source values(2,'测试数据1....2',sysdate-2,'N'); insert into t_source values(3,'测试数据1....3',sysdate-2,'N'); commit; 测试insert into select 操作insert into test2 select * from t_source where id=1; commit;
测试select into 操作:因为select into是一个plsql语言中的复制语句,和:=实现的目标一样。
create or replace procedure sp_sync_test isaa varchar2(100);v_record t_source%rowtype; beginselect t1.testname into aa from t_source t1 where id = 1;dbms_output.put_line('普通变量 t1.testname= ' || aa);
select t1.* into v_record from t_source t1 where id = 1;dbms_output.put_line('记录变量 t1.testname= ' || v_record.testname);
end;
3、这里增加了原始类型的变量和记录类型的变量,便于大家理解。
甲骨文股份有限公司(Oracle)是全球大型数据库软件公司,总部位于美国加州红木城的红木岸。在2008年,甲骨文股份有限公司是继Microsoft及IBM后,全球收入第三多的软件公司。Oracle数据库产品为财富排行榜上的前1000家公司所采用,许多大型网站也选用了Oracle系统。甲骨文股份有限公司于1989年正式进入中国,在北京、上海、广州和成都均设立了分支机构。
2016年1月,甲骨文表示会收购网站数据追踪服务商AddThis。2016年2月,甲骨文收购了云计算创业公司Ravello Systems。2017年6月7日发布的2017年美国《财富》500强,甲骨文公司排名第81位。2017年6月,《2017年BrandZ最具价值全球品牌100强》公布,甲骨文公司排名第46位。
参考资料
csdn博客.csdn博客[引用时间2018-1-12]

阅读更多 >>>  select语句查询,谁可以给我全部的SQL查询语句?

Oracle中insert into select和select into的区别

  在Oracle中,将一张表的数据复制到另外一个对象中。通常会有这两种方法:insert into select 和 select into from。
  前者可以将select 出来的N行(0到任意数)结果集复制一个新表中,后者只能将"一行"结果复制到一个变量中。这样说吧,select into是PL/SQL language 的赋值语句。而前者是标准的SQL语句。
Oracle中insert into select和select into的区别如下:
1、insert into相当于自定义数据数据插入
2、insert into select则相当于根据其他表的数据插入到被插入的表中。
比如,有如下要被插入的表,表名test ,字段名为id和name
用insert into的方法
insert into test values (1,'张三')
如果用insert into select的方法
insert into test select 1,'张三'
或者所插入的数据有其他表的来源:
insert into test select id,name from 其他表

Oracle中insert into select和select into的区别

Oracle中insert into select和select into的区别
oracle中insert into select用语将数据插入到表中。
select into 一般用于存储过程或函数等,将某个查询结果放入变量中。
举例:
1、insert into select
1
2
insert into a select * from b;
commit;
2、select into
create or replace procedure p_test
as
v_begintime varchar2(20);
v_endtime varchar2(20);
v_str varchar2(10);
begin
v_begintime:=to_char(sysdate,'yyyy-mm-dd hh24:mi:ss');
select 'badkano' into v_str from dual;--其中这句是将某个值放入v_str变量中
v_endtime:=to_char(sysdate,'yyyy-mm-dd hh24:mi:ss');
dbms_output.put_line('开始时间为:'||v_begintime);
dbms_output.put_line('结束时间为:'||v_endtime);
end;

Oracle中insert into select和select into的区别

insert into select
是普通的sql语句
select into
不是sql语句,是plsql语法里面的一种赋值语句
insert into select
要求目标表必须存在,由于目标表T已经存在,所以除了插入源表的字段外,还可以插入常量
select into
要求目标表不存在,因为在插入时会自动创建表,并将源表中指定字段数据复制到目标表中
具体参考
http://www.cnblogs.com/freshman0216/archive/2008/08/15/1268316.html
楼主您好
insert into 表1 select...是将select的结果集插入到表1中
select into不能单独使用,是存储过程中的给变量赋值的语句,select的结果集只能为一个数据,select 列1 into 变量1 from 表1 where id=123

Oracle中insert into select和select into的区别

Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) values(value1,value2,...)这种形式的在应用程序开发中必不可少。但在实际开发、测试过程中,经常会遇到需要表复制的情况,如将一个table1的数据的部分字段复制到table2中,或者将整个table1复制到table2中,这时候就要使用SELECT INTO 和 INSERT INTO SELECT 表复制语句了。
1.INSERT INTO SELECT语句
语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1
要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量。示例如下:
--1.创建测试表 create TABLE Table1 ( a varchar(10), b varchar(10), c varchar(10), CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED ( a ASC ) ) ON [PRIMARY] create TABLE Table2 ( a varchar(10), c varchar(10), d int, CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED ( a ASC ) ) ON [PRIMARY] GO --2.创建测试数据 Insert into Table1 values('赵','asds','90') Insert into Table1 values('钱','asds','100') Insert into Table1 values('孙','asds','80') Insert into Table1 values('李','asds',null) GO select * from Table2 --3.INSERT INTO SELECT语句复制表数据 Insert into Table2(a, c, d) select a,c,5 from Table1 GO --4.显示更新后的结果 select * from Table2 GO --5.删除测试表 drop TABLE Table1 drop TABLE Table2 2.SELECT INTO FROM语句
语句形式为:SELECT vale1, value2 into Table2 from Table1
要求目标表Table2不存在,因为在插入时会自动创建表Table2,并将Table1中指定字段数据复制到Table2中。示例如下:
--1.创建测试表 create TABLE Table1 ( a varchar(10), b varchar(10), c varchar(10), CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED ( a ASC ) ) ON [PRIMARY] GO --2.创建测试数据 Insert into Table1 values('赵','asds','90') Insert into Table1 values('钱','asds','100') Insert into Table1 values('孙','asds','80') Insert into Table1 values('李','asds',null) GO --3.SELECT INTO FROM语句创建表Table2并复制数据 select a,c INTO Table2 from Table1 GO --4.显示更新后的结果 select * from Table2 GO --5.删除测试表 drop TABLE Table1 drop TABLE Table2

阅读更多 >>>  将select结果insert,T-SQL语句中如何使用INSERT语句插入多行数据?

insert select的语句和select into语句的区别?

select into 和 insert into select 两种表复制语句
第一句(select into from)要求目标表(destTbl)不存在,因为在插入时会自动创建。
第二句(insert into select from)要求目标表(destTbl)存在,由于目标表已经存在,所以我们除了插入源表(srcTbl)的字段外,还可以插入常量.

select into from和insert into select都是用来复制表,两者有什么区别

select into from 和 insert into select都是用来复制表,两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建。insert into select from 要求目标表存在。
备份表数据: create table emp as select * from scott.emp
还原表数据:insert into emp select * from scott.emp
复制表结构及其数据:
create table table_name_new as select * from table_name_old
只复制表结构:
create table table_name_new as select * from table_name_old where 1=2;
或者:
create table table_name_new like table_name_old
只复制表数据:
如果两个表结构一样:
insert into table_name_new select * from table_name_old
如果两个表结构不一样:
insert into table_name_new(column1,column2...) select column1,column2...
from table_name_old pasting

select Insert into和Insert into select的区别

select * into new_table from old_table
要求new_table不存在
insert into new_table
select * from old_table
要求new_table存在
1.INSERT INTO SELECT语句
语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1
要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量
2.SELECT INTO FROM语句
语句形式为:SELECT vale1, value2 into Table2 from Table1
要求目标表Table2不存在,因为在插入时会自动创建表Table2,并将Table1中指定字段数据复制到Table2中
若使要实现你所要的功能,为什么不使用exists呢?
insert into相当于自定义数据数据插入,而insert into select则相当于根据其他表的数据插入到被插入的表中。
比如,有如下要被插入的表,表名test ,字段名为id 和 name
用insert into的方法
insert into test values (1,'张三')如果用insert into select的方法
insert into test select 1,'张三'或者所插入的数据有其他表的来源:
insert into test select id,name from 其他表

网站数据信息

"select into和insert into的区别,select Insert into和Insert into select的区别"浏览人数已经达到25次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:select into和insert into的区别,select Insert into和Insert into select的区别的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!