0

I have written a function minimum2 which take two numbers as arguments and returns the minimum number. This function compiles without any error. when I call the function minimum(1,2); I get the errors PLS-00103. Here is the function and the function call:

CREATE OR REPLACE FUNCTION minimum2(v1 number, v2 number) RETURN number IS
     BEGIN
       IF v1 < v2 THEN
         RETURN v1;
       ELSE
         RETURN v2;
       END IF;
     END;     
 --I call the function asl follow
 minimum2(1,2);

What did I do wrong? I wrote this code in sql developer

Max_Salah
  • 2,407
  • 11
  • 39
  • 68

2 Answers2

4

You need to run a select

select minimum2(1,2) 
from dual

You also need to end the function with a /:

enter image description here

For details on how and why to use the / see here


Are you aware that there is a built-in function for that?

select least(1,2) 
from dual
Community
  • 1
  • 1
  • I tried select but got the same errors. I dont want use the built-in function i want to know why my function call does not work :) – Max_Salah Jul 12 '16 at 12:29
  • @Max_Salah: and what error **exactly** did you get with the `select`? You _did_ end the `create function` with a `/` did you? http://stackoverflow.com/questions/1079949/when-do-i-need-to-use-a-semicolon-vs-a-slash-in-oracle-sql/10207695#10207695 –  Jul 12 '16 at 12:30
1

--specifying 'in' and 'out' to parameters is important or it can work as it is, but best practice is to use:

CREATE OR REPLACE FUNCTION minimum2(v1 IN number, v2 IN number) RETURN number IS
     BEGIN
       IF v1 < v2 THEN
         RETURN v1;
       ELSE
         RETURN v2;
       END IF;
     END; 

--I call the function as follows through anonymous block and you can not call the function directly.

set serveroutput on;
begin
dbms_output.put_line('Output is ' || minimum2(1,2));
END;
/
akash
  • 11
  • 1