Oracle:在单个语句中应用多个更新?

时间:2016-01-26 17:32:32

标签: sql oracle

假设我只使用另一个表中的数据对一个表进行了简单更新。

public void test() throws IOException {
    Socket sock = new Socket("127.0.0.1", 1234);
    InputStream is = sock.getInputStream();
    boolean done = false;
    while (!done) {
        int available;
        if ((available = is.available()) > 0) {
            // Your read stuff.
            is.read(buffer, 0, available);
        }
    }
}

如何在一个语句中对多个id应用类似的更新?在我的大脑中,我正在反复思考这样的事情:

update t1
   set (a,b) = (select a,b from t2 where id=17)
 where id=17;

通用SQL首选,但也欢迎特定于Oracle的解决方案。

1 个答案:

答案 0 :(得分:1)

怎么样:

update t1
   set (a, b) = (select a,b from t2 where t2.id=t1.id)
 where t1.id in (select id from t2 where ...);