当前位置: 首页 > 图文教程 > 数据库 > Oracle > 使用Instr()与decode()进行多条件组合查询

Oracle
数据库Oracle性能优化可能出现的问题
oracle认证辅导:重访Oracle密码
Oracle认证:修改用户指定的默认表空间
Oracle认证:Oracle的三种Join方法
Oracle认证辅导:教你数据库查询初始化参数
教你查询Oracle中的表空间
利用变量在Linux中给文件命名
oracle的case函数控制结构DECODE()函数
解决Oracle被锁定有妙招
Oracle数据库编写事务 几个需要遵守指导方针
如何解决Oracle被锁定问题
如何控制Oracle虚拟专用数据
Oracle入门基础之参数文件
如何解决Oracle数据库ORA-00257故障
实例解析:用Oracle创建实例的参数需求
对比Caché和Oracle在数据库的应用
风河应用Oracle产品为企业2.0提供动力
Oracle数据库中Insert、Update、Delete操作速度大提速
Oracle11g再创TPC-C基准测试性价比世界纪录
Oracle用户常用数据字典的查询

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-31   浏览: 81 ::
收藏到网摘: n/a

    系统中遇到了要处理多条件组合查询的情况,好比说有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])

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()的功能和语法:

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] )