Simple access to Oracle database NVL function decode function

Source: Internet
Author: User

Decode () and NVL () function usage for SQL statements

SELECT

DECODE (choose_tool,0, ' BMW ', 1, ' EV ', 2, ' bike ', ' walk ') as My_tool

From

data_tool_t

Analysis: When Choose_tool is 0, my_tool= ' BMW '

When Choose_tool is 1, my_tool= ' EV '

When Choose_tool is 2, my_tool= ' bike '

My_tool= ' walk ' when Choose_tool is not the number above

NVL () function:

NVL (arg,value) If the preceding ARG value is not NULL, the value returned is ARG, otherwise the returned value is the following:

Decode function

The If-then-else logic in DECODE

In logic programming, If–then–else is often used to make logical judgments. In Decode's syntax, this is actually the logical process. Its syntax is as follows:

DECODE (value, IF1, Then1, If2,then2, If3,then3, ... else)

Value represents any column of any type of a table or any result that is computed. When each value is tested, if value is the result of the If1,decode function is then1, and if value equals If2,decode The result of the function is then2; In fact, multiple if/then pairs can be given. If the value result is not equal to any given pairing, the Decode result returns else.

It is important to note that if, then, and else here can be functions or evaluation expressions.

Simple access to Oracle database NVL function decode function

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.