字段匹配的前提下,INSERT INTO B [此处填写,选择插入所需字段] SELECT [此处填写A表需要插到B表的字段] FROM A WHERE 后面加插入条件
范例:INSERT INTO Future
SELECT Substring(a.sDeptNO,1,1)+'处',Sum(a.nFutureSaleAmount)
FROM Future a,tDept b
WHERE a.sDeptNO = b.sDeptNO GROUP BY Substring(a.sDeptNO,1,1)
1、先创建a和b表的序列CREATE SEQUENCE SEQ_A
CREATE SEQUENCE SEQ_B
2、插入A表并返回A表当前ID
v_id1 number(20)
insert into a (ID1,name,sex)values(SEQ_A.NEXTVAL,name_value,sex_value) return ID1 into v_id1
3、插入B表
insert into b (ID2,ID1,Fraction)values(SEQ_B.NEXTVAL,v_id1,franction_value)
4、事务提交
commit
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)