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: if statement inside function

Re: if statement inside function

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Wed, 15 Feb 2006 19:52:37 +0100
Message-ID: <kst6v1ht1mu3r084o7ulkj6hq0cadm50gv@4ax.com>


On 15 Feb 2006 10:24:20 -0800, drdave_at_canoemail.com wrote:

>New to Oracle and cant understand why my code is not working ..
>
>FUNCTION "VARIATION_ID" ("range_id" IN VARCHAR2) return NUMBER is
> rangebig NUMBER;
>
>BEGIN
>
>
> SELECT max(minimum_wage_variation_id) as bigrange into rangebig
> FROM minimum_wage_variation
>
> IF range_id = 1 THEN
> WHERE minimum_wage_variation_id < 100
> ELSE
> WHERE minimum_wage_variation_id > 100
> END IF;
>
>
> RETURN rangebig;
>END;
>
>error:00933 sql command not properly ended, yet if I put a semicolon on
>the where clauses it throws an error on the else clause..
>
>thx.
>
>Dave

You are mixing a sql statement with procedural code. This is not allowed and not syntactically correct.
You would need to have either 2 different select into statements if range_id = 1
 then

    select max(minimum_wage_variation_id)   into rangebig
   from minimum_wage_variation
  where mimimum_wage_variation_id < 100;   else
    select max(minimum_wage_variation_id)   into rangebig
   from minimum_wage_variation
  where mimimum_wage_variation_id > 100; end if;

--
Sybrand Bakker, Senior Oracle DBA
Received on Wed Feb 15 2006 - 12:52:37 CST

Original text of this message

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