请教一下:比较两个表每行数据的id,如果相同,就用一个表中的列更新另一个表?这个upd

[复制链接]
查看11 | 回复3 | 2011-11-1 16:20:28 | 显示全部楼层 |阅读模式
请教一下:比较两个表每行数据的id,如果相同,就用一个表中的列更新另一个表?这个update应该怎么写呢?
回复

使用道具 举报

千问 | 2011-11-1 16:20:28 | 显示全部楼层
是这个意思吗 ?
CREATE TABLE TEST (
id
NUMBER (8)NOT NULL,
name varchar2 (200))
CREATE TABLE TEST1 (
id
NUMBER (8)NOT NULL,
name varchar2 (200))
CREATE OR REPLACE Procedure updatetest
as
cursor test1_cursor is


select* from land.test1 ;

reftest1 test1_cursor%rowtype;

begin
open test1_cursor;
loop
fetch test1_cursor into reftest1;

exit when test1_cursor%notfound;



update test set name=reftest1.namewhere docid =reftest1.id;


end loop;
close test1_cursor;

end updatetest;
/
回复

使用道具 举报

千问 | 2011-11-1 16:20:28 | 显示全部楼层
update tabA set cola = (select cola from tabB where tabB.cola = taba.cola and rownum<2)
回复

使用道具 举报

千问 | 2011-11-1 16:20:28 | 显示全部楼层
http://zhouwf0726.itpub.net/post/9689/205013
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行