一个MYSQL多值查询的存储过程
DELIMITER $$
DROP PROCEDURE IF EXISTS `ipy`.`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
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 = ";
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;
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;
END$$
DELIMITER ;
分享到:
相关推荐
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 代码如下:select * from peoplewhere peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)2、删除...
数据库查询删除重复数据是数据库管理中的一项重要操作,旨在查找和删除表中的重复记录。重复记录是根据单个字段或多个字段来判断的。下面介绍几种查找和删除重复记录的方法。 根据单个字段查找和删除重复记录 可以...
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 例二: ...
1. **根据单个字段删除重复数据:** 当我们需要删除基于特定字段(如 `peopleId`)的重复数据时,可以先找出这些重复项,然后删除除最小 ROWID 之外的所有记录。例如: ```sql -- 查找重复的 peopleId SELECT * ...
查询及删除重复记录的SQL语句1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select peopleId from people group by peopleId having count...
针对单个字段查找并删除重复记录的情况,例如根据`peopleId`字段,可以执行以下操作: 1. 查找重复记录: ```sql SELECT * FROM people WHERE peopleId IN ( SELECT peopleId FROM people GROUP BY peopleId ...
在MySQL数据库管理中,有时我们需要查询并处理表中的重复数据。本文将详细介绍如何利用SQL语句来检测和处理这些重复信息。 首先,我们要理解“重复数据”是指在某个或某些字段上具有相同值的记录。以下是一些常用的...
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 2、删除表中多余的...