1. 创建存储过程:
CREATE OR REPLACE PROCEDURE PROCEDURE_NAME(IN FILED FILE_TYPE|OUT FIELD FIELD_TYPE|INOUT FIELD_TYPE)
BEGIN
[DECLARE I INT DEFAULT 1;]
[可以写循环:
REPEAT
UNTIL (...)
END REPEAT;
]
...
END
@
2. 例子:
CREATE OR REPLACE PROCEDURE INSERTDATA(
IN COUNTS INT
)
BEGIN
DECLARE I INT DEFAULT 1;
REPEAT
insert into ESBTLOG(UUID, UUID_POS, MSG_ID, ESB_CODE, CLI_ID, CLI_ID_BOCS, SERV_ID, SERV_TRAN_CODE, SERV_TCODE, ESB_RET_CODE, ERR_MSG, TRACE_NO, TRAN_DATE, TRAN_TIME, TXN_STATUS, JOURNAL_NO, EXT_UUID, TXN_TOKEN, NODE_NAME, TRAN_BEGIN_TIME, TRAN_END_TIME, SP1_BEGIN_TIME, SP1_END_TIME, USER_BOCS, WKSTATION, RET_TRAN_DATE, RET_TRAN_TIME, RET_AC_DATE, RET_TRACE_NO, AP_TRACE_NO, BR_NO, TM_SMP)
values('141114B0000R', '0-0-0-0-25', '414d51204553422e514d312020202020afab9e5810880020', 'BOCI060460', '520', '14', '-', '-', '000000', '2020001003', 'Send To client error.QM:CAPAQ01 QUEUE:ESB.CAP.RES.LQ1', '530000U1KQUMT', '20180730', '095310', 'E', '-', '-', '-', 'ESB.QM2', '2018-12-11-09.51.16.398765', '2018-12-11-09.51.16.398765', '2018-12-11-09.51.16.398765', '2018-12-11-09.51.16.398765', '4980261', '994', '-', '-', '-', '-', '-', '51604', '2018-12-11-09.51.16.398765');
SET I = I + 1;
UNTIL (I > COUNTS)
END REPEAT;
END
@
注意:写存储过程需要以一个符号结尾,此处用的是@符号
3. 查找存储过程
db2 "select * from SYSCAT.PROCEDURES where PROCNAME='INSERTDATA'"
4. 删除存储过程
db2 "drop procedure INSERTDATA2SIPTLOG(INT,VARCHAR())"
注意:要将参数带进去
5. 执行存储过程文件
db2 -td@ -vf filename (该文件需以@符号结尾).
-td选项让命令行处理程序使用@作为语句终止字符;-v选项让命令处理程序将命令文本回显到标准输出;-f让命令行处理程序从指定文件读取命令输入
网友评论