0% found this document useful (0 votes)
2 views1 page

Procedure

The document outlines SQL procedures for creating and manipulating a table named EMP and another table named t. It includes procedures for selecting data, inserting values, and updating records based on conditions and loops. Additionally, it demonstrates the use of variables and control flow in SQL procedures.

Uploaded by

Ayush Singh
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)
2 views1 page

Procedure

The document outlines SQL procedures for creating and manipulating a table named EMP and another table named t. It includes procedures for selecting data, inserting values, and updating records based on conditions and loops. Additionally, it demonstrates the use of variables and control flow in SQL procedures.

Uploaded by

Ayush Singh
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/ 1

Procedure

Create a table with name EMP. Add some data into it.
delimiter //
create procedure alll()
begin
select * from EMP;
end//

delimiter ;
CALL alll();
DROP PROCEDURE GetEmployees;
DROP PROCEDURE IF EXISTS abc;

---------------------------------------------------------------

Variables
create table t (s1 int);

CREATE PROCEDURE pname ()


BEGIN
DECLARE a INT;
DECLARE b INT;
SET a = 5;
SET b = 5;
INSERT INTO t VALUES (a);
SELECT s1 * a FROM t WHERE s1 >= b;
END; //

call pname();

CREATE PROCEDURE p12 (IN parameter1 INT)


BEGIN
DECLARE variable1 INT;
SET variable1 = parameter1 + 1;
IF variable1 = 0 THEN
INSERT INTO t VALUES (17);
END IF;
IF parameter1 = 0 THEN
UPDATE t SET s1 = s1 + 1;
ELSE
UPDATE t SET s1 = s1 + 2;
END IF;
END; //
CALL p12(23);
---------------------------------------------------------------------------------
Loops:

CREATE PROCEDURE p14 ()


BEGIN
DECLARE v INT;
SET v = 0;
WHILE v < 5 DO
INSERT INTO t VALUES (v);
SET v = v + 1;
END WHILE;
END; //

You might also like