使用Oracle Instr()函数进行多条件组合查询方案

数据库 Oracle
我们今天主要和大家介绍的是正确的使用Oracle Instr()和decode()函数来进行多条件的组合查询的方案,以下就是文章的具体内容介绍。

以下的文章主要介绍的是如何正确的使用Oracle Instr()和decode()函数来进行多条件的组合查询,在相关系统中我们经常遇到要处理的多条件组合查询的相关情况,使用instr()和decode()函数的实现方法。

下面先说明一下instr()的功能和语法:(函数的语法是从处得到的,相当清晰明了:)

 

  1. In Oracle/PLSQL, the instr function returns the location of a substring in a string.  
  2. The syntax for the instr function is:  
  3. instr (string1, string2, [start_position], [nth_appearance])  
  4. string1 is the string to search.  
  5. string2 is the substring to search for in string1.  
  6. 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.  
  7. nth_appearance is the nth appearance of string2. This is optional. If omiited, it defaults to 1.  

 

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

 

  1. In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.  
  2. The syntax for the decode function is:  
  3. decode ( expression , search , result [, search , result]... [, default] )  
  4. expression is the value to compare.  
  5. search is the value that is compared against expression.  
  6. result is the value returned, if expression is equal to search.  
  7. default is optional. If no matches are found, the decode will return default. 
    If default is omitted, then the decode statement will return null (if no matches are found).  

 

综合使用得到的SQL语句如下:

select e.到达日期,

e.角色名,

d.单据标题,

d.单据编号,

e.节点编号,

e.处理动作,

e.处理日期,

b.流程实例编号

from gzl_流程类型a,

gzl_流程实例b,

gzl_流程定义c,

dj_单据 d,

gzl_流程流转状态 e

where a.流程类型编号 = c.流程类型编号 and e.处理标记 = '是'

and e.用户id = 'tetdmis' and b.流程定义编号 = c.流程定义编号

and b.活动编号 = d.单据编号 and c.流程定义编号 = b.流程定义编号

and e.流程实例编号 = b.流程实例编号

and instr(decode(:流程类型条件, '-1', a.流程类型编号, :流程类型条件), a.流程类型编号) > 0

and (to_char(e.处理日期, 'yyyy-mm-dd') between :开始日期 and :结束日期)

and instr(decode(:节点名称条件, '-1', e.处理动作, :节点名称条件),

e.处理动作) > 0

以上的相关内容就是对使用Oracle Instr()与decode()函数进行多条件组合查询,系统中遇到了要处理多条件组合查询的情况,使用instr()和decode()函数的实现方法。的介绍,望你能有所收获。

【编辑推荐】

  1. 对Oracle数据字典的文档描述
  2. Oracle to_char的用法的描述
  3. Oracle struts2中相关日期输入显示某些问题的方案
  4. Oracle 11g调用相关函数的5种方法
  5. 调用Oracle procedure在pl/sql中的操作
责任编辑:佚名 来源: 互联网
相关推荐

2010-05-06 14:11:55

Oracle多条件查询

2009-09-15 17:45:34

Linq多条件

2010-04-30 09:34:24

Oracle多条件查询

2009-09-15 09:33:46

linq多条件查询

2009-09-15 11:34:47

Linq多条件查询

2009-06-29 09:03:31

Hibernate多条

2010-11-09 15:18:37

SQL Server多

2010-09-25 16:42:45

sql语句

2010-10-25 10:55:11

Oracle函数索引

2020-12-01 11:13:00

MySQL8

2023-11-17 15:34:03

Redis数据库

2009-05-19 14:34:52

Oraclehash优化

2010-04-26 14:43:17

Oracle递归条件查

2010-10-26 12:03:25

Oracle备份

2023-11-06 12:00:04

GORM

2010-10-25 10:20:33

ORACLE函数

2017-09-04 17:34:17

HBASESolr查询

2010-05-07 11:00:25

Oracle多表查询

2010-07-15 09:14:32

SQL server组

2011-07-29 14:39:11

CASE WHEN E
点赞
收藏

51CTO技术栈公众号