Вы находитесь на странице: 1из 2

Function Creation:

create [or replace] function function_name [(parameter_name type [, ...])]


RETURN type {IS | AS}
begin
function_body;
end function_name;
Function Calling:
1. select function_name from dual;
2. select function_name() from dual;
3. BEGIN
DBMS_OUTPUT.PUT_LINE(funcation_name ());
END;
Example 1:
create or replace function fun1
return number as
x number;
begin
x := 12;
return x;
end fun1;
Example 2:
create or replace function fun2
return number as
avg_age number;
begin
select avg(age) into avg_age from student;
return avg_age;
end fun2;

Example 3:
create or replace function fun1(a in number,b in number)
return number as
c number;
begin
c:=a+b;
return c;
end fun1;
Example 4:
create or replace function fun1(a number,b number)
return number is
c number;
begin
c:=a+b;
return c;
end fun1;
Example 5:
create or replace function square(num number)
return number is
begin
return num * num;
end square;