In the MySQL database, use the cursor to traverse cyclically /*
Delete all data tables in the * dt database with empty docuemttype and MD, PD, and ET documenttype:
Delete from table name where length (documenttype) <2 or documenttype is null or documenttype in ('ET ', 'MD', 'PD ');
*/
DELIMITER $
USE 'database name 1' $
Drop procedure if exists 'stored PROCEDURE name 1' $
Create procedure 'stored PROCEDURE name 1 '()
BEGIN
DECLARE str varchar (40 );
DECLARE Done int default 0;
DECLARE rs cursor for select table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'database name 1 ';
/* Exception handling */
Declare continue handler for sqlstate '000000' SET Done = 1;
/* Open the cursor */
OPEN rs;
/* Retrieve the values of the userId field of the current record one by one */
Fetch next from rs INTO str;
/* Traverse the data table */
REPEAT
Delete from str where length (documenttype) <2 or documenttype is null or documenttype in ('ET ', 'MD', 'PD ');
Fetch next from rs INTO str;
UNTIL Done end repeat;
/* Close the cursor */
CLOSE rs;
END $
DELIMITER;
Use database name 1;
Call stored procedure name 1;
/*
Delete data whose docuemttype is not empty from all data tables in * sd database
Delete from table name where length (documenttype)> 1;
*/
DELIMITER $
USE 'database name 2' $
Drop procedure if exists 'stored PROCEDURE name 2' $
Create procedure 'stored PROCEDURE name 2 '()
BEGIN
DECLARE str varchar (40 );
DECLARE Done int default 0;
DECLARE rs cursor for select table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'database name 2 ';
/* Exception handling */
Declare continue handler for sqlstate '000000' SET Done = 1;
/* Open the cursor */
OPEN rs;
/* Retrieve the values of the userId field of the current record one by one */
Fetch next from rs INTO str;
/* Traverse the data table */
REPEAT
Delete from str where length (documenttype)> 1;
Fetch next from rs INTO str;
UNTIL Done end repeat;
/* Close the cursor */
CLOSE rs;
END $
DELIMITER;
Use database name 2;
Call stored procedure name 2;
/*
Delete Non-dissertation data from all data tables in * et database:
Delete from table name where length (doucmenttype) = ''or documenttype is null or documenttype not in ('ET ', 'MD', 'PD ');
*/
DELIMITER $
USE 'database name 3' $
Drop procedure if exists 'stored PROCEDURE name 3' $
Create procedure 'stored PROCEDURE name 3 '()
BEGIN
DECLARE str varchar (40 );
DECLARE Done int default 0;
DECLARE rs cursor for select table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'database name 3 ';
/* Exception handling */
Declare continue handler for sqlstate '000000' SET Done = 1;
/* Open the cursor */
OPEN rs;
/* Retrieve the values of the userId field of the current record one by one */
Fetch next from rs INTO str;
/* Traverse the data table */
REPEAT
Delete from str where length (doucmenttype) = ''or documenttype is null or documenttype not in ('ET ', 'MD', 'PD ');
Fetch next from rs INTO str;
UNTIL Done end repeat;
/* Close the cursor */
CLOSE rs;
END $
DELIMITER;
Use database name 3;
Call stored procedure name 3;