更新oracle中的多行
你能告诉我如何更新 oracle 中的多行吗,当我触发更新语句时,它给了我以下错误
UPDATE BI_BSELATEST_LATESTPRICESTEST
SET PREVIOUS_DAY_CLOSE =
(SELECT DISTINCT aa.DLYPRICE_CLOSE
FROM DATAFEED_EQTY.FEED_DLYPRICE aa ,
(
SELECT a.sc_code , MAX(a.DLYPRICE_DATE) as max_date
from DATAFEED_EQTY.FEED_DLYPRICE a,BI_BSELATEST_LATESTPRICES b
where a.SC_CODE = b.SC_CODE
and a.ST_EXCHNG = 'BSE'
and a.DLYPRICE_DATE < b.upd_time
group by a.sc_code
) bb
WHERE aa.SC_CODE = bb.sc_code
and aa.DLYPRICE_DATE = max_date)
ORA-01427: 单行子查询返回多行
提前致谢
Can you tell me how to update multiple rows in oracle as when I fired the update statement it gave me the following error
UPDATE BI_BSELATEST_LATESTPRICESTEST
SET PREVIOUS_DAY_CLOSE =
(SELECT DISTINCT aa.DLYPRICE_CLOSE
FROM DATAFEED_EQTY.FEED_DLYPRICE aa ,
(
SELECT a.sc_code , MAX(a.DLYPRICE_DATE) as max_date
from DATAFEED_EQTY.FEED_DLYPRICE a,BI_BSELATEST_LATESTPRICES b
where a.SC_CODE = b.SC_CODE
and a.ST_EXCHNG = 'BSE'
and a.DLYPRICE_DATE < b.upd_time
group by a.sc_code
) bb
WHERE aa.SC_CODE = bb.sc_code
and aa.DLYPRICE_DATE = max_date)
ORA-01427: single-row subquery returns more than one row
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的语句中的子查询是错误的。您遗漏了
WHERE
或FIRST
子句,现在它在不应该返回的情况下返回了多个值。您基本上是想说
PREVIOUS_DAY_CLOSE
应该同时是多个值。我猜您在子选择中遗漏了一个WHERE
子句,该子句会将该子查询的结果链接到您尝试更新的特定行。类似于(注意粗体线):不过,老实说,我不太确定您想对这个查询做什么。
A subquery in your statement is wrong. You left off either a
WHERE
orFIRST
clause, and now it's returning multiple values when it shouldn't.You're basically trying to say
PREVIOUS_DAY_CLOSE
should be multiple values at the same time. I'm guessing you left off aWHERE
clause on your subselect, which would link the results of that subquery to the particular row you're trying to update. Something like (note the bolded line):Although, I'll be honest, I'm not exactly sure what you're trying to do with this query.
我认为您想要的是这样的:
这将从子查询中删除 BI_BSELATEST_LATESTPRICESTEST ,并告诉数据库使用它正在更新的表中的列来过滤子查询。正如您所写的,数据库无法知道如何将子查询中的列与正在更新的表相关联。
I think what you want is this:
This removes BI_BSELATEST_LATESTPRICESTEST from the sub-query and instead tells the database to use the columns from the table that it is updating to filter the sub-query. As you had written it, the database had no way of knowing how to correlate the columns from the sub-query to the table being updated.