sql insert into 命令的使用 我想在表1的特定3行中插入数据,数据在表2里边请问命令如何写?

我需要把表2的1、2列插入到表1的a.b列前提是表2的b列不为空便插入表一同时表一的c列替换为111

设定table1的字段是a,b,c,table2的字段是c,d,e,table1和table2的对应字段类型一致,不然需要转换类型,当然这两张表的字段也可以更多,
只要将你要处理的字段分别替换成设定的字段就行。
insert into table1(a,b,c)
select c, d, 111
from table2
where d is not null
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-12-23
--这样?
insert into table1(column1, column2, column3...)
select 1, b.column1, b.column2...
from table2 as b
第2个回答  2011-12-23
直接使c列是'111' 是吧?是varchar类型吗?这是思路,你试一下
insert into t1 (
select t2.*,'111' c from t2 where b is not null and rownum < 3 );
第3个回答  2011-12-23
同楼上,不过得确认你的这三列外的值可以为空或者有默认值才可以这样插数据。as b类似同义词,将table2同义为b
相似回答