Processing of optional Oracle Parameters

Source: Internet
Author: User

This small problem is also common today. Record it.

Query data within an input range: Select * From Table1 where fld1> = A and between <= B

Both A and B are optional input items, which have the following combinations:

1: A has a value, B has no value, that is, select * From Table1 where fld1> =

2: A has a value, B has a value, that is, select * From Table1 where fld1> = A and then <= B

3: A has no value, B has no value, that is, select * From Table1

4: A has no value, B has a value, that is, select * From Table1 where partition <= B

The basic syntax is as follows (Oracle). The fld1 field is a numeric function.

Select * From Table1

Where

Decode ('& 1', '', 1, fld1)> = to_number (decode (' & 1','', 1, '& 1 '))

And

Decode ('& 2', '', 1, fld1) <= to_number (decode (' & 2','', 1, '& 2 '))

The basic idea is:

If the input value is null, the system takes the initiative to give 1 and set the field to 1.
If the value is null, this condition is converted to 1> = 1, and the value is constant to true, so that the condition is invalid (that is, it is valid ).

Similarly, for an optional parameter

Select * From Table1

Where

Decode ('& 1', '', 1, fld1)> = to_number (decode (' & 1','', 1, '& 1 '))

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.