插入从选择序列和组通过
问题描述:
我想插入一些数据到表tableA
,但我必须使用group by
和my_sequence.nextval
。在相同的语句中使用两者是不可能的,是否存在任何解决方法?插入从选择序列和组通过
例如:执行该statment
insert into tableA (
taba_id,
taba_sum,
taba_date
) select
tabb_sequence.nextval,
sum(tabb_value),
tabb_date
from
tableB group by (tabb_date);
后,我得到了:
ORA-02287: sequence number not allowed here
根据Oracle文档,我应该得到这个错误。 如何通过calns在一个语句中处理序列和组?
答
这里的问题是因为你的序列没有被聚合,因此你有这个错误。试试这个方法:
insert into tableA (
taba_id,
taba_date,
taba_sum
)
select tabb_sequence.nextval,
tabb_date,
stv
from (select tabb_date,
sum(tabb_value) stv,
from tableB
group by tabb_date) a;