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

Home -> Community -> Usenet -> c.d.o.server -> Re: Decode

Re: Decode

From: Dieter Buecherl <Dieter.Buecherl_at_t-online.de>
Date: Wed, 3 Apr 2002 22:53:41 +0200
Message-ID: <a8fq3q$6di$03$1@news.t-online.com>


How about something like:

SELECT DECODE (GREATEST(CEIL ( (SYSDATE - TRUNC (my_date)) / 7), 13), 13,COUNT(record_id), 0) w13 .....

to get around the comparision mechanism of DECODE and still avoid the context switch from SQL to PL/SQL?

HTH Dieter

"markag" <member_at_dbforums.com> schrieb im Newsbeitrag news:3cab29fb$3_at_usenetgateway.com...
> Hmmm.
>
> Problem is that becomes a nested SQL statement that screws the pooch.
>
> Anyway, the problem was that DECODE cannot handle a comparison in the
> value portion of the function, like
>
> DECODE (ROUND ( (SYSDATE - TRUNC (my_date)) / 7 + .5, 0) > 13,
> 13,COUNT(record_id), 0) w13
>
> returns an error.
>
> So, i created an f_over13() function CREATE OR REPLACE FUNCTION F_OVER13
> ( in_claim_date IN DATE DEFAULT NULL) RETURN NUMBER IS BEGIN IF ROUND (
> (SYSDATE - TRUNC (in_claim_date)) / 7 + .5, 0) > 13 THEN RETURN 1; ELSE
> RETURN 0; END IF; EXCEPTION WHEN OTHERS THEN raise_application_error
> (-20001, SQLERRM); END;
>
> ..and called it from within DECODE like this:
>
> DECODE(f_over13(TRUNC(claim_date)), 1,
> COUNT(claim_transaction_summary_id), 0) wover13
>
> and it seemed to work by my rigorous testing methods.... :)
>
>
>
> --
> Posted via dBforums
> http://dbforums.com
Received on Wed Apr 03 2002 - 14:53:41 CST

Original text of this message

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