1.MySql函数中不能使用动态sql
CREATE DEFINER=`root`@`%` PROCEDURE `SP_GetEmpFixedSalary`(id BIGINT(20),#定薪id或者薪档id
entId BIGINT(20),#企业id
type INT,#自定义或者薪档
cluName VARCHAR(200),
OUT salary DECIMAL(9,2))
BEGIN
#type 1:员工定薪 2: 薪档定薪
IF(type=1) THEN
set @sql = CONCAT('SELECT @salaryTemp := ',cluName,' FROM s_group_emp WHERE ID=? AND ENT_ID=? LIMIT 1');
prepare stmt1 from @sql;
SET @p2 = id;
SET @p3 = entId;
execute stmt1 USING @p2,@p3;
DEALLOCATE PREPARE stmt1 ;
ELSEIF(type=2) THEN
set @sql = CONCAT('SELECT @salaryTemp := ',cluName,' FROM s_level WHERE LEVEL_ID=? AND ENT_ID=? LIMIT 1');
prepare stmt2 from @sql;
SET @p2 = id;SET @p3 = entId;
execute stmt2 USING @p2,@p3;
DEALLOCATE PREPARE stmt2 ;
END IF;
SET salary=@salaryTemp;
END