PL/SQL - changing one column's value depending another column's value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uninvitedm
    New Member
    • May 2007
    • 6

    PL/SQL - changing one column's value depending another column's value

    I have a table which I'm extracting data from with a SELECT statement(and outputing as a text file), there's some changes I want to make to the extracted data before it is output (not the actual data on the table).

    There's column1 and column2.
    column1 has some null values. I want these values to be a certain value 'NB' if they are null AND if column2 is null as well! If there is a value in column2, then these can stay null. And if column1 already has a value (is not null) then I want to display that value..

    How can I go about this in PL SQL? Thanks
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    try using the NVL function and do post back with your code that u have tried .

    Comment

    • uninvitedm
      New Member
      • May 2007
      • 6

      #3
      Originally posted by debasisdas
      try using the NVL function and do post back with your code that u have tried .
      Thanks, sure. I've tried
      Code:
      nvl (column1||column2, 'NB') column1
      Just returns '0' each time, and obviously displays both columns together.. was thinking along those lines

      Also tried combining the two values using a DECODE so if both columns are null, show 'NB' for column1 -- but the following code
      Code:
      DECODE (column1||column2, 0, 'NB', column1) column1
      doesn not work.. has the error 'invalid number'


      EDIT: Scratch that, the decode with the 0 in quotes seems to work..... now i feel stupid.. thanks

      Comment

      Working...