CREATE [OR REPLACE] FUNCTION function_name [parameters]
[(parameter_name [IN | OUT | IN OUT] type[,.....])]
RETURN return_datatype
[IS| AS]
BEGIN
<function_body>
END[function_name];
DECLARE
a number;
b number;
c number;
FUNCTION findMax(x IN number, y IN number)
RETURN number
IS
z number;
BEGIN
IF x > y THEN
z:= x;
ELSE
Z:= y;
END IF;
RETURN z;
END;
BEGIN
a:= 20;
b:= 30;
c := findMax(a, b);
dbms_output.put_line(' Maximum of (20,30): ' | | c);
END;
/
Id | Name | Department | salary |
---|---|---|---|
1 | Jay | IT | 45000 |
2 | Albert | HR | 30000 |
3 | Anna | HR | 28000 |
4 | Bob | IT | 35000 |
5 | Alice | IT | 55000 |
CREATE OR REPLACE FUNCTION totalEmployee
RETURN number IS
total number(2) := 0;
BEGIN
SELECT count(*) into total
FROM Employee;
RETURN total;
END;
/
DECLARE
c number(2);
BEGIN
c := Employee();
dbms_output.put_line('Total no. of Employee: ' | | c);
END;
/