update 操作用法
--update 这个字段的所值为2
update tab a set a.字段1=2;
--带条件的update
update tab a set a.字段1=2 where id=10000;
--根据一个表update 另外一个表
update tab a set a.字段=(select b.字段 from tab1 b where a.id=b.fid)
where exists (select 1 from tab1 b where a.id=b.fid)
--update 多个字段
update tab a set (a.字段,a.字段1)=(select b.字段,b.字段1 from tab1 b where a.id=b.fid)
where exists (select 1 from tab1 b where a.id=b.fid)
update tab a set a.字段=(select b.字段 from tab1 b where a.id=b.fid) where a.字段1='地名'
在oracle的update语句语法中,除了可以update表之外,也可以是视图,所以有以下1个特例:
update (select a.city_name,b.city_name as new_name
from customers a,
tmp_cust_city b
where b.customer_id=a.customer_id
)
set city_name=new_name
这样能避免对B表或其索引的2次扫描,但前提是 A(customer_id) b(customer_id)必需是unique index或primary key。否则报错:
update 和 decode 结合使用
update tpr_fwzh set jjbz=decode(jjbz,1,2,2,4,3,1,4,6,5,3,6,10,7,7,8,8,10,9,jjbz)
update 与case when 结合使用
--修改对应关系
UPDATE TEMP_ZS_PXJH_MXFW SET XZQ= --行政区
CASE XZQ
WHEN '0,27,28,29,30,31,32,33,34,35,59' THEN
'320202,320203,320204,320205,320206,320211,320291,320281,320282,320215'
WHEN '0,27,28,29,30,31,32,33,34,59' THEN
'320202,320203,320204,320205,320206,320211,320291,320281,320215'
WHEN '0,27,28,29,30,31,32,33,34,59,35' THEN
'320202,320203,320204,320205,320206,320211,320291,320281,320282,320215'
WHEN '0,27,28,29,30,31,32,33,59' THEN '320202,320203,320204,320205,320206,320211,320291,320215'
WHEN '34' THEN '320281'
WHEN '0,35' THEN '320282'
WHEN '0,34' THEN '320281'
WHEN '0' THEN NULL
ELSE XZQ END,
ZZDJ= --资质等级
CASE ZZDJ
WHEN '0,2,3,46,47,70' THEN '2,3,1,4,5'
WHEN '0,2,3,46,47' THEN '2,3,1,4'
WHEN '0' THEN NULL
ELSE ZZDJ END,
HYLX= --会员类型
CASE HYLX
WHEN '0,4,5,48,64,71' THEN '1,2,3,4,5'
WHEN '0,4,5,48' THEN '1,2,3'
WHEN '0,4,5,48,64' THEN '1,2,3,4'
WHEN '0' THEN NULL
ELSE HYLX END
update 操作用法的更多相关文章
- 使用merge同时执行insert和update操作
SQL点滴18—SqlServer中的merge操作,相当地风骚 今天在一个存储过程中看见了merge这个关键字,第一个想法是,这个是配置管理中的概念吗,把相邻两次的更改合并到一起.后来在tech ...
- MyBatis魔法堂:各数据库的批量Update操作
一.前言 MyBatis的update元素的用法与insert元素基本相同,因此本篇不打算重复了.本篇仅记录批量update操作的sql语句,懂得SQL语句,那么MyBatis部分的操作就简单了. ...
- ORACLE MERGE INTO UPDATE DELETE 用法
ORACLE MERGE INTO UPDATE DELETE 用法 使用该MERGE语句从一个或多个源中选择行以进行更新或插入表或视图.您可以指定条件以确定是更新还是插入目标表或视图. 此语句是组合 ...
- Oracle中如何实现Mysql的两表关联update操作
在看<MySQL 5.1参考手册>的时候,发现MySQL提供了一种两表关联update操作.原文如下: UPDATE items,month SET items.price=month.p ...
- mysql update操作
update语法 Single-table语法: UPDATE [LOW_PRIORITY] [IGNORE] tbl_name SET col_name1=expr1 [, col_name2=ex ...
- Mysql执行Update操作时会锁住表
update tableA a,(select a.netbar_id,sum(a.reward_amt) reward_amt from tableB a group by a.netbar_id) ...
- Update操作浅析,一定是先Delete再Insert吗?
Update操作一定是先Delete再Insert吗? Update在数据库中的执行是怎么样的?“Update操作是先把数据删除,然后再插入数据”.在网上看了很多也都是这么认为的.但在查阅到一些不同看 ...
- veridata实验例(5)在更改主键列值,update操作将被分成两个语句
veridata实验例(5)更改主键列值,update操作将被分成两个语句 续接"veridata实验举例(4)验证veridata查找出updata.delete操作导致的不同步现象&qu ...
- veridata实验举例(6)验证agent启动先后顺序是否对捕获update操作有影响
veridata实验举例(6)验证agent启动先后顺序是否对捕获update操作有影响 续接veridata实验系列 上篇:"veridata实验举例(5)改动主键上的列值.update ...
随机推荐
- JUC学习记录
先附上学习的博客地址:http://blog.csdn.net/cx8122389/article/details/70049425, 具体见该博客 Java JUC 简介 在Java 5.0 提供了 ...
- 不影响Inspector布局拓展类
DecoratorEditor.cs using System.Collections.Generic; using System.Linq; using System.Reflection; usi ...
- OpenCv 人脸识别 基础
#include <opencv2\opencv.hpp> #include <iostream> using namespace std; int main() { // 摄 ...
- JPEG和Variant的转换
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ...
- SWFUpload乱码问题的解决
目前比较流行的是使用SWFUpload控件,这个控件的详细介绍可以参见官网http://demo.swfupload.org/v220/index.htm 在使用这个控件批量上传文件时发现中文文件名都 ...
- scala sparseVetor, SprseMatrix 实现
def rand(seed:Int):Double={ val rand=new Random(seed) rand.nextDouble()} def rand2(size:Int,seed:Int ...
- oracle 网络环境配置
PLSQL Developer连接Oracle11g 64位数据库配置详解 最近换了台64bit的电脑,所以oracle数据库也跟着换成了64bit的,不过 问题也随之产生,由于plsql devel ...
- django提交post请求
在做post的时候,view.py用到了下面的方法,如果是POST的method,就通过request.POTST['XX']获得html中name为XX的值,然后将值save到数据库里 models ...
- webservice jaxws header验证
@WebService @HandlerChain public class UserService { ... } package com.xx.ws.header; import org.w3c. ...
- clear(), evict(), flush()三种方法的用法实例
先贴代码: @Before public void init() { System.out.println("Test开始之前执行"); Configuration configu ...