关于ORACLE数据库UPDATE的问题!!!

smlstar 2003-05-22 12:47:12
tab a (col1,col2)
tab b (col1,col3)

update a set a.col1=b.col3 from a,b where a.col1=b.col1这句在SQLserver可以执行,在oracle下不行。请教在oracle下面怎么改?100分相送!
...全文
73 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
xudazhi 2003-05-26
  • 打赏
  • 举报
回复
update a
2 set
3 a.col1=(select col3 from a,b where a.col1=b.col1)
4 where a.col1=(select a.col1 from a,b where a.col1=b.col1)
5 ;
改成
update a
2 set
3 a.col1=(select col3 from a,b where a.col1=b.col1)
4 where exists (select col3 from a,b where a.col1=b.col1);
会快一些
Qihua_wu 2003-05-24
  • 打赏
  • 举报
回复
真是的Trigger竟然没人认识,算了,不用也罢,你们慢慢去写什么cursor、Procedure吧
smlstar 2003-05-23
  • 打赏
  • 举报
回复
用sqlplus可以执行又表吗?可以用ado 的 pconnect->excute()来执行吗?
nojuli 2003-05-23
  • 打赏
  • 举报
回复
用cursor好了,不会很困难的。。
jiezhi 2003-05-22
  • 打赏
  • 举报
回复
update a
set
a.col1=(select col3 from a,b where a.col1=b.col1)
where a.col1=b.col1
caspling 2003-05-22
  • 打赏
  • 举报
回复
update a set a.col1=(select b.col3 from a,b where a.col1=b.col1)
zzyok 2003-05-22
  • 打赏
  • 举报
回复
写个简单的存储过程吧,用游标或者动态sql来解决你的问题
smlstar 2003-05-22
  • 打赏
  • 举报
回复
??
smlstar 2003-05-22
  • 打赏
  • 举报
回复
如果是返回多条怎么处理呀?我就是要批量更新数据呀。
jiezhi 2003-05-22
  • 打赏
  • 举报
回复
当然select a.col1 from a,b where a.col1=b.col1只能返回一条记录
jiezhi 2003-05-22
  • 打赏
  • 举报
回复
SQL> select * from a;

COL1 COL2
--------------------------------------- ---------------------------------------
1 100
2 200

SQL> select * from b;

COL1 COL3
--------------------------------------- ---------------------------------------
1 900
3 700

SQL>
SQL> update a
2 set
3 a.col1=(select col3 from a,b where a.col1=b.col1)
4 where a.col1=(select a.col1 from a,b where a.col1=b.col1)
5 ;

1 row updated

SQL> select * from a;

COL1 COL2
--------------------------------------- ---------------------------------------
900 100
2 200

SQL>
shuipipi 2003-05-22
  • 打赏
  • 举报
回复
呵呵~

那就是泥的问题了,看看泥给的字段名和表中的实际字段名是否一致?
jiezhi 2003-05-22
  • 打赏
  • 举报
回复
update a
set
a.col1=(select col3 from a,b where a.col1=b.col1)
where a.col1=(select a.col1 from a,b where a.col1=b.col1)
smlstar 2003-05-22
  • 打赏
  • 举报
回复
致jiezhi(西域浪子) 和 ccbzzp(ccbzzp)
我把你们的语句在sqlplus试了一下,系统提示
ORA-00904: invalid column name

where a.col1=b.col1
*
ccbzzp 2003-05-22
  • 打赏
  • 举报
回复
jiezhi(西域浪子)

你寫的好像不太嚴禁的
ccbzzp 2003-05-22
  • 打赏
  • 举报
回复
update a
set
a.col1=(select col3 from a,b where a.col1=b.col1)
where a.col1=b.col1 AND B.COL1 IS NOT NULL

3,490

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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