请一个SQL语句

rngn 2006-02-21 11:51:03
table1 字段 a1,a2,a3,a4 主键 a1
table2 字段 a1,b2,b3,b4 主键 a1
现在想更新table1中满足table1.a1=table2.a1记录中字段a2的值 , table1.a2=table1.a2-table2.b2
我写的
update table1 a set table1.a2=table1.a2 - (select b.b2 from table2 b
where a.a1=b.a1 and a.a4='000001')
where a.a4='000001'
我感觉没问题 可是总执行不了 提示 ORA-00936: 缺少表达式
使用oracle8.0.5
...全文
180 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ourlin 2006-02-22
  • 打赏
  • 举报
回复
>> update table1 a set table1.a2=table1.a2 - (select b.b2 from table2 b
>>where a.a1=b.a1 and a.a4='000001')
>>where a.a4='000001'

改为:

update table1 set a.a2=a.a2 -b.b2 from table1 a, table2 b
where a.a1=b.a1 and a.a4='000001'






rngn 2006-02-22
  • 打赏
  • 举报
回复
谢谢各位了。可是我还是无法执行,楼上的2位我看了一下。好象也没有问题,可是问题依然。
和 我写的好象也差不多。但为什么?????谁能给我解释一下。难道和ORACLE有关系???
请各位实验一下。。。再次谢谢大家的关注!!!!!!!!!!!!
rngn 2006-02-21
  • 打赏
  • 举报
回复
请问楼上的 这个SQL语句在ORACLE能执行吗?
Antiquesoft 2006-02-21
  • 打赏
  • 举报
回复
update table1 set ColA = '' from table1 a, (Select ColA from tableB) b
where a.ColA = b.ColA
jadeluo 2006-02-21
  • 打赏
  • 举报
回复
update table1 a
set a.a2 = a.a2 - (select b.b2 from table2 b where b.a1 = a.a1)
where a.a4='000001'
Tensionli 2006-02-21
  • 打赏
  • 举报
回复
update table1 a set a2=a2-(select b2
from table2 b
where a.a1=b.a1 and a.a4='000001')
where a.a1=(select a1 from table2 c where a.a1=c.a1) and a.a4='000001';

rngn 2006-02-21
  • 打赏
  • 举报
回复
首先谢谢apartst,但是你写的 我实验了一下无法执行!错误!
也谢谢 ncwuhh 关注,但我就是执行不了使用的是oracle8.0.5
不会和oracle版本有关系吧!呵呵!
ncwuhh 2006-02-21
  • 打赏
  • 举报
回复
楼主的写法应该是没问题的,是不是执行时少加了一个分号";"
apartst 2006-02-21
  • 打赏
  • 举报
回复
update table1
set table1.a2=table1.a2-table2.b2
from table2
where table1.a1=table2.a1

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧