【发布时间】:2022-11-02 10:48:13
【问题描述】:
需要帮助来处理以下要求。
我们需要处理可能出现在 pl sql 块中的异常,并将 select 语句中的某些值记录到量身定制的表 - audit_log 中。 例如:
audit_log 表结构: col1,stored_procedure_name,error_code
CREATE OR REPLACE PROCEDURE SP_TEMP()
LANGUAGE plpgsql
AS $procedure$
declare
begin
/* loop through the data in table_a */
for sq in (select a.column1,a.column2..a.columnN from table_a a )
loop
/*Do some operations (not shown here) and select data from table_b */
(
select col1, col2, col3
from table_b b where
b.col1=sq.column1 )
/*insert into table_c*/
insert into table_c
values(sq.column1,sq.column2,b.col2,b.col3);
end loop;
EXCEPTION:
WHEN OTHERS THEN
/* Log the failure information to audit_log table */
insert into audit_log
values(column1, 'SP_TEMP',SQLERRM)
end
$procedure$
;
是否有可能做到这一点?如何将 column1 值传递给异常?
我们无法将 column1 值传递给异常。
【问题讨论】:
标签: postgresql exception plpgsql