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

姩_少オ輕狂

姩_少オ輕狂

2016-01-29 14:40

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

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

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

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

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

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

The syntax for the instr function is:

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

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

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

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

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

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

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

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

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

string1 is the string to search.

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

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

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

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

string2 is the substring to search for in string1.

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

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

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

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The syntax for the decode function is:

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

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

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

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

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

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

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

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

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com)
展开更多 50%)
分享

猜你喜欢

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

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

使用准则进行条件查询

编程语言 网络编程
使用准则进行条件查询

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Excel2007轻松进行多条件求和

办公软件
Excel2007轻松进行多条件求和

多条件数据库查询的优化方法

编程语言 网络编程
多条件数据库查询的优化方法

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Excel2019中多条件筛选如何使用?

excel
Excel2019中多条件筛选如何使用?

如何使用oracle的decode函数进行多值判断

编程语言 网络编程
如何使用oracle的decode函数进行多值判断

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

在ORACLE中实现SELECTTOPN的方法

在ORACLE中实现SELECTTOPN的方法

模拟OICQ的实现思路和核心程序(三)

模拟OICQ的实现思路和核心程序(三)
下拉加载更多内容 ↓