Oracle 10g:插入多行 [英] Oracle 10g: Inserting multiple rows

查看:104
本文介绍了Oracle 10g:插入多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 select语句:

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;

返回多个行,例如:

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.

问题

我应该如何编写insert语句?我是否应该使用游标,因为似乎INSERT可以一次处理一行?

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

推荐答案

使用select作为插入的来源:

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;

没有必要将UNION的各个查询放在括号之间.

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

这篇关于Oracle 10g:插入多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆