从table1选数据插入到table2
insert语句普通写法
INSERT INTO TABLE2(字段1,字段2) values(值1,值2)
把一张配置表TABLE1的某些字段查询出来插入到另一张表TABLE2中去:
//tab1和tab2字段数目对应,tab1和tab2可以是同一个表
insert into tab1 (select * from tab2)
//tab1和tab2字段不对应A中有3例,B表中你只能获得2列,可以用常量占位解决
insert into tableA (列1,列2,列3) select 列1,列2,常量 from tableB
例:如下
insert into tableA (列1,列2,列3) select 列1,列2,'123' from tableB 【字符串常量】
insert into tableA (列1,列2,列3) select 列1,列2,123 from tableB 【数值常量】
例如:
```sql
INSERT INTO TABLE2(UUID,UNITID, TARGET_TYPE)
SELECT '74fdac29-118a-492b-885b-58a3e12b70f4' AS UUID,conf.UNITID AS UNITID,'P' AS TARGET_TYPE FROM TABLE1 conf WHERE DEVID='w999' AND UNITID='1';
COMMIT;
使用示例:
app.run("insert into w_file (ID,t_name,f_path,f_type,record_tim,f_name,t_id) \n" +
"(select SYS_GUID(),t_name,f_path,f_type,record_tim,f_name ,{?newTID?}from w_file where t_id={?T_ID?} and f_type in ('船舶资料','吨位证书') )");