2
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
5
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
7
create database if not exists mysqltest1;
8
DROP PROCEDURE IF EXISTS mysqltest1.p1;
9
DROP PROCEDURE IF EXISTS mysqltest1.p2;
10
DROP TABLE IF EXISTS mysqltest1.t2;
11
DROP TABLE IF EXISTS mysqltest1.t1;
12
CREATE TABLE IF NOT EXISTS mysqltest1.t1(name CHAR(16), birth DATE,PRIMARY KEY(name))ENGINE=InnoDB;
13
CREATE TABLE IF NOT EXISTS mysqltest1.t2(name CHAR(16), age INT ,PRIMARY KEY(name))ENGINE=InnoDB;
14
CREATE PROCEDURE mysqltest1.p1()
16
DECLARE done INT DEFAULT 0;
19
DECLARE cur1 CURSOR FOR SELECT name,
20
(YEAR(CURDATE())-YEAR(birth))-(RIGHT(CURDATE(),5)<RIGHT(birth,5))
22
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
26
FETCH cur1 INTO spa, spb;
29
INSERT INTO mysqltest1.t2 VALUES (spa,spb);
32
UNTIL done END REPEAT;
36
CREATE PROCEDURE mysqltest1.p2()
38
INSERT INTO mysqltest1.t1 VALUES ('MySQL','1993-02-04'),('ROCKS', '1990-08-27'),('Texas', '1999-03-30'),('kyle','2005-1-1');
42
DROP PROCEDURE IF EXISTS mysqltest1.p1;
43
DROP PROCEDURE IF EXISTS mysqltest1.p2;
44
DROP TABLE IF EXISTS mysqltest1.t1;
45
DROP TABLE IF EXISTS mysqltest1.t2;
46
DROP DATABASE mysqltest1;