Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL-HELP

Re: SQL-HELP

From: Ken Madsen <madsenkj_at_pe-nelson.com>
Date: Mon, 17 Aug 1998 10:49:42 -0700
Message-ID: <35D86D36.D242714B@pe-nelson.com>


The closest thing is the DECODE statement. Abbrev. syntax:

  DECODE(Column, test_value1, return_value1, default_value)

You can add many more (test, return) pairs before the default value. And the default value is optional.

A real example can be like this:

  SELECT col2,

          col3,
          DECODE(col3, 'YES', 1, 'NO', 0, -1) True_false,
          col4

  FROM table
  WHERE conditions

In this example if col3 it the string 'YES', the return value for the expression is the number 1; if it is the string 'NO', the return value is zero, if it is anything else, the return value is -1.

If you don't specify a default value, the return value is NULL.

This is just a simple contrived case. You can do much more with DECODE.  

--
Ken Madsen Received on Mon Aug 17 1998 - 12:49:42 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US