delimiter //
drop procedure if exists operate_tables //
create procedure operate_tables (in db_name varchar(100), in operate varchar(100))
begin
declare finish int default 0;
declare tab_name varchar(100);
-- 把select 出来的数据放到游标中
declare cur_tables cursor for select table_name from information_schema.tables
where table_schema = db_name and table_type = 'base table';
-- 若没有数据返回,程序继续,并将变量finish设为1
declare continue handler for not found set finish = 1; open cur_tables; exce_loop:loop
if finish = 1 then
leave exce_loop;
end if;
fetch cur_tables into tab_name;
set @str = concat(operate , ' ', db_name, '.', tab_name);
prepare stmt from @str; -- 预定义sql
execute stmt; -- (如果sql有参数的话, USING xxx,xxx); 这里USING的只能是会话变量
deallocate prepare stmt; -- 释放连接
end loop; close cur_tables;
end; //
delimiter ; -- call operate_tables('test', 'truncate');
-- call operate_tables('test', 'drop table');

mysql 存储过程 (ps:用法自己看 :)的更多相关文章

  1. MySQL 存储过程参数用法 in, out, inout

    MySQL 存储过程参数有三种类型:in.out.inout.它们各有什么作用和特点呢? 一.MySQL 存储过程参数(in) MySQL 存储过程 “in” 参数:跟 C 语言的函数参数的值传递类似 ...

  2. mysql存储过程简单用法

    show procedure status 查看所有存储过程 <!--  简单存储过程  --> 先将结束符改成// delimiter // create procedure query ...

  3. MySQL存储过程02

    这次接着说MySQL存储过程: 我们先看它的多分支控制结构case: case的语句很简单: case 变量名 when 条件1 then 输出结果1; when 条件2 then 输出结果2; .. ...

  4. mysql存储过程出参入参,sqlserver很熟悉的一件事到mysql,捣鼓了大半天。记录一下提醒自己。勿看

    create PROCEDURE myTestProcname(in score int ,out result varchar(100))BEGINIF score>60 THENset re ...

  5. MySQL 存储过程传参之in, out, inout 参数用法

    存储过程传参:存储过程的括号里,可以声明参数. 语法是 create procedure p([in/out/inout] 参数名  参数类型 ..) in :给参数传入值,定义的参数就得到了值 ou ...

  6. Mysql存储过程知识,案例--mysql存储过程基本函数

    Mysql存储过程知识,案例: create procedure delete_setting(in p_settingid integer) begin delete from setting wh ...

  7. MySQL存储过程学习笔记

    MySQL在5.0以前并不支持存储过程,这使得MySQL在应用上大打折扣.MySQL 5.0终于开始支持存储过程了. MySQL的关键字大小写通用.该学习笔记对关键字使用大写:变量名,表名使用小写. ...

  8. 【转】MySQL存储过程中使用动态行转列

    MySQL存储过程中使用动态行转列 最近做项目关于数据报表处理,然而数据库存储格式和报表展现形式不同,需要进行一下行转列的操作,在做上一个项目的时候也看了一下,但是后来换了读取方式,也就没深入研究这个 ...

  9. MySQL存储过程的动态行转列

    MySQL存储过程中使用动态行转列 最近做项目关于数据报表处理,然而数据库存储格式和报表展现形式不同,需要进行一下行转列的操作,在做上一个项目的时候也看了一下,但是后来换了读取方式,也就没深入研究这个 ...

随机推荐

  1. 2018年蓝桥杯b组国赛真题

    1.标题:换零钞x星球的钞票的面额只有:100元,5元,2元,1元,共4种.小明去x星旅游,他手里只有2张100元的x星币,太不方便,恰好路过x星银行就去换零钱.小明有点强迫症,他坚持要求200元换出 ...

  2. 使用Sigar做后台服务器管理时,遇到的linux上的问题

    首先是线下猛如虎,线上惨不忍赌........ 问题的出处是: function change() { /*获取cpu*/ $.ajax({ url: "http://localhost:8 ...

  3. C# 中的数据库操作~存储过程篇Mysql SqlServer

    Mysql 存储过程查询方式 SQL server 普通数据库操作 EF 调用SQL SERVER存储过程 Mysql 存储过程查询方式: public NetPort GetNetdevicePor ...

  4. Springboot源码分析之事务拦截和管理

    摘要: 在springboot的自动装配事务里面,InfrastructureAdvisorAutoProxyCreator ,TransactionInterceptor,PlatformTrans ...

  5. lua_lua与.Net互相调用

    配置环境:创建C#项目,引入luainterface-1.5.3\Built下面的LuaInterface.dll文件和luanet.dll文件.引入命名空间using LuaInterface 代码 ...

  6. 18_init 函数的使用

    1.init()函数是一个内置函数,在程序执行前会先执行init()函数,及在main()函数执行前执行 2.如果调用包里有init()函数,会先执行调用包的init()函数,在这执行本函数的init ...

  7. hbase G1 GC优化

    本文借鉴之前HBaseConAsia2017,小米公司对hbase g1 gc的优化分享.此外还可以参考apache官方博客对于hbase g1 gc优化的一篇文章(Tuning G1GC For Y ...

  8. NLP(四) 正则表达式

    * + ? * :0个或多个 + :1个或多个 ? :0个或1个 re.search()函数,将str和re匹配,匹配正确返回True import re # 匹配函数,输入:文本,匹配模式(即re) ...

  9. lightoj 1201 - A Perfect Murder(树形dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1201 题解:简单的树形dp,dp[0][i]表示以i为根结点不傻i的最多有多少 ...

  10. Covered Points Count CF1000C 思维 前缀和 贪心

     Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...