----- MYSQL代码-----
CREATE DEFINER=`uativiza_v3`@`localhost` PROCEDURE `Procedure name`(IN p_processno INT)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
CALL offline_logger (p_processno,'Exception caught -----Exception caught : RollingBack!') ;
ROLLBACK ;
END ;
START TRANSACTION ;
Insert into table1 select * from table2
COMMIT ;
END$$
DELIMITER ;
-摘要 如果在插入时发生任何异常,则上述过程调用offline_logger过程
以上代码我必须迁移到postgresql中。那么如何在PostgreSQL中处理Handler(Exception)
答案 0 :(得分:0)
这将大致翻译为
CREATE PROCEDURE procedure_name(IN p_processno integer)
LANGUAGE plpgsql AS
$$BEGIN
INSERT INTO table1
SELECT * FROM table2;
EXCEPTION
WHEN OTHERS THEN
CALL offline_logger(
p_processno,
'Exception caught -----Exception caught : RollingBack!'
);
END;$$;
INSERT
会在发生异常时自动回滚。