Re: CASE Statement

From: Mark D Powell <Mark.Powell_at_eds.com>
Date: Wed, 25 Jun 2008 11:57:58 -0700 (PDT)
Message-ID: <13228bfe-4d95-4ad8-be29-454c616f740a@x41g2000hsb.googlegroups.com>


On Jun 25, 7:45 am, Serge Rielau <srie..._at_ca.ibm.com> wrote:
> Nit:
> SQL knows two (aside from searched vs. simple) different forms of CASE
> constructs:
> Statement and expression
>
> The CASE STATEMENT is a flavor of IF THEN ELSE procedural logic.
> I.e. it belongs into the world of SQL/PSM (or PL/SQL in the case of Oracle).
> The CASE EXPRESSION is a functional construct and belongs into the world
> of SQL queries.
>
> Statement (in SQL/PSM notation):
> CASE
>   WHEN a > b THEN
>    INSERT INTO T VALUES (1);
>   WHEN b < a THEN
>    INSERT INTO T VALUES (2);
> END CASE;
>
> Expression:
> INSERT INTO T VALUES (CASE WHEN a > b THEN 1 WHEN b < a THEN 2 END);
>
> So it pays to be precise on the wording here to clarify what's being
> looked for.
>
> Cheers
> Serge
> --
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab

Serge has a point. The Oracle 10gR2 SQL manual does refer to the case statement within SQL as a case expression:

>>

CASE expressions let you use IF ... THEN ... ELSE logic in SQL statements without having to invoke procedures. <<

Proper terminology is important.

HTH -- Mark D Powell -- Received on Wed Jun 25 2008 - 13:57:58 CDT

Original text of this message