使用Instr()与decode()进行多条件组合查询

2016-01-29 14:40 4 1 收藏

使用Instr()与decode()进行多条件组合查询,使用Instr()与decode()进行多条件组合查询

【 tulaoshi.com - Oracle教程 】

    系统中遇到了要处理多条件组合查询的情况,好比说有4个独立的条件,那么组合出的查询条件便有24种,不可能写24条Sql语句再分别指定给24种组合情况吧,条件数再多点呢,人都会搞疯的。。。。于是我求助于高手,获得了使用instr()和decode()函数的实现方法。

    下面先说明一下instr()的功能和语法:(函数的语法是从http://www.techonthenet.com/oracle/functions/index.htm处得到的,相当清晰明了:)

In Oracle/PLSQL, the instr function returns the location of a substring in a string.

The syntax for the instr function is:

instr (string1, string2, [start_position], [nth_appearance])

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)

string1 is the string to search.

string2 is the substring to search for in string1.

start_position is the position in string1 where the search will start.  This argument is optional.  If omitted, it defaults to 1.  The first position in the string is 1.  If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.

nth_appearance is the nth appearance of string2.  This is optional.  If omiited, it defaults to 1.

再说明一下decode()的功能和语法:

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)

In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.

The syntax for the decode function is:

decode ( expression , search , result [, search , result]... [, default] )

来源:https://www.tulaoshi.com/n/20160129/1493865.html

延伸阅读
代码如下: DECLARE @PAGESIZE INT DECLARE @PAGEINDEX INT DECLARE @PAGECOUNT INT DECLARE @RECORDCOUNT INT SELECT @PAGESIZE=5 SELECT @PAGEINDEX=1 DECLARE @FIELDNAME VARCHAR(50) DECLARE @FIELDVALUE VARCHAR(50) DECLARE @OPERATION VARCHAR(50) --组合条件 DECLARE @WHERE NVARCHAR(1000) SELECT @WHERE=' WHERE NOTD...
标签: excel
Excel无需数组公式也能查询多条件、指定项的结果   Excel无需数组公式,也能查询多条件、指定项的结果 在Excel单元格中快速创建数据小图标 &nbs(www.tulaoshi.com)p; 枯燥的数字后如果能有个小数据图,对数据的感受能更直观。点击插入功能选项卡,在迷你图组中,单击一种迷你图表类型(拆线图、柱线图、盈亏图),打开创建迷...
标签: SQLServer
可以使用sql-server企业管理器进行建立,注意其中的rpc及rpc out两项,也可以使用sql语句来完成定义,主要涉及到三个存储过程 sp_addlinkedserver,sp_serveroption和sp_addlinkedsrvlogin,以下是三个存储过程的语法: sp_addlinkedserver 创建一个链接的服务器,使其允许对分布式的、针对 OLE DB 数据源的异类查询进行...
标签: 软件教程 excel
在Excel中,如果根据某一个条件,查找表中的值,这是一件较为容易的事情,MATCH()、INDEX()、LOOKUP()、VLOOKUP()、HLOOKUP()等函数均可较为容易的实现。但如果要进行满足多条件查找,则是一件不容易的事情,而工作中会经常遇到需要对满足两个以上条件的数据进行查找并引用的问题,本节提供多种方法如:数组公式、VLOOKUP函数、INDEX和MATCH函...
标签: excel
Excel多条件、指定内容的高级筛选   Excel多条件、指定内容的高级筛选 Excel批量生成指定名称的文件夹   Excel批量生成指定名称的文件夹 如何在Excel里给汉字标注拼音?   如何在Excel里给汉字标注拼音?你只需要通过拼音指南tulaoshi按钮,三个小小的步骤就能给完成~先点击拼音设置决定拼音的排列格式和字...

经验教程

151

收藏

35
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部