我在MySQL中有以下功能。
当一行成功插入行时,如何使函数返回GUID
,如果“插入”出现错误,如何返回MySQL错误消息。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `fnInsertBusinessInfo`(
BU_NAME VARCHAR(300),
BU_PHONE VARCHAR(20),
BU_TYPE VARCHAR(50)
) RETURNS varchar(100) CHARSET latin1
BEGIN
DECLARE
BU_ID VARCHAR(100);
SET BU_ID := (SELECT UUID());
INSERT INTO tb_business_info (BU_ID,BU_NAME,BU_PHONE,BU_TYPE) values (BU_ID,BU_NAME,BU_PHONE,BU_TYPE);
RETURN BU_ID;
END
我已经设法返回id
但是如何在不成功的插入时返回错误消息?
答案 0 :(得分:0)
DECLARE
BU_ID VARCHAR(100);
--modify SET BU_ID := (SELECT UUID());
SELECT UUID() into BU_ID;
INSERT INTO tb_business_info (BU_ID,BU_NAME,BU_PHONE,BU_TYPE) values (BU_ID,BU_NAME,BU_PHONE,BU_TYPE);
RETURN BU_ID;
END