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