Oracle--(case when then else end )和(update set replace)的用法
2016-04-14 17:50
453 查看
update `表名` set 字段名 =replace(字段名, '查找的内容','更改的内容') where 字段名 like '%查找的内容%';
update shangpin set click_url=replace(click_url,'21508360','1111111111') where click_url like '%21508360%';
--------------------------------------------------------------------------------------------------
case具有两种格式。简单case函数和case搜索函数。
--简单case函数
case sex
when
'1' then '男'
when
'2' then '女'
else
'其他' end
--case搜索函数
case
when sex = '1'
then '男'
when sex =
'2' then '女'
else
'其他' end
这两种方式,可以实现相同的功能。简单case函数的写法相对比较简洁,但是和case搜索函数相比,功能方面会有些限制,比如写判定式。
还有一个需要注重的问题,case函数只返回第一个符合条件的值,剩下的case部分将会被自动忽略。
--比如说,下面这段sql,你永远无法得到“第二类”这个结果
case
when col_1 in (
'a', 'b') then'第一类'
when col_1
in ('a')
then '第二类'
else'其他'end
原文:http://blog.csdn.net/xuxurui007/article/details/8479953
update shangpin set click_url=replace(click_url,'21508360','1111111111') where click_url like '%21508360%';
--------------------------------------------------------------------------------------------------
SELECT a.managecom, a.subtype, count(*) loadsucc, sum(case when a.state in ('4', '5', '6', '7', '8', '9') then 1 else 0 end) recogsucc, sum(case when a.state in ('3', '12', '13') then 1 else 0 end) recogfail, sum(case when a.state in ('1', '2') then 1 else 0 end) waitrecog FROM ocr_docdetail a, ocr_loaddetail c WHERE 1 = 1 and a.managecom like '86%' and a.managecom = c.managecom and a.bussno = c.bussno and a.subtype = c.subtype and c.loadstate = 0 and c.scandate >= date '2012-07-29' and c.scandate <= date '2013-01-07' group by a.managecom, a.subtype order by a.managecom, a.subtype;
case具有两种格式。简单case函数和case搜索函数。
--简单case函数
case sex
when
'1' then '男'
when
'2' then '女'
else
'其他' end
--case搜索函数
case
when sex = '1'
then '男'
when sex =
'2' then '女'
else
'其他' end
这两种方式,可以实现相同的功能。简单case函数的写法相对比较简洁,但是和case搜索函数相比,功能方面会有些限制,比如写判定式。
还有一个需要注重的问题,case函数只返回第一个符合条件的值,剩下的case部分将会被自动忽略。
--比如说,下面这段sql,你永远无法得到“第二类”这个结果
case
when col_1 in (
'a', 'b') then'第一类'
when col_1
in ('a')
then '第二类'
else'其他'end
原文:http://blog.csdn.net/xuxurui007/article/details/8479953
相关文章推荐
- ORACLE PL/SQL编程详解之七:程序包的创建与应用(聪明在于学习,天才在于积累!)
- ORACLE PL/SQL编程之五:异常错误处理(知已知彼、百战不殆)
- ORACLE PL/SQL编程之四:把游标说透(不怕做不到,只怕想不到)
- ORACLE PL/SQL编程详解之三:PL/SQL流程控制语句(不给规则,不成方圆)
- oracle分组后取每组第一条数据
- Oracle-15-唯一约束
- ORACLE PL/SQL编程详解之二:PL/SQL块结构和组成元素(为山九仞,岂一日之功)
- ORACLE PL/SQL编程详解之一:PL/SQL 程序设计简介(千里之行,始于足下)
- Oracle-14-非空约束
- Oracle-13-当父表和子表有外键约束时如何删表及数据
- Converting Index-Organized Tables to Regular Tables
- Oracle-12-外键约束
- Oracle-11-主键约束
- oracle中CAST函数使用简介
- BIG biang教你误删oracle 怎么办,
- Oracle疑问_20160414
- oracle job SYSDATE
- debian 安装oracle-jdk
- oracle中的decode的使用
- Mybatis中oracle、mysql、db2、sql server的like模糊查询