Oracle function decode

Source: Internet
Author: User

First, decode function

Meaning explanation:
1, Decode (condition, value 1, return value 1, value 2, return value 2,... Value N, return value N, default value)

The function has the following meanings:
IF condition = value 1 Then
RETURN (translation value 1)
elsif condition = value 2 Then
RETURN (translation value 2)
......
elsif condition = value n Then
RETURN (translated value N)
ELSE
RETURN (default value)
END IF

The result of this function is that when the value of the field or Field operation is equal to the value 1 o'clock, the function returns the value 2, otherwise the value 3
Of course, a value of 1, a value of 2, a value of 3 can also be an expression, this function makes some SQL statements a lot simpler

2, Decode (field or Field operation, value 1, value 2, value 3)

The result of this function is that when the value of the field or Field operation is equal to the value 1 o'clock, the function returns the value 2, otherwise the value 3
Of course, a value of 1, a value of 2, a value of 3 can also be an expression, this function makes some SQL statements a lot simpler

Second, add_months

Add_months has two parameters, the first parameter is the date, the second argument is the number (in months) that the date is added and minus

3 months later, select Add_months (sysdate,3) from dual;

3 months ago, select Add_months (sysdate,-3) from dual;

Third, case and then usage

Https://www.cnblogs.com/Richardzhu/p/3571670.html

Oracle function decode

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.