0% found this document useful (0 votes)
18 views2 pages

Procedures

Uploaded by

Dhavan Ravuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Procedures

Uploaded by

Dhavan Ravuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

PL/SQL Procedures:

* PL/SQL Procedures are also called Stored Procedures


* Used to perform an operation when we call it.
* Procedures are callable objects
* to create procedure we have to use "create or replace procedure " statement
syntax:
create or replace procedure procedurename(arg1 [IN/OUT] type, ....)
is / as
begin
statements
end;
A procedure must have arguments (variables to store data)
ex:
create or replace procedure pro1(name in varchar2)
as
begin
dbms_output.put_line('Hello,'||name);
end;

How to call a procedure ?


There are two ways to call a procedure
1.Using Exec
* exec means execute
* It will call and execute procedure block
syn:
sql>exec procedurename(data1,...)
ex:
sql>exec pro1('Admin');
Hello,Admin

2.using PL/SQL Block:


* define a pl/sql block with procedure call to execute it.
ex:
begin
pro1('Admin');
end;
Types of Arguments:
* there are two types of arguments
1.IN argument: Read only argument, value can't be changed.
2.OUT argument : Write only argument, value can be changed.

PL/SQL Functions:
* PL/SQL Functions are also called Stored functions
* Used to perform an operation when we call it.
* Functions are callable objects
* Function can return a value whereas procedures can't return a value.
* to create function we have to use "create or replace Function " statement
syntax:
create or replace Function functionname(arg1 type, ....)
return type
is / as
begin
statements ;
return value;
end;
A procedure must have arguments (variables to store data)
ex:
create or replace function fun1(n number)
return number
as
begin
return n+20;
end;

How to call a Function?


There are two ways to call a function
1.Using select
* Select statement will call and execute a function
syn:
sql>select functionname(data1,...) from dual;
ex:
sql>select fun1(20) from dual;
Fun1(20)
--------------
40

2.using PL/SQL Block:


* define a pl/sql block with function call to execute it.
ex:
begin
dbms_output.put_line(fun1(22));
end;

You might also like