MySQL 中的自定义函数和存储过程 简单实例
来源:互联网 发布:淘宝客服经典对话 编辑:程序博客网 时间:2024/04/27 15:03
需要说明的是:MySQL中没有表变量, 一般是通过临时表来存贮结果集的。
那么 我们如何取出在储存过程中select出来的结果集呢?如果是其它存储过程中,你可以使用生成的临时表。如果是java程序中,你可以直接象执行select * from aa一样调用call xxx();的结果
--MySQL 中的函数
-- 函数 返回int类型DELIMITER $$DROP FUNCTION IF EXISTS `switchnum`$$create FUNCTION switchnum() RETURNS int begin declare v_xx int default null; declare v_yy int default 1; declare v_zz int default 2; set v_xx=v_yy; set v_yy=v_zz; set v_zz=v_xx; return v_zz; end $$ DELIMITER ; select switchnum();
----MySQL中的存储过程
-- 创建存储过程 传入int类型的参数 delimiter ;drop procedure if exists getUserInfo; create PROCEDURE getUserInfo (in us int) begin if (us is not null) then set us=2; end if; end ; set @us=4;call getUserInfo( @us);select @us as tempus; -- 创建存储过程 传入varchar 类型的参数 delimiter;drop procedure if exists getvarchar;create procedure getvarchar( in ad varchar(20)) begin if (ad is not null) then select * from tb_users where username=ad; else select * from tb_users; end if; end ; set @ad=null; call getvarchar(@ad); select @ad; -- 测试drop procedure if exists pr_param_inout;create procedure pr_param_inout(inout id int)beginselect id as id_inner_1; -- id 值为调用者传进来的值if (id is not null) thenset id = id + 1;select id as id_inner_2;elseselect 1 into id;end if;select id as id_inner_3;end;set @inout=2;call pr_param_inout(@inout);select @inout as in_out; -- ---测试procedure delimiter; DROP PROCEDURE IF EXISTS text; create procedure text( out rtn int ) begin declare LoginId INT default 0; set rtn=1; IF LoginId = 3 THEN set rtn=2; ELSEIF LoginId = 0 THEN set rtn=3; ELSE set rtn=4; END IF; end ;call text(@rtn);select @rtn as rtn;
0 0
- MySQL 中的自定义函数和存储过程 简单实例
- (9)mysql中的存储过程和自定义函数
- Mysql中的存储过程和存储函数
- oracle函数和存储过程简单实例
- mysql存储过程和函数使实例
- MySQL存储过程和函数实例
- Mysql中的自定义函数和自定义过程
- mysql创建自定义函数和存储过程
- 4)mysql自定义函数和存储过程
- mysql中的存储过程和函数
- mysql中的函数 存储过程和触发器
- MySQL中的存储过程和函数
- MySQL中的存储过程和函数
- MySQL 触发器 存储过程 自定义函数 视图 简单示例
- mysql存储过程函数实例
- mysql存储过程函数实例
- MySQL学习笔记 4:自定义函数和MySQL存储过程
- 【MySQL】MySQL函数、自定义函数、存储过程
- js判断上传文件的格式和大小
- MFC登陆窗口
- Levenberg–Marquardt algorithm
- Android app进入前的闪屏界面代码
- 给程序员新人的一封信
- MySQL 中的自定义函数和存储过程 简单实例
- [leetcode] Construct Binary Tree from Preorder and Inorder Traversal
- linux驱动中的链表操作
- wxPython源码编译和安装
- POJ 1094 Sorting It All Out
- 页面的缓存与不缓存设置
- 如何让一个div跟随鼠标移动
- Administrator privileges required for OLE Remote Procedure Call debugging: this feature will not wo
- Oracle 数据泵使用详解