| Decode expression help [message #645045] |
Tue, 24 November 2015 10:02  |
 |
redhonda9834
Messages: 3 Registered: November 2015
|
Junior Member |
|
|
Hello Everyone,
I have a decode expression i need help understanding.
decode(location_area, alternate_area, location_area, alternate_area) "Current_Location"
Am I correct with this if statement?
if location_area = alternate_area then
current_location = location_area
else
current_location = alternate_area
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Decode expression help [message #645060 is a reply to message #645049] |
Wed, 25 November 2015 03:19   |
cookiemonster
Messages: 13975 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Or do the sensible thing - copy your data onto a test instance and test it there.
Also if you're finding decode hard to follow use CASE instead - it's much more obvious.
|
|
|
|
| Re: Decode expression help [message #645063 is a reply to message #645045] |
Wed, 25 November 2015 03:34   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
redhonda9834 wrote on Tue, 24 November 2015 21:32
decode(location_area, alternate_area, location_area, alternate_area) "Current_Location"
Am I correct with this if statement?
if location_area = alternate_area then
current_location = location_area
else
current_location = alternate_area
As CM said, if DECODE is difficult for you to understand, then you could use CASE which is verbose and easy to interpret.
CASE
WHEN
location_area = alternate_area
THEN
location_area
ELSE
alternate_area
END
It's exactly like your IF-ELSE interpretation, only the IF becomes CASE WHEN and END IF becomes END CASE. It would work both in SQL and PL/SQL.
Read more in documentation https://docs.oracle.com/database/121/LNPLS/case_statement.htm#LNPLS01304
[Updated on: Wed, 25 November 2015 03:42] Report message to a moderator
|
|
|
|
|
|