mySql 存储过程与函数

过程

CREATE DEFINER=`root`@`%` PROCEDURE `clearDate_Jk`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN

DELETE   FROM sys_dept WHERE create_time > '2023-12-31';
truncate table sys_file;

END
CREATE DEFINER=`root`@`%` PROCEDURE `getAssets`(
	IN `companyId` BIGINT
)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
   SELECT CAST(JSON_UNQUOTE(JSON_EXTRACT(a.infos,'$."总资产"')) AS DECIMAL(10, 2)) AS zzc
 FROM bs_company_financial a  WHERE  del_flag =0 AND years = YEAR(CURDATE()) 
 ORDER BY  update_time  LIMIT 1;
END

函数

CREATE DEFINER=`root`@`%` FUNCTION `tt`(
	`Param1` INT
)
RETURNS decimal(10,0)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
declare num decimal default 0;
	set num = Param1;
return num;
END
posted @ 2024-05-24 09:55  寒冷的雨呢  阅读(3)  评论(0编辑  收藏  举报