oracle从一个表中批量查询数据并插入到另一张表里 查询到的数据和其他数据一起插入

因为业务的需要,现在需要查询1个表里的数据并插入到另一个表内且对应自己想要对应的列。

且表的id应该是根据序列自动生成。
生成序列:
create sequence history_seq start with 1 increment by 1 nomaxvalue nocycle;
插入的sql:

INSERT INTO A
(ID,REQ_ID,UPLOAD_TS,NAME,P_ID,MOBILE,QUERY_REASON,GUARANTEE_TYPE,
LOAN_PURPOSE,CUSTOM_TYPE,APPLY_AMOUNT,LOAN_ID,HOME_ADDRESS,
HOME_PHONE,WORK_NAME,WORK_ADDRESS,WORK_PHONE,DEVICE_TYPE,IMEI,MAC,
IP_ADDRESS,OS_NAME,DEPT_CODE,ORG_ENTITY,DATA_STAT,RPT_STAT,BH_EXIST,
BATCH_NUM,MSG_NUM,USER_ID,CREATE_TIME,UPDATE_TIME,RPT_TYPE,
RPT_USETIME,ERR_DESC,RPT_TIME) 
(SELECT HISTORY_SEQ.NEXTVAL,b.REQ_ID,b.UPLOAD_TS,b.NAME,b.P_ID,b.MOBILE,
b.QUERY_REASON,b.GUARANTEE_TYPE,b.LOAN_PURPOSE,b.CUSTOM_TYPE,
b.APPLY_AMOUNT,b.LOAN_ID,b.HOME_ADDRESS,b.HOME_PHONE,b.WORK_NAME,
b.WORK_ADDRESS,b.WORK_PHONE,b.DEVICE_TYPE,b.IMEI,b.MAC,b.IP_ADDRESS,
b.OS_NAME,b.DEPT_CODE,b.ORG_ENTITY,b.DATA_STAT,b.RPT_STAT,b.BH_EXIST,
b.BATCH_NUM,b.MSG_NUM,b.USER_ID,b.CREATE_TIME,b.UPDATE_TIME,'2','0','',
SYSDATE 
FROM B b 
WHERE b.RPT_STAT = '4' AND b.BATCH_NUM = ':BATCH_NUM' 
AND b.ORG_ENTITY = ':ORG_ENTITY')

参考:https://blog.csdn.net/lindiwo/article/details/73863489

你可能感兴趣的:(数据库)