Use the Instr () and decode () functions of Oracle for multi-condition combination _ MySQL

Source: Internet
Author: User
Use the Instr () and decode () functions of Oracle for multi-condition combination of ORACLE functions

The system encounters a situation where you want to process the multi-condition combination query, using the implementation methods of the 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 :)

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

Expression is the value to compare.

Search is the value that is compared against expression.

Result is the value returned, if expression is equal to search.

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

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.