update 表A set 字段a=(select 字段b from 表B where 表A.ID=表B.id)
where exists (select 1 from 表B where 表A.ID=表B.id);
where exists (select 1 from 表B where 表A.ID=表B.id);
解决方案 »
- Oracle plsql中tns plsql连接超时
- 请问oracle的DEFAULT_MAINTENANCE_PLAN是干什么用的?
- 高分求一查询语句
- 会分析 *.trc 跟踪文件的请进。(谢谢)
- 怎么将表空间sos的主人设置成用户ALPHA啊?而且ALPHA只能看到SOS表空间,怎么建立一个SID啊?
- 一台数据库上的表如何同另一台数据库上的表同步
- 转换成MS SQL的数据库
- 帮个忙,写条语句
- 我的代码错在那里了,请大家帮我看一下
- IMP导入时的表及索引HWM降低方式讨论
- 有一个ERP的程序在服务器上,客户端调用它访问oracle,为什么同时只能有三个用户并发,可数据库设置同时并发140呀?大家帮忙,谢谢!
- 请问select语句中for update of ......nowait是什么意思?
你的意思就是说可以使用语句修改,不必要使用游标了。难道是我的语句有问题吗?在SQL SERVER中
是没有问题的呀?
where exists (select 1 from 表B where 表A.ID=表B.id);这样改一下试试,不知道你的错误是什么。
下次问问题最好把错误提示贴出来,否则别人不好帮你判断。
TO: ORARichard(没钱的日子......)
还是不行呀?报告的错误为 ORA-01247 单行子查询返回多与一个行。
where exists (select 1 from 表B where 表A.ID=表B.id);
你这应该是只能修改一条记录吧!
我是想这么做,当表A和表B的ID值相同时,使表A.字段a=表B.字段b,并且是批量修改。
Connected as gdzc
SQL> create table table1(id number(10),com1 varchar2(20));Table createdSQL> create table table2(id number(10),com2 varchar2(20));Table createdSQL> insert into table1 values(1,'01');1 row insertedSQL> insert into table1 values(2,'02');1 row insertedSQL> insert into table1 values(3,'02');1 row insertedSQL> insert into table1 values(4,'04');1 row insertedSQL> insert into table2 values(1,'aa');1 row insertedSQL> insert into table2 values(2,'bb');1 row insertedSQL> insert into table2 values(3,'bb');1 row insertedSQL> commit;Commit completeSQL> select * from table1; ID COM1
----------- --------------------
1 01
2 02
3 02
4 04SQL> select * from table2; ID COM2
----------- --------------------
1 aa
2 bb
3 bb
SQL> update table1 set table1.com1=(select max(table2.com2) from table2 where table1.id=table2.id) ;4 rows updated
SQL> select * from table1; ID COM1
----------- --------------------
1 aa
2 bb
3 bb
4 SQL>
where exists (select 1 from 表B where 表A.ID=表B.id);
这个语句就没问题!你执行过吗?
select id from
(select id,count(id) cnt from 表B group by id) t
where cnt>1
可是我还是不清楚
update table1 set table1.com1=(select max(table2.com2) from table2 where table1.id=table2.id) 和
update table1 set table1.com1=(select table2.com2 from table2 where table1.id=table2.id)
加了max() 和没加 max()为什么执行结果确实一样的?
这事本人的最后一个问题。谢谢!!!!!!
update table1 set table1.com1=(select max(table2.com2) from table2 where table1.id=table2.id) 和
update table1 set table1.com1=(select table2.com2 from table2 where table1.id=table2.id)
加了max() 和没加 max()为什么执行结果确实一样的?
max(1)=1当然是成立的,呵呵