Oracle SQL:在带有 Select 语句的插入中使用序列
基本上我想运行以下查询:
INSERT INTO historical_car_stats (historical_car_stats_id, year, month, make, model, region, avg_msrp, count)
SELECT
my_seq.nextval,
'2010',
'12',
'ALL',
'ALL',
region,
sum(avg_msrp * count) / sum(count),
sum(count)
FROM historical_car_stats
WHERE year = '2010'
AND month = '12'
AND make != 'ALL'
GROUP BY region;
它不起作用,因为“此处不允许序列号”SQL 错误。我该如何写这个以便 Oracle 让我做我想做的事?
Basically I want to run the following query:
INSERT INTO historical_car_stats (historical_car_stats_id, year, month, make, model, region, avg_msrp, count)
SELECT
my_seq.nextval,
'2010',
'12',
'ALL',
'ALL',
region,
sum(avg_msrp * count) / sum(count),
sum(count)
FROM historical_car_stats
WHERE year = '2010'
AND month = '12'
AND make != 'ALL'
GROUP BY region;
It doesn't work because "sequence number not allowed here" SQL error. How can I write this so Oracle will let me do what I want to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您想在使用序列生成密钥之前对数据进行分组,听起来您想要类似的东西
Assuming that you want to group the data before you generate the key with the sequence, it sounds like you want something like
我测试了一下,脚本运行正常!
你可以阅读这篇文章来了解更多!
http://www.orafaq.com/wiki/ORA-02287
I tested and the script run ok!
you can read this article to understand more!
http://www.orafaq.com/wiki/ORA-02287