mysql创建一个函数

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
mengvlog 阅读 50 次 更新于 2025-12-16 11:53:04 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部