gpt4 book ai didi

function - 在 postgresql 中运行函数抛出运行时错误

转载 作者:行者123 更新时间:2023-11-29 13:30:23 26 4
gpt4 key购买 nike

当我尝试运行一个返回表的函数时,我遇到了一个神秘的错误,我的函数代码是这样的

CREATE OR REPLACE FUNCTION FN_JOURNEY_SUMMARY(IN ENTITY INTEGER,
IN VEHICLE VARCHAR2,
IN SDATE VARCHAR2,
IN EDATE VARCHAR2,
IN FLG VARCHAR,
IN P_IS_DEBUG CHAR DEFAULT 'Y')
RETURNS TABLE(TRNNAME VARCHAR2(100),
SASSETID VARCHAR2(50),
DTDATE VARCHAR2(50),
IDAYS NUMBER,
SMOVINGTIME VARCHAR2(30),
SSTOPTIME VARCHAR2(30),
SDISTANCE VARCHAR2(60),
SCUMMDISTANCE VARCHAR2(60),
SAVARAGE VARCHAR2(60),
ICNTR NUMBER)
LANGUAGE PLPGSQL
AS $FUNCTION$
DECLARE

TM_START DATE;
TM_END DATE;
I_ELAPS_TIME NUMBER;
BEGIN
TM_START:= CLOCK_TIMESTAMP();
BEGIN
CREATE TEMPORARY TABLE GTT_V4JOURNEY_SUMM1 (TRN_NAME VARCHAR2(100),
S_ASSET_ID VARCHAR2(50),
DT_DATE VARCHAR2(50),
I_DAYS NUMBER,
S_MOVING_TIME VARCHAR2(30),
S_STOP_TIME VARCHAR2(30),
S_DISTANCE VARCHAR2(60),
S_CUMM_DISTANCE VARCHAR2(60),
S_AVARAGE VARCHAR2(60),
i_cntr number);
EXCEPTION
WHEN OTHERS THEN
DROP TABLE GTT_V4JOURNEY_SUMM1;
CREATE TEMPORARY TABLE GTT_V4JOURNEY_SUMM1 (TRN_NAME VARCHAR2(100),
S_ASSET_ID VARCHAR2(50),
DT_DATE VARCHAR2(50),
I_DAYS NUMBER,
S_MOVING_TIME VARCHAR2(30),
S_STOP_TIME VARCHAR2(30),
S_DISTANCE VARCHAR2(60),
S_CUMM_DISTANCE VARCHAR2(60),
S_AVARAGE VARCHAR2(60),
i_cntr number);

END;

INSERT INTO GTT_V4JOURNEY_SUMM1
SELECT * FROM FN_JOURNEY_SUMM_WEEK(ENTITY,VEHICLE, SDATE,EDATE,P_IS_DEBUG);

IF P_IS_DEBUG = 'Y' THEN
TM_END:=CLOCK_TIMESTAMP();
RAISE NOTICE 'THE START TIME WAS %',TM_START;
RAISE NOTICE 'THE END TIME WAS %',TM_END;
I_ELAPS_TIME:=EXTRACT(MICROSECONDS FROM (TM_END - TM_START))/1000;
RAISE NOTICE 'THE TIME TAKEN IS >>>>>>-------------->>>>>>> %',I_ELAPS_TIME;
END IF;
RAISE NOTICE '*** end of all ***';
RETURN QUERY SELECT * FROM GTT_V4JOURNEY_SUMM1 ;

END $FUNCTION$;

当我运行函数时:

select * from FN_JOURNEY_SUMMARY(100,'NL01L0639','28/03/2014','23/06/2014','W',1);

这给我一个错误:

invalid input syntax for type timestamp: "28-Mar:28-Mar-14(13)"

它存储在返回表的 DTDATE 列中,它是一个 character varying 类型。

但是当我用不同的名称编译相同的函数时,不会抛出任何错误并且运行顺利。

最佳答案

这是一团糟。而且它肯定不会像您声称的那样编译。

VARCHAR2NUMBER 无效 data types in Postgres .

TM_STARTTM_END 应该是 timestamptimestamptz,而不是 date

P_IS_DEBUG 应该是 boolean

您的 INSERT 语句应该有一个目标列表。

关于function - 在 postgresql 中运行函数抛出运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25216278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com