?
Solved

Decode in Oracle 8i

Posted on 2003-03-18
5
Medium Priority
?
1,083 Views
Last Modified: 2008-02-01
I need to insert a value in a column based on the value of two other columns...  For example, if column A and column B are NOT NULL then update column C with the value of column A.  Can this be done using DECODE?

thanks,
JGreenwood.  
0
Comment
Question by:JGreenwood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 200 total points
ID: 8159869
If A and B are both VARCHAR2 you can do:

DECODE( A||B, NULL, NULL, A )

If A and B are both NUMBER you can do:

DECODE (A+B, NULL, NULL, A )

Otherwise:

DECODE( A, NULL, NULL, DECODE( B, NULL, NULL, A ) )
0
 

Author Comment

by:JGreenwood
ID: 8160424
thanks, that worked... JGreenwood.
0
 
LVL 3

Expert Comment

by:bkowalski
ID: 8160521
I don't believe an AND operation can be done using DECODE.

Are you trying to avoid PL/SQL? Can you just use the following:

UPDATE <tablename>
SET c = a
WHERE a IS NOT NULL
  AND b IS NOT NULL
;
0
 

Author Comment

by:JGreenwood
ID: 8160765
Yes, I am trying to avoid PL/SQL...  I want to do this in SQL+...  What is the best way?
0
 
LVL 3

Expert Comment

by:bkowalski
ID: 8160837
The best way is the update statement I gave you earlier, unless andrewst's suggestion works for you which is actually the best answer to your original question.  
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question