整数 POSTGRESQL 的输入语法无效
Invalid input syntax for integer POSTGRESQL
使用 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;
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 时,我没有收到任何错误。但是,当我调用函数 control_reports_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
*Inside Chrg_In_Bill_Not_In_Crm_Fn I 运行 在 sql 执行结果的循环中(当我 运行 this sql in psql 它有效 - 没有错误),我用 UTL 写入文件。
有人可以回答我接下来的问题吗:
1) 为什么会出现该错误?当我在 psql 中调用 func Chrg_In_Bill_Not_In_Crm_Fn 时,我没有收到任何错误 - 只是得到下一个输出:
chrg_in_bill_not_in_crm_fn
----------------------------
0
我意识到在函数 control_reports_fn 中循环没有开始。但是,当我 运行 我在 psql 中的 select 时,我得到了返回的行。为什么它不进入循环,为什么我会收到那个错误?
2) 如您所见,我使用 UTL_FILE 写入文件系统中的文件。但是,我没有看到文件已创建。是因为我收到错误还是其他原因?
我的问题是变量 Rec_Daily_Reports 是 %ROWTYPE 类型,我试图 select 特定列。
感谢您的帮助。
使用 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;
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 时,我没有收到任何错误。但是,当我调用函数 control_reports_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
*Inside Chrg_In_Bill_Not_In_Crm_Fn I 运行 在 sql 执行结果的循环中(当我 运行 this sql in psql 它有效 - 没有错误),我用 UTL 写入文件。
有人可以回答我接下来的问题吗:
1) 为什么会出现该错误?当我在 psql 中调用 func Chrg_In_Bill_Not_In_Crm_Fn 时,我没有收到任何错误 - 只是得到下一个输出:
chrg_in_bill_not_in_crm_fn
----------------------------
0
我意识到在函数 control_reports_fn 中循环没有开始。但是,当我 运行 我在 psql 中的 select 时,我得到了返回的行。为什么它不进入循环,为什么我会收到那个错误?
2) 如您所见,我使用 UTL_FILE 写入文件系统中的文件。但是,我没有看到文件已创建。是因为我收到错误还是其他原因?
我的问题是变量 Rec_Daily_Reports 是 %ROWTYPE 类型,我试图 select 特定列。
感谢您的帮助。