Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4180215
  • 博文数量: 240
  • 博客积分: 11504
  • 博客等级: 上将
  • 技术积分: 4277
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-28 14:24
文章分类

全部博文(240)

分类: Mysql/postgreSQL

2007-03-08 13:24:56

这个SP写的不是很规范,有时间我修改一下。


-- Created by david yeung 2006-10-31

-- A store procedure to get result from mutiple offered values

DELIMITER $$

DROP PROCEDURE IF EXISTS
`test`.`sp_pers_srch`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_pers_srch`(IN comp_id int(15),IN var_emplid varchar(15),
 IN var_first_name varchar(30),IN var_last_name varchar(30))
BEGIN

  -- The original sql statments.
  SET @stmt = "SELECT emplid,first_name,last_name FROM ipy_pers_data WHERE 1 = 1";
  SET @op = "'";
  SET @e = " AND emplid = ";
  SET @f = " AND first_name = ";
  SET @l = " AND last_name = ";
  SET @c = " AND company_id = ";

  -- Begin if.
  IF IFNULL(NULL,LENGTH(var_emplid)) != 'NULL' THEN
    SET @stmt = CONCAT(@stmt,@e,@op,var_emplid,@op);
  END IF;
  IF IFNULL(NULL,LENGTH(var_first_name)) != 'NULL' THEN
    SET @stmt = CONCAT(@stmt,@f,@op,var_first_name,@op);
  END IF;
  IF IFNULL(NULL,LENGTH(var_last_name)) != 'NULL' THEN
    SET @stmt = CONCAT(@stmt,@l,@op,var_last_name,@op);
  END IF;

  -- End if.

  -- Concat all the dynamic sql statement.

  SET @stmt = CONCAT(@stmt,@c,@op,comp_id,@op);
  PREPARE s1 FROM @stmt;
  EXECUTE s1;
  DEALLOCATE PREPARE s1;
  IF FOUND_ROWS() != 0 THEN
    SET @error_code = 0;
  ELSE
    SET @error_code = 1;
  END IF;

   SELECT @error_code;

  -- Free memory.

  SET @stmt = '';

  SET @c = '';

  SET @e = '';

  SET @l = '';

  SET @f = '';

END$$

DELIMITER ;



阅读(2737) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:[转贴]JavaScript中Array(数组)的属性和方法

给主人留下些什么吧!~~