From: MindTerm <mindterm@yahoo.com>
To: Tod McQuillin <devin@spamcop.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Porting Oracle Decode to Postgresql
Date: Thu, 22 Nov 2001 01:54:57 -0800 (PST)
Message-ID: <20011122095457.94397.qmail@web20210.mail.yahoo.com> (raw)
In-Reply-To: <20011122184250.G20207-100000@glass.pun-pun.prv>
Dear Tod McQuillin,
Can perform the action as same as oracle in
postgresql ?
e.g.
Select decode_function( ... , ... , ..... ) from ..
I can write a plpgsql to simulate the nvl function
by using coalesce .
CREATE FUNCTION nvl( numeric, numeric ) RETURNS
varchar AS '
DECLARE
input_value ALIAS FOR $1;
else_value ALIAS FOR $2;
output_value numeric;
BEGIN
select coalesce( input_value, else_value ) into
output_value ;
return output_value ;
END;
' LANGUAGE 'plpgsql' ;
M.T.
--- Tod McQuillin <devin@spamcop.net> wrote:
> On Thu, 22 Nov 2001, MindTerm wrote:
>
> > I am writing to ask how to port oracle's decode(
> ..)
> > function to postgresql ?
>
> The ANSI SQL version of decode is CASE.
>
> See
>
http://www.postgresql.org/idocs/index.php?functions-conditional.html> for the full documentation, but basically, it works
> like this:
>
> Oracle:
> decode (value, 0, 'zero', 1, 'one', 'unknown')
>
> ANSI:
> CASE WHEN value=0 THEN 'zero' WHEN value=1 THEN
> 'one' ELSE 'unknown' END
>
> or
>
> CASE value WHEN 0 THEN 'zero' WHEN 1 THEN 'one' ELSE
> 'unknown' END
>
> --
> Tod McQuillin
>
>
__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mindterm@yahoo.com, devin@spamcop.net
Subject: Re: Porting Oracle Decode to Postgresql
In-Reply-To: <20011122095457.94397.qmail@web20210.mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox