Functions in an Oracle database
A: Table name, B: The name of the field to be modified
Update A Set B = replace (b, ' null ', ' 0 ') where id = ' 5644 ';
The execution effect is as follows:
The use of Decode functions
The function is--the time of display changed the database true data unchanged AH
Meaning explanation:
Decode (condition, value 1, return value 1, value 2, return value 2,... Value N, return value N, default value)
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
Note: The default value can be either the column name you want to select or the other values you want to define, such as other;
An example is provided:
The definition of a table named output, which defines two column is Monthid (VAR) and sale (number type), if the sale value =1000 when translated to d,=2000 when translated to c,=3000 when translated as a , if other values are translated into other;
SQL is as follows:
Select Monthid, decode (sale,1000, ' D ', Watts, ' C ', 3000, ' B ', 4000, ' A ', ' other ') sale from output
Special case:
If you compare to only one value
Select Monthid, decode (sale, NULL, '---', sale) sale from output
Another: Decode can use other functions, such as NVL function or sign () function, etc.
NVL (EXPR1,EXPR2)
If EXPR1 is null, return EXPR2 or return EXPR1.
SELECT Name,nvl (To_char (COMM), ' not application ') from TABLE1;
If you use the Decode function, it's
Select Monthid,decode (NVL (sale,6000), 6000, ' NG ', ' OK ') from output
The sign () function returns 0, 1, and 1, depending on whether a value is 0, positive, or negative.
If you take a smaller value, you are
Select Monthid,decode (sign (sale-6000), -1,sale,6000) from output, that is, to achieve a smaller value.