我使用ora2pg将oracle(12c)包迁移到postgres(EnterpriseDB10.5)。大多数函数都成功地运行了迁移。但是,包中多次引用的一个函数会导致错误。我给出了以下两个版本的代码: oracle
create or replace package body sms_package as
--- Other functions
PROCEDURE LOG_MESSAGE (LogType varchar2, LogDetails varchar2) IS
BEGIN
INSERT INTO SMS_TABLE (REF_DATE, LOG_TYPE, LOG_DETAILS)
VALUES (SYSDATE, LogType, LogDetails);
COMMIT;
END;ora2pg
CREATE OR REPLACE FUNCTION log_message (LogType text, LogDetails text) RETURNS VOID AS $body$
BEGIN
INSERT INTO SMS_TABLE(REF_DATE, LOG_TYPE, LOG_DETAILS)
VALUES (clock_timestamp(), LogType, LogDetails);
COMMIT;
END;
$body$
LANGUAGE PLPGSQL
;引用的示例: oracle
procedure sendtest (dash_type varchar2, sms_message varchar2) IS
cursor x is
SELECT ISDN FROM oracle_store;
begin
dbms_output.put_line('1');
if sms_message is not null then
for i in x loop
insert into s_table(message_text, received_time, DELIVERY_STATUS, retry_attempts) values (..);
sms_package.LOG_MESSAGE (dash_type, 'sending to '||i.ISDN||' message =>'||sms_message);
dbms_output.put_line('notification_type='||dash_type||' sms='||sms_message);
end loop;
commit;
end if;
end;ora2pg
CREATE OR REPLACE FUNCTION sendtest (dash_type text, sms_message text) RETURNS VOID AS $body$
DECLARE
x CURSOR FOR
SELECT ISDN FROM postgres_store;
BEGIN
RAISE NOTICE '1';
if sms_message is not null then
for i in x loop
insert into s_table(message_text, received_time, DELIVERY_STATUS, retry_attempts) values ();
sms_package.LOG_MESSAGE(dash_type, 'sending to '||i.ISDN||' message =>'||sms_message);
RAISE NOTICE 'notification_type=% sms=%', dash_type, sms_message;
end loop;
commit;
end if;
end;
$body$
LANGUAGE PLPGSQL在从另一个函数中调用该函数时出现了问题,因为正在获取此错误。
[42601] ERROR: syntax error at or near "sms_package"如何从postgres中的函数内部执行另一个函数。如何从另一个函数中调用该函数?
发布于 2019-09-02 11:06:58
由于sms_package.LOG_MESSAGE是PostgreSQL中的一个函数,所以必须在PL/pgSQL中使用PERFORM调用它:
PERFORM sms_package.LOG_MESSAGE(...);但是您的代码中还有其他问题。至少芬兰定义中的COMMIT将导致错误。
您可能需要重新设计和重写代码。
https://dba.stackexchange.com/questions/246750
复制相似问题