insert oracle用法,insert into select的实际用法,insertselect
insert into select的实际用法,insertselect
INSERT INTO SELECT语句
语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1
或者:Insert into Table2 select * from Table1
注意:(1)要求目标表Table2必须存在,并且字段field,field2...也必须存在
(2)注意Table2的主键约束,如果Table2有主键而且不为空,则 field1, field2...中必须包括主键
(3)注意语法,不要加values,和插入一条数据的sql混了,不要写成:
Insert into Table2(field1,field2,...) values (select value1,value2,... from Table1)
由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量。示例如下:
业务背景:在部分字段有变化的情况下,需要把部分数据复制插入到表里;
insert into MARKETING_JUMP_MANAGE (ID,JUMP_CHANNEL,JUMP_CLASS, STATE, CREAT_TIME, UPDATE_TIME, CREAT_NAME, UPDATE_NAME, SHOW_STATE, POSITION_NAME, POSITION_CODE, COMPONENT_ID, COMPONENT_NAME, CUSTOM, JUMP_NAME,jump_channel_name)
SELECT SEQ_SUBSET_MESSAGE.NEXTVAL ,b.* from
(
SELECT '60',JUMP_CLASS, STATE, CREAT_TIME, UPDATE_TIME, CREAT_NAME, UPDATE_NAME, SHOW_STATE, POSITION_NAME, POSITION_CODE, COMPONENT_ID, COMPONENT_NAME, CUSTOM, JUMP_NAME, 'XX渠道'
FROM MARKETING_JUMP_MANAGE c
where c.jump_channel='2'
)b;
分析sql:
1.insert语句全部字段
2.自增id 通过序列 SEQ_SUBSET_MESSAGE.NEXTVAL 查询
3.部分变化字段可以 直接写死,如上sql '60', 'XX渠道'
http://www.dengb.com/oracle/1333545.htmlwww.dengb.comtruehttp://www.dengb.com/oracle/1333545.htmlTechArticleinsert into select的实际用法,insertselect INSERT INTO SELECT 语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1 或者:Ins...
更多推荐
所有评论(0)