Learn PL/SQL Language

A block structured language that can have multiple blocks in it. Our tutorial includes all topics of PL/SQL language.

PL/SQL Introduction
Control Statements
PLSQL Concepts

Procedure in PL/SQL

The PL/SQL stored procedure or simply a procedure is a PL/SQL block which performs one or more specific tasks. It is just like procedures in other programming languages.

The procedure contains a header and a body.

Header: The header contains the name of the procedure and the parameters or variables passed to the procedure.

Body: The body contains a declaration section, execution section and exception section similar to a general PL/SQL block.

How to pass parameters in procedure:

When you want to create a procedure or function, you have to define parameters .There is three ways to pass parameters in procedure:

IN parameters: The IN parameter can be referenced by the procedure or function. The value of the parameter cannot be overwritten by the procedure or the function.

OUT parameters: The OUT parameter cannot be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function.

INOUT parameters: The INOUT parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.

Create procedure example

Table creation

create table user(id number(10) primary key,name varchar2(100));

Procedure Code

create or replace procedure "INSERTUSER"    
(id IN NUMBER,    
name IN VARCHAR2)    
is    
begin    
insert into user values(id,name);    
end;    

Output :

Procedure created.

PL/SQL program to call procedure

          
BEGIN    
   insertuser(101,'Rahul');  
   dbms_output.put_line('record inserted successfully');    
END;             

Now, see the "USER" table, you will see one record is inserted.

Syntax for drop procedure

          
    DROP PROCEDURE procedure_name;            

Let's learn functions in PL/SQL


Share this page on :