整数POSTGRESQL的输入语法无效
使用ora2pg工具,我将oracle func转换为下一个函数:整数POSTGRESQL的输入语法无效,postgresql,plpgsql,Postgresql,Plpgsql,使用ora2pg工具,我将oracle func转换为下一个函数: CREATE OR REPLACE FUNCTION Control_Reports_Pg.control_reports_fn (P_Report_Type bigint, P_Log_File_Name text,C_Path text) RETURNS bigint AS $body$ DECLARE V_Return smallint; V_Function_Return smallint:=1;
CREATE OR REPLACE FUNCTION Control_Reports_Pg.control_reports_fn (P_Report_Type bigint, P_Log_File_Name text,C_Path text) RETURNS bigint AS
$body$
DECLARE
V_Return smallint;
V_Function_Return smallint:=1;
C_Daily_Reports varchar(300);
C_Function_Name varchar(200) := 'Control_Reports_Fn';
Rec_Daily_Reports CONTROL_REPORTS%ROWTYPE;
G_Log_File_Type UTL_FILE.FILE_TYPE;
BEGIN
-- Open Log File
--PERFORM control_reports_pg.send_error_mail(C_Path ,C_Function_Name);
G_Log_File_Type := UTL_FILE.FOPEN(C_Path, P_Log_File_Name,'w');
C_Daily_Reports := 'SELECT REPORT_ORDER,PROCEDURE_NAME,DIRECTORY_NAME,FILE_NAME,TITLE FROM CONTROL_REPORTS WHERE RUN_FLAG=1 AND REPORT_TYPE=' || P_Report_Type || ' ORDER BY REPORT_ORDER';
-- RAISE NOTICE '%',C_Daily_Reports;
FOR Rec_Daily_Reports IN EXECUTE C_Daily_Reports LOOP
PERFORM UTL_FILE.PUT_LINE(G_Log_File_Type,'Procedure_Name = '||Rec_Daily_Reports.Procedure_Name);
PERFORM UTL_FILE.PUT_LINE(G_Log_File_Type,'start time= '|| to_char(clock_timestamp(),'dd/mm/yyyy hh24:mi:ss'));
V_Return := control_reports_pg.chrg_in_bill_not_in_crm_fn(Rec_Daily_Reports.Directory_Name,
Rec_Daily_Reports.File_Name,
Rec_Daily_Reports.Title);
IF V_Return = 0 THEN
V_Function_Return := 0;
END IF;
............
当我连接到psql并调用函数chrg_in_bill_not_in_crm_fn和相关参数时,我没有得到任何错误。但是,当我调用函数控制报告时,我得到下一个错误:
mydb=> select Control_Reports_Pg.control_reports_fn (arg1,arg2,arg3);
NOTICE: FUNC : Control_Reports_Fn, SQLERRM: invalid input syntax for integer: "Chrg_In_Bill_Not_In_Crm_Fn"
CONTEXT: PL/pgSQL function control_reports_pg.daily_control_reports_fn() line 9 at assignment
NOTICE: Message : invalid input syntax for integer: "Chrg_In_Bill_Not_In_Crm_Fn", Func : Control_Reports_Fn
CONTEXT: SQL statement "SELECT control_reports_pg.send_error_mail(SQLERRM ,C_Function_Name)"
PL/pgSQL function control_reports_pg.control_reports_fn(bigint,text,text) line 339 at PERFORM
PL/pgSQL function control_reports_pg.daily_control_reports_fn() line 9 at
assignment
daily_control_reports_fn
--------------------------
1
*在Chrg_In_Bill_Not_In_Crm_Fn内部,我在循环中运行sql执行的结果,当我在psql中运行此sql时,它可以工作-没有错误,我使用UTL写入文件
有人能回答我下面的问题吗
1为什么我会犯这样的错误?当我在psql中调用func Chrg_In_Bill_Not_In_Crm_Fn时,我没有得到任何错误-只是得到下一个输出:
chrg_in_bill_not_in_crm_fn
----------------------------
0
我意识到在func控制报告中,循环不会启动。但是,当我运行psql中的select时,我得到了返回的行。为什么它没有进入循环,为什么我会出错
2如您所见,我使用UTL_文件写入文件系统中的文件。但是,我看不到文件是否已创建。是因为我出错还是其他原因?我的问题是变量Rec_Daily_Reports的类型为%ROWTYPE,我试图选择特定的列
谢谢您的帮助。PostgreSQL中没有UTL_文件。如果您使用的是EnterpriseDB的PostgreSQL分支,那么应该使用标记postgres-plus.There is。我正在使用一个名为orafce的扩展名,因此我可以使用utl_文件。查看您的问题,我看不出有错误,只有一个通知。也许您捕获了一个异常并将其报告为通知?无论如何,如果你想要答案,你必须发布整个函数定义,包括第339行以及控制报告的定义。