DB2存储过程中的日志记录

huangapple go评论48阅读模式
英文:

DB2 Logging in stored procedure

问题

在存储过程中创建特定模式(如调试或信息)的日志输出是否可能?
我只知道DBMS_OUTPUT.PUT_LINE命令,但我需要指定日志级别。

英文:

Is it possible to create log outputs in a specific mode like debug or info within a stored procedure?
I just know only awared about the cmd DBMS_OUTPUT.PUT_LINE. But I need it with specification of the log level.

答案1

得分: 0

--#设置终止符@
CREATE TABLE LOG (TS TIMESTAMP NOT NULL, MSG VARCHAR (100))@

CREATE OR REPLACE PROCEDURE LOGGER (P_MSG VARCHAR (100))
AUTONOMOUS 
BEGIN
	INSERT INTO LOG (TS, MSG) VALUES (GENERATE_UNIQUE()::TIMESTAMP, P_MSG);
END@

CREATE TABLE TEST (I INT)@

CREATE OR REPLACE TRIGGER TEST_AIR
AFTER INSERT ON TEST
REFERENCING NEW AS N
FOR EACH ROW
BEGIN ATOMIC
  CALL LOGGER ('Start of insertion: ' || N.I);
  CALL DBMS_ALERT.SLEEP (3);
  CALL LOGGER ('End of inserion: ' || N.I);
END@

INSERT INTO TEST VALUES 1, 2@
SELECT * FROM LOG ORDER BY TS@
TS MSG
2023-02-13-17.41.57.098209 Start of insertion: 1
2023-02-13-17.42.00.115693 End of inserion: 1
2023-02-13-17.42.00.137199 Start of insertion: 2
2023-02-13-17.42.03.163761 End of inserion: 2

<details>
<summary>英文:</summary>

--#SET TERMINATOR @
CREATE TABLE LOG (TS TIMESTAMP NOT NULL, MSG VARCHAR (100))@

CREATE OR REPLACE PROCEDURE LOGGER (P_MSG VARCHAR (100))
AUTONOMOUS
BEGIN
INSERT INTO LOG (TS, MSG) VALUES (GENERATE_UNIQUE()::TIMESTAMP, P_MSG);
END@

CREATE TABLE TEST (I INT)@

CREATE OR REPLACE TRIGGER TEST_AIR
AFTER INSERT ON TEST
REFERENCING NEW AS N
FOR EACH ROW
BEGIN ATOMIC
CALL LOGGER ('Start of insertion: ' || N.I);
CALL DBMS_ALERT.SLEEP (3);
CALL LOGGER ('End of inserion: ' || N.I);
END@

INSERT INTO TEST VALUES 1, 2@
SELECT * FROM LOG ORDER BY TS@


|TS|MSG|
|--|---|
|2023-02-13-17.41.57.098209|Start of insertion: 1|
|2023-02-13-17.42.00.115693|End of inserion: 1|
|2023-02-13-17.42.00.137199|Start of insertion: 2|
|2023-02-13-17.42.03.163761|End of inserion: 2|


</details>



huangapple
  • 本文由 发表于 2023年2月8日 19:32:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定