mysql 遍歷所有表並條件查詢


use eepm_push;

DROP  PROCEDURE  IF EXISTS FountTable;
delimiter $$
create  procedure  FountTable()
begin
     declare  TableName  varchar (64);   
     
     DECLARE  cur_FountTable  CURSOR  FOR  SELECT  TABLE_NAME  FROM  information_schema.TABLES  WHERE  TABLE_NAME  LIKE  'msgfor%' ;
     DECLARE  EXIT HANDLER  FOR  not  found  CLOSE  cur_FountTable;
     #打開游標
     OPEN  cur_FountTable;
     REPEAT
      FETCH  cur_FountTable  INTO  TableName;
      SET  @SQLSTR1 = CONCAT( 'select * from ' ,TableName, ' where appId = ' , '' '' , 'cc055a4d-53b9-4cfc-9f1a-d8bad41b7502' , '' '' , ' and createTime > ' , '' '' , '2017-02-23 00:00:00' , '' '' );
      PREPARE  STMT1  FROM  @SQLSTR1;
      EXECUTE  STMT1;
      
      DEALLOCATE  PREPARE  STMT1;    
       
      UNTIL 0  END  REPEAT;
   #關閉游標
   CLOSE  cur_FountTable;
  
END  $$
DELIMITER ;
  
call FountTable();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM