Re: Porting Oracle Decode to Postgresql
От | MindTerm |
---|---|
Тема | Re: Porting Oracle Decode to Postgresql |
Дата | |
Msg-id | 20011122095457.94397.qmail@web20210.mail.yahoo.com обсуждение исходный текст |
Ответ на | Re: Porting Oracle Decode to Postgresql (Tod McQuillin <devin@spamcop.net>) |
Список | pgsql-sql |
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
В списке pgsql-sql по дате отправления: