需求是這樣的,先在一個從句中根據sub_code查詢dis_code和reg_code,
再把這;兩個值作為insert value的一部分,差到rate表里,好了,這里提供一種常規做法,和一種用with實現的做法
常規做法:
insert into HW_RATE (ID, SUB_TYPE, DISTRICT_CODE, REGION_CODE, SUB_AREA_CODE, CREATE_DATE, CREATE_USER) select sys_guid(), 2, o.district_code bu, o.region_code re, '60487', sysdate, 'ww00068' from eis_user.org_office o where o.sub_area_code = '60487' and o.status = 1 and o.year = extract(year from sysdate) and o.sub_type = 2
用with的用法:
insert into HW_RATE (ID, SUB_TYPE, DISTRICT_CODE, REGION_CODE, SUB_AREA_CODE, CREATE_DATE, CREATE_USER) with areaInfo as (select o.district_code bu, o.region_code re from eis_user.org_office o where o.sub_area_code = '60487' and o.status = 1 and o.year = extract(year from sysdate) and o.sub_type = 2) select sys_guid(), 2, areaInfo.bu,//這里直接with 臨時表別名.子句查詢結果別名,即可 areaInfo.re, '60487', sysdate, 'ww00068' from areaInfo
唯一需要注意的就是,with語句后面直接只能跟select語句,稍微換下思路就可以吧insert和with結合使用了