【问题标题】:When i Update same table column with calculate another columns values当我用计算其他列值更新同一个表列时
【发布时间】:2017-04-18 07:19:18
【问题描述】:
Update dp2 a set a.amt= (select((b.qty*b.rate)-b.discount) from dp2 b where a.dpinheadid=b.dpinheadid)

错误来了

ORA-01427: single-row subquery returns more than one row
#For.Ex: TABLES DP2 A,DP2 B
(b.qty*b.rate)-b.discount) THIS VALUE Update TO This column A.AMT

【问题讨论】:

  • 添加一些示例表数据,包括版本之前和之后的版本。 (以及格式化文本,使用{}。)

标签: sql oracle11g oracle10g


【解决方案1】:

问题是您尝试使用返回多于 1 行select 语句更新行。

这个选择:

select((b.qty*b.rate)-b.discount) from dp2 b where a.dpinheadid=b.dpinheadid

返回超过 1 个结果 - 因此您不能将其用作更新值。

如果你想使用它,你需要它返回单个值,所以尝试使用WHERE 子句或TOP 1 只返回第一个结果,等等。

【讨论】:

  • 那么 OP 现在应该做什么?
  • 你只问了
【解决方案2】:

你试过这个查询吗:

Update dp2 a set a.amt= a.qty*a.rate-a.discount 

【讨论】:

  • @siva 有用吗?如果是,请随时接受我的回答。如果没有,请告诉我
猜你喜欢
  • 2012-04-20
  • 2019-03-09
  • 1970-01-01
  • 2016-10-14
  • 2011-07-16
  • 1970-01-01
  • 2019-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多