VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 数据库 > MySQL >
  • MySQL教程之

mysql创建存储过程

复制代码
DROP PROCEDURE IF EXISTS getCreateTimes
/*前面要写DELIMITER $$ 或DELIMITER // */
DELIMITER $$ 
CREATE PROCEDURE `getCreateTimes`()
 BEGIN
  SELECT userCreateTime FROM users;

END;
复制代码

mysql 存储过程有参数输入拼接

复制代码
DROP PROCEDURE IF EXISTS getTest01;
DELIMITER $$ 
CREATE PROCEDURE `getTest01`(
  uname VARCHAR(50),
  upass VARCHAR(50)
)
 BEGIN
 SET @sql= 'SELECT * FROM users where 1=1';
 IF uname IS NOT NULL THEN
      SET @sql=CONCAT(@sql,' AND userName=',"'",uname,"'");
      END IF;
  IF upass IS NOT NULL THEN
      SET @sql=CONCAT(@sql,' AND password=',"'",upass,"'");
      END IF;
  PREPARE stmt FROM @sql;
   EXECUTE stmt;    
END;

CALL getTest01(NULL,"123");
复制代码

mysql存储过程含输入参数的拼接的分页 

复制代码
 DROP PROCEDURE IF EXISTS getTest01;
DELIMITER $$ 
CREATE PROCEDURE `getTest01`(
  startPage INT,/*第startPage页,从0开始算*/
  pageSize INT,/*每页显示的记录数*/
  uname VARCHAR(50),
  upass VARCHAR(50)
)
 BEGIN
 SET @sql= 'SELECT * FROM users where 1=1';
 IF uname IS NOT NULL THEN
      SET @sql=CONCAT(@sql,' AND userName=',"'",uname,"'");
      END IF;
  IF upass IS NOT NULL THEN
      SET @sql=CONCAT(@sql,' AND password=',"'",upass,"'");
      END IF;
      SET @sql=CONCAT(@sql,' LIMIT ',startPage*pageSize,",",pageSize);
  PREPARE stmt FROM @sql;
   EXECUTE stmt;    
END;

CALL getTest01(4,2,NULL,NULL);
复制代码

 

--------------------------------------------------------------------------------------------------------------------------------------------

 

作者:Honey_Badger —— 觉得这文章好,点一下左下角 

出处:http://tk55.cnblogs.com/



相关教程