PL/SQL Programming MySQL

PL/SQL is a procedural language that Oracle developed as an extension to standard SQL to provide a way to execute procedural logic on the database.

The Syntax for a PL/SQL Block

DECLARE
variable_declarations
BEGIN
program_code
EXCEPTION
exception_handlers
END;

CREATE PROCEDURE and CREATE FUNCTION Syntax in MySQL:

DROP PROCEDURE IF EXISTS CALLS;
DELIMITER ;;
CREATE PROCEDURE CALLS()
BEGIN
DECLARE i INT DEFAULT 0;
DECLARE n INT DEFAULT 0;
SELECT COUNT(*) FROM car INTO n;
SET i=1;
WHILE i
select * from car where id between i and i+100
SET i = i + 100;
SELECT SLEEP(2);
END WHILE;
END;
;;

DELIMITER ;

Sources :

http://www.mysqltutorial.org/getting-started-with-mysql-stored-procedures.aspx

http://www.plsqltutorial.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s