CREATE FUNCTION `ChkInsert`(in_pk int) returns int begin declare _count int;declare _returnValue int;set _count = 0;select count(列1) into _count from 你的表 where 列1 = in_pk;if _count > 0 then set _returnValue = 2;else insert into 你的表 ( 列1 ) values ( ...
mysql创建一个函数
DELIMITER $$
CREATE FUNCTION `ChkInsert`(in_pk int) returns int
begin
declare _count int;
declare _returnValue int;
set _count = 0;
select count(列1) into _count from 你的表 where 列1 = in_pk;
if _count > 0 then
set _returnValue = 2;
else
insert into 你的表 ( 列1 ) values ( in_pk );
set _returnValue = 0;
end if;
return _returnValue;
end $$2015-12-04
MySQL教程4 MySQL8运算符、函数、存储过程及新增数据类型 17.之创建带有IN和OUT参数的存储过程 学习猿地
2021-01-03