mysql 遍历所有表并条件查询
Posted 那些年的代码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
以上是关于mysql 遍历所有表并条件查询的主要内容,如果未能解决你的问题,请参考以下文章