zoukankan      html  css  js  c++  java
  • Oracle update 之部分更新

    建表语句。

    create table TABLEB (   ID       VARCHAR2(10),   TYPENAME VARCHAR2(10) ); create table TABLEA (   ID     VARCHAR2(10),   TYPEID VARCHAR2(10),   NAME   VARCHAR2(10) );

    insert into tableb (ID, TYPENAME) values ('1', 'type1');

    insert into tableb (ID, TYPENAME) values ('2', 'type2');

    insert into tableb (ID, TYPENAME) values ('3', 'type3'); insert into tablea (ID, TYPEID, NAME) values ('1', '1', 'name1');

    insert into tablea (ID, TYPEID, NAME) values ('2', '2', 'name2' );

    insert into tablea (ID, TYPEID, NAME) values ('3', '3', 'name3'  );

    insert into tablea (ID, TYPEID, NAME) values ('4', '4', 'name4');

    根据b表更新a表。部分更新。

    解决方案1:update tablea set typeid =
    case
      when
      (select name from tableb where tablea.typeid = tableb.id) is not null then
       (select name from tableb where tablea.typeid = tableb.id)
       else tablea.typeid
         end
    解决方案2:

    update tablea a set a.typeid = (select typename from tableb  where a.typeid = tableb.id)
     where exists (select * from tableb where a.typeid=tableb.id)

    两种解决方案都能够解决问题。

  • 相关阅读:
    Visual Studio 2013 的 Xamarin 安装教程
    BeesCMS后台登录SQL报错注入
    Linux系统更改IP地址
    SSRF漏洞
    代码执行漏洞
    Python零碎的知识(持续更新)
    iptables
    WAF学习_(2)安装
    WAF学习_(1)Lua基础
    SSL协议
  • 原文地址:https://www.cnblogs.com/thxuaimin/p/2882171.html
Copyright © 2011-2022 走看看