Oracle order by specifies the order --- decode Function

Source: Internet
Author: User

Oracle order by: In the decode SQL statement, www.2cto.com order by can be sorted in the specified order. No, for example, NCH HCH ACS TWN .... order by decode (col, 'nch ', '1', 'hch', '2', 'acs', '3', 'twn', '4', col) col indicates the data found in a column. decode function usage in Oracle www.2cto.com meaning and explanation: decode (condition, value 1, return value 1, value 2, return value 2 ,... value n, RETURN value n, default value) the meaning of this function is as follows: IF condition = value 1 then return (translation value 1) ELSIF condition = value 2 then return (translation value 2 )...... ELSIF condition = value n then return (translation value n) else return (default value) end if www.2c To.com 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 of 1, the return value of this function is 2. Otherwise, the return value is 3. Of course, the value 1, the value 2, and the value 3 can also be expressions. This function makes some SQL statements much easier to use: 1. Compare the select decode (sign (variable 1-variable 2),-1, variable 1, variable 2) from dual; -- take a smaller value sign () the function returns 0, 1, and-1 based on a value of 0, positive, or negative. For example, if the variable 1 is 10, and the variable 2 is 20, then sign (variable 1-variable 2) is returned) -1 is returned, and the decode decoding result is "variable 1", so that a smaller value is obtained.

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.