Oracle 10g: Inserting multiple rows

空扰寡人 提交于 2019-12-11 15:26:22

问题


I'm having the following select statement :

select dte, wm_concat(issue) as issues
from ((select date_a as dte, issue from t where date_a is not null) union all
      (select date_b, issue from t where date_b is not null)
     ) di
group by dte
order by dte;

that returns multiple rows such as:

DTE        | ISSUES
-----------+---------
01/JUN/91  | EE
01/JUN/03  | EE
01/JAN/06  | HH
01/AUG/06  | EE
01/AUG/08  | EE,HS,HE

I would like insert these records into a table.

Question

How should I write the insert statement ? Should I use a cursor as it seems INSERT can process one row at time ?


回答1:


Use the select as the source for the insert:

insert into some_table (dte, issues)
select dte, wm_concat(issue) as issues
from (
   select date_a as dte, issue 
   from t 
   where date_a is not null
   union all
   select date_b, issue 
   from t 
   where date_b is not null
) di
group by dte;

There is no need to put the individual queries of a UNION between parentheses.



来源:https://stackoverflow.com/questions/52058972/oracle-10g-inserting-multiple-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!