ORA-01427: 单行子查询返回多于一个行,请教高手:怎么改?

updateitemactivitydetailidsetid.lngorderdetailid=(selectlngactivitydetailid27from(sel... update itemactivitydetail id
set id.lngorderdetailid = (select lngactivitydetailid27
from (select id1.lngactivityid,
id1.lngactivitydetailid,
id1.lngitemid
from itemactivity i1,
itemactivitydetail id1
where i1.lngactivityid =
id1.lngactivityid
and i1.lngactivitytypeid = 28
and id1.lngorderdetailid = 0) a28,
(select id2.lngitemid,
i2.lngorderactivityid,
id2.lngactivitydetailid as lngactivitydetailid27
from itemactivity i2,
itemactivitydetail id2
where i2.lngactivityid =
id2.lngactivityid
and i2.lngactivitytypeid = 27) a27
where a28.lngitemid = a27.lngitemid
and a28.lngactivityid =
a27.lngorderactivityid
and a28.lngactivitydetailid =
id.lngactivitydetailid)
where exists
(select 1
from (select id1.lngactivityid,
id1.lngactivitydetailid,
id1.lngitemid
from itemactivity i1, itemactivitydetail id1
where i1.lngactivityid = id1.lngactivityid
and i1.lngactivitytypeid = 28
and id1.lngorderdetailid = 0) a28,
(select id2.lngitemid,
i2.lngorderactivityid,
id2.lngactivitydetailid as lngactivitydetailid27
from itemactivity i2, itemactivitydetail id2
where i2.lngactivityid = id2.lngactivityid
and i2.lngactivitytypeid = 27) a27
where a28.lngitemid = a27.lngitemid
and a28.lngactivityid = a27.lngorderactivityid
and a28.lngactivitydetailid = id.lngactivitydetailid)
展开
 我来答
airson79
2010-09-19 · TA获得超过835个赞
知道小有建树答主
回答量:767
采纳率:100%
帮助的人:538万
展开全部
在update的时候,子查询返回是多条,你首先必须要确定怎么从这多条里面选择一条出来,比如你可以选最大的select max(lngactivitydetailid27) 最小的select min(lngactivitydetailid27),当然也可以选第一条出来,改完的句子类似于:
update itemactivitydetail id
set id.lngorderdetailid = (select max(lngactivitydetailid27)
from (select id1.lngactivityid,
id1.lngactivitydetailid,
id1.lngitemid
from itemactivity i1,
itemactivitydetail id1
where i1.lngactivityid =
id1.lngactivityid
and i1.lngactivitytypeid = 28
and id1.lngorderdetailid = 0) a28,
(select id2.lngitemid,
i2.lngorderactivityid,
id2.lngactivitydetailid as lngactivitydetailid27
from itemactivity i2,
itemactivitydetail id2
where i2.lngactivityid =
id2.lngactivityid
and i2.lngactivitytypeid = 27) a27
where a28.lngitemid = a27.lngitemid
and a28.lngactivityid =
a27.lngorderactivityid
and a28.lngactivitydetailid =
id.lngactivitydetailid
and rownum <=1)
where exists
(select 1
from (select id1.lngactivityid,
id1.lngactivitydetailid,
id1.lngitemid
from itemactivity i1, itemactivitydetail id1
where i1.lngactivityid = id1.lngactivityid
and i1.lngactivitytypeid = 28
and id1.lngorderdetailid = 0) a28,
(select id2.lngitemid,
i2.lngorderactivityid,
id2.lngactivitydetailid as lngactivitydetailid27
from itemactivity i2, itemactivitydetail id2
where i2.lngactivityid = id2.lngactivityid
and i2.lngactivitytypeid = 27) a27
where a28.lngitemid = a27.lngitemid
and a28.lngactivityid = a27.lngorderactivityid
and a28.lngactivitydetailid = id.lngactivitydetailid)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式