当前位置: 代码迷 >> Oracle开发 >> 这条sql语句如何写?能写吗
  详细解决方案

这条sql语句如何写?能写吗

热度:122   发布时间:2016-04-24 06:39:53.0
这条sql语句怎么写?能写吗?
本帖最后由 xingshen100 于 2014-07-16 16:47:07 编辑
insert into table1 values( “数据”);


关键是这里的数据是这样的:首先一条select查询语句得到前部分的字段的值,后部分几个个字段的值是常量。



求大神指点怎么做???
------解决方案--------------------
insert into table1 
select 字段,"数据" from 表
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

insert into table1 values( “数据”);


关键是这里的数据是这样的:首先一条select查询语句得到前部分的字段的值,后部分几个个字段的值是常量。



求大神指点怎么做???

insert into table select 字段
------解决方案--------------------
常量 from table;
insert into table1 values(select * from table2,'常量1“,"常量2”,"常量3”)           我的目的就是这样的。              你这里
------解决方案--------------------
代表什么意思?另外我select的是另一个表

注意字段类型和数量必须和被插入的表一致
insert into table select t.*,"常量1“,"常量2”,"常量3" from table2 t
------解决方案--------------------

-- LZ ,给你一个例子。
create table a (id int , c1 varchar(10) , c2 varchar(10) , c3 varchar(10))
create table b (id int , c1 varchar(10)) 
insert into b(id , c1) values(1,'a')
-- 下面的语句,就是你想的效果,和其他人的回复也是这意思 
insert into a(id , c1,c2,c3) select id , c1 , 'china','beijing' from b 

select * from a 
  相关解决方案