У меня есть скрипт в процедуре Oracle как Pragma aut автономная_транзакция:
CREATE OR REPLACE EDITIONABLE PROCEDURE "CIDR_STAGING"."PR_WRITE_ERROR_LOG" is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
insert into cidrmgmt.errorlog(
tstamp, os_user,host,module,errorcode,errormsg)
values
(sysdate, v_os_user, v_host, v_module, v_ErrorCode, v_ErrorMsg );
commit;
end;
/
и другая процедура для вызова процедуры транзакции:
CREATE OR REPLACE EDITIONABLE PROCEDURE "CIDR_STAGING"."PR_MIG_STG_FORMS" ( v_Ret OUT number )
as
v_ErrorCode number;
v_ErrorMsg varchar2(512);
v_Module varchar2(32) := 'PR_MIG_STG_FORMS';
begin
----
-- Simply delete the data from production table
----
delete from cidrdba.ref_forms where 1=1;
----
-- Simply copy the data from staging into production
----
insert into cidrdba.ref_forms(
form_number, form_title, mig_filename
)
select form_number, form_title, mig_filename
from cidr_staging.stg_ref_forms;
----
-- Set the return code to 0
----
v_Ret := SQLCODE;
----
-- Exception error handler
----
exception
when others then
v_ErrorCode := SQLCODE;
v_ErrorMsg := SQLERRM;
v_Ret := v_ErrorCode;
----
-- Commit the record into the ErrorLog
----
pr_write_error_log( sys_context('userenv','session_user'),
sys_context('userenv','host'), v_Module,
v_ErrorCode, v_ErrorMsg );
----
-- Intentionally leaving the "commit" to application
----
end;
/
и я преобразовал его в Postgres Pragma aut автономную_транзакцию, и я не уверен, что оно исправлено, но оно не выдало ошибку.
create or replace FUNCTION "PR_WRITE_ERROR_LOG" ( v_os_user IN varchar(4000), v_host IN
varchar(4000), v_module IN varchar(4000), v_errorcode IN int, v_errormsg IN varchar(4000) )
RETURNS VOID
as $$
BEGIN
START TRANSACTION;
insert into cidrmgmt.errorlog(
tstamp, os_user,host,module,errorcode,errormsg)
values
(current_timestamp, v_os_user, v_host, v_module, v_ErrorCode, v_ErrorMsg );
/* commit; */
end;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION "CIDR_STAGING"."PR_MIG_STG_FORMS" ( v_Ret OUT int ) RETURNS integer
as $$
declare
v_ErrorCode int;
v_ErrorMsg varchar(512);
v_Module varchar(32) = 'PR_MIG_STG_FORMS';
begin
----
-- Simply delete the data from production table
----
delete from cidrdba.ref_forms where 1=1;
----
-- Simply copy the data from staging into production
----
insert into cidrdba.ref_forms(
form_number, form_title, mig_filename
)
select form_number, form_title, mig_filename
from cidr_staging.stg_ref_forms;
----
-- Set the return code to 0
----
v_Ret := SQLCODE;
----
-- Exception error handler
----
exception
when others then
v_ErrorCode := SQLCODE;
v_ErrorMsg := SQLERRM;
v_Ret := v_ErrorCode;
----
-- Commit the record into the ErrorLog
----
**RAISE NOTICE 'Calling "CIDR_STAGING"."PR_WRITE_ERROR_LOG"(%)', ( sys_context('userenv','session_user'),
sys_context('userenv','host'), v_Module,
v_ErrorCode, v_ErrorMsg );**
or
**PERFORM pr_write_error_log( sys_context('userenv','session_user'),
sys_context('userenv','host'), v_Module,
v_ErrorCode, v_ErrorMsg );
-- Intentionally leaving the "commit" to application**
----
end;
$$ LANGUAGE plpgsql;
и как мне выполнить другую функцию внутри функции, как Oracle? Я искал и нашел параметры поднять журнал, поднять информацию, поднять до и выполнить. Я хочу понять, как вызвать функцию с функцией типа Oracle, не могли бы вы объяснить это?