本文主要是介绍mysql简单存储过程范例之遍历数据库生成视图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
范例:
BEGIN
-- 定义参数
declare done int(10);
declare p_feeCode varchar(50);
declare abc varchar(50);
declare sqlstr varchar(500);
-- 定义游标
declare feeCodeCursor cursor for select TABLE_NAME FROM INFORMATION_SCHEMA.TABLES Where table_schema='common_db';
-- 定义变量
declare continue handler for not found set done=1;set done=0;
-- 代开游标
open feeCodeCursor;
-- 执行循环
the_loop_new : LOOP
--
fetch feeCodeCursor into p_feeCode;
Set abc = concat("common_db.",p_feeCode);
SET sqlstr=concat("CREATE OR REPLACE view ",p_feeCode," as select * from ",abc,";");
set @v_sql=sqlstr;prepare stmt from @v_sql;EXECUTE stmt;deallocate prepare stmt;IF done = 1 THEN
close feeCodeCursor;
LEAVE the_loop_new;
END IF;END LOOP the_loop_new;
END
这篇关于mysql简单存储过程范例之遍历数据库生成视图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!