此示例是存储过程简单的插入数据,如有更新、合并,需要自己根据项目需求实现。
SET SCHEMA TMISUSR ;
SET CURRENT PATH = "SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","TMISUSR";
CREATE PROCEDURE "TMISUSR"."PRO_ADD_LOG"
(IN "FISK_CODE" CHARACTER(12),
IN "USER_CODE" VARCHAR(20),
IN "USER_NAME" VARCHAR(40),
IN "USER_IP" VARCHAR(30),
IN "USER_ACTION" VARCHAR(40),
IN "USER_CONTENT" VARCHAR(100),
IN "LOG_DATE" DATE,
OUT "PO_I_RETCODE" INTEGER,
OUT "PO_S_RETINFO" VARCHAR(400)
)
SPECIFIC "TMISUSR"."SQL170610131252485"
DYNAMIC RESULT SETS 1
LANGUAGE SQL
NOT DETERMINISTIC
CALLED ON NULL INPUT
EXTERNAL ACTION
OLD SAVEPOINT LEVEL
MODIFIES SQL DATA
INHERIT SPECIAL REGISTERS
------------------------------------------------------------------------
P1: BEGIN
---------------------------------------------------------------------
-----------************1.变量声明***********---------------
---------------------------------------------------------------------
-- 声明变量
-- 声明错误代码
DECLARE SQLCODE INT DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE v_s_ErrMsg varchar(1024);--错误原因描述
-- 声明异常处理
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000'
BEGIN
END;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS EXCEPTION 1 v_s_ErrMsg = MESSAGE_TEXT;
VALUES(SQLCODE,'错误状态:'||SQLSTATE||'说明:'||v_s_ErrMsg) into PO_I_RETCODE,PO_S_RETINFO;
END;
---------------------------------------------------------------------
-----------************2.查询条件***********---------------
---------------------------------------------------------------------
insert into table_log(fisk_code,user_code,user_name,user_ip,user_action,user_content,log_date)
values(fisk_code,user_code,user_name,user_ip,user_action,user_content,log_date);
COMMIT;
VALUES (0) INTO PO_I_RETCODE;
END P1;