DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Decode statement

  1. #1
    Join Date
    Feb 2002
    Posts
    25
    Hi,

    I need to write a decode statement which does the following:
    Returns elec_id if elec_id is not null in the database, and gas_id if elec_id is null.

    How do I do that?

    Thanks in advance,

    Boris

  2. #2
    Join Date
    May 2002
    Posts
    2,645
    select decode(elec_id,null,gas_id,elec_id) from table_name;

    What this says in pseudocode is:

    If elec_id is null then
    use gas_id
    else
    use elec_id
    end;

  3. #3
    Join Date
    Feb 2002
    Posts
    25
    Thank you very much.

    Boris

  4. #4
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Isn't that what NVL() function is all about? No need for DECODE or other fancy stuf in this case...

    SELECT NVL(elec_id, gas_id) FROM table_name;
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width