Multi-condition combination query scheme using Oracle Instr () function

Source: Internet
Author: User

The following articles mainly introduce how to use the Oracle Instr () and decode () functions correctly to perform combined queries with multiple conditions, in related systems, we often encounter queries with combinations of multiple conditions to be processed, using the implementation methods of instr () and decode () functions.

The following describes the functions and syntax of instr (): (the syntax of the function is obtained from the points, which is quite clear :)

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

The SQL statement is as follows:

Select e. Date of arrival,

E. Role name,

D. Document title,

D. Document No,

E. node number,

E. processing actions,

E. Processing date,

B. Process instance id

From gzl _ process type,

Gzl _ process instance B,

Gzl _ process definition c,

Dj _ document d,

Gzl _ process flow status e

Where a. Process type No. = c. Process type no. and e. Process tag = 'yes'

And e. User ID = 'dms' and B. process definition number = c. process definition number

And B. Activity No. = d. Document No. and c. process definition no. = B. process definition no.

And e. Process instance No. = B. Process instance No.

And instr (decode (: Process type condition, '-1', a. Process type number,: Process type condition), a. Process type number)> 0

And (to_char (e. Processing date, 'yyyy-mm-dd') between: start date and end date)

And instr (decode (: node name condition, '-1', e. Processing action,: node name condition ),

E. Processing action)> 0

The above content is related to the use of Oracle Instr () and decode () functions for multi-condition combination query, the system encountered the need to process multi-condition combination query, the use of instr () and decode () functions. We hope you will have some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.