Create a Simple Procedure
Simple Procedure is a set of SQL statement which are executed under one name.
Understand with Example
This example shows you how to create a simple procedure. This procedure display all records of stu_table table. The create table construct a table 'Stu_Table'.
Create Table Stu_Table
create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class varchar(10))
Insert data into Stu_Table
The insert into add the records or rows to the table 'Stu_Table'.
insert into Stu_Table values(1,'Komal',10); insert into Stu_Table values(2,'Ajay',10); insert into Stu_Table values(3,'Rakesh',10); insert into Stu_Table values(4,'Bhanu',10); insert into Stu_Table values(5,'Santosh',10); insert into Stu_Table values(1,'Komal',10); |
Stu_Table
Stu_Id | Stu_Name | Stu_Class |
1 | Komal | 10 |
2 | Ajay | 10 |
3 | Rakesh | 10 |
4 | Bhanu | 10 |
5 | Santosh | 10 |
1 | Komal | 10 |
Create Procedure
The Create Procedure in SQL is used to create a procedure Abc( ).The SQL stored procedure bodies contain of one or more statement nested inside a BEGIN and END keyword. In this Query stored procedure returns you the records from 'Stu_Table'.
delimiter $$ create procedure Abc() BEGIN SELECT * FROM Stu_Table; END$$ delimiter; |
Call Procedure
The call procedure abc is used to execute the procedure andS return you the records from table 'Stu_Table'.
call abc(); |
Result
Stu_Id | Stu_Name | Stu_Class |
1 | Komal | 10 |
2 | Ajay | 10 |
3 | Rakesh | 10 |
4 | Bhanu | 10 |
5 | Santosh | 10 |
1 | Komal | 10 |