Max_Salah - 4 months ago 17

SQL Question

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);`

`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

Answer

You need to run a `select`

```
select minimum2(1,2)
from dual
```

You also need to end the function with a `/`

:

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
```

Source (Stackoverflow)

Comments