欢迎投稿

今日深度:

update进行跨表之间的更新,update跨表更新

update进行跨表之间的更新,update跨表更新


有时我们可能需要多个表之间进行更新数据。我们可以使用这个语句

UPDATE table1,table2 SET table1.column=table2.column, table1.column1=table2.column1
WHERE table1.column3=table2.column3



两个表之间更新数据

应该是用SQL语句吧?

update table1 set count=table2.count from table2 where table2.tid=table1.id

这样就可以实现table1表的更新了

=====================================================================================
这已经是最好的方法了好不好.

而且效率很高啊,这是直接连接两上表来更新数据.
 

oracle 10g中通过update关键字跨表更新

1、update emp A,emp2 B set B.comm=A.comm WHERE B.empno=A.empno;
2、update emp2 B set B.comm=(select A.comm emp A where A.empno=B.empno group by A.comm);
如果不增加group by,存在重复值会报错。
3、将所有id存为一个文件或者指定id
spoll id.txt
select empno from emp;
spool off

写个shell
#!/bin/sh
cid=$1
if [ -z "$1" ];then
echo "Usage : $0 id.txt"
exit 1;
fi
for id in `cat id.txt`;do
echo -e "update emp2 B set B.comm=(select A.comm from emp A where A.empno='$id')
where B.id='$id';"
done | sqlplus -s 'user/123456'
 

www.htsjk.Com true http://www.htsjk.com/shujukunews/2470.html NewsArticle update进行跨表之间的更新,update跨表更新 有时我们可能需要多个表之间进行更新数据。我们可以使用这个语句 UPDATE table1,table2 SET table1.column=table2.column, table1.column1=table2.column1WHERE table...
评论暂时关闭