Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DELIMITER $$
- DROP PROCEDURE IF EXISTS `test1`.`get_partition_info` $$
- CREATE PROCEDURE `test1`.`get_partition_info` (tb VARCHAR(64))
- BLOCK1:BEGIN
- DECLARE loop0_eof INT DEFAULT FALSE;
- DECLARE tmp_title VARCHAR(200);
- DECLARE date_part DATE;
- DECLARE cur0 CURSOR FOR SELECT DISTINCT(TableName) FROM metadataTable;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET loop0_eof = TRUE;
- OPEN cur0;
- loop0: LOOP
- FETCH cur0 INTO tmp_title;
- IF loop0_eof THEN
- CLOSE cur0;
- LEAVE loop0;
- END IF;
- BLOCK2: BEGIN
- DECLARE loop1_eof INT DEFAULT FALSE;
- DECLARE cur1 CURSOR FOR SELECT PARTITION_DESCRIPTION
- FROM INFORMATION_SCHEMA.PARTITIONS
- WHERE TABLE_NAME=tmp_title AND TABLE_SCHEMA='test1';
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET loop1_eof = TRUE;
- OPEN cur1;
- loop1: LOOP
- FETCH cur1 INTO date_part;
- SELECT max(id) from `test1`.tmp_title where CurrentDate < date_part;
- IF loop1_eof THEN
- CLOSE cur1;
- LEAVE loop1;
- END IF;
- END LOOP loop1;
- END BLOCK2;
- END LOOP loop0;
- END BLOCK1 $$
- DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement