简体   繁体   English

Oracle报告将数据库时间戳与当前时间戳进行比较

[英]Oracle Reports Comparing Database Timestamp to Current Timestamp

I'm attempting to write a BeforeReport Trigger that checks to see if a user is accessing report data within 120 seconds of creation. 我试图编写一个BeforeReport触发器,以检查用户是否在创建后的120秒内访问报告数据。

My code is as follows: 我的代码如下:

function BeforeReport return boolean is

ENTRYDATE TIMESTAMP;
SERVERDATE TIMESTAMP;
DIFFSECONDS NUMBER;
begin

/*Checks to see if user is accessing the data within 120 seconds of creation in database*/
VALIDTIMELENGTH := 120;
SELECT SYS_DATE INTO ENTRYDATE FROM WOS_REPORT_PARAM WHERE SEQUENCE_NUM=UPPER(:SEQUENCENUM) AND PARAMETER='year';
SERVERDATE := CURRENT_TIMESTAMP;
DIFFSECONDS := ((EXTRACT(YEAR FROM ENTRYDATE)- EXTRACT(YEAR FROM SERVERDATE))*31536000) +
             ((EXTRACT(MONTH FROM ENTRYDATE)- EXTRACT(MONTH FROM SERVERDATE))*2592000) +
             ((EXTRACT(DAY FROM ENTRYDATE) - EXTRACT(DAY FROM SERVERDATE))*86400) +
             ((EXTRACT(HOUR FROM ENTRYDATE) - EXTRACT(HOUR FROM SERVERDATE))*3600) +
             ((EXTRACT(MINUTE FROM ENTRYDATE) - EXTRACT(MINUTE FROM SERVERDATE))*60) +
             (EXTRACT(SECOND FROM ENTRYDATE) - EXTRACT(SECOND FROM SERVERDATE));
  IF DIFFSECONDS > VALIDTIMELENGTH THEN RETURN(FALSE);
  ELSE
  return (TRUE);
  END IF;
  END;

The problem is, my code seems to return true regardless of how much time has gone by. 问题是,无论经过多少时间,我的代码似乎都返回true。 Am I not implementing my seconds/minutes code correctly? 我没有正确执行秒/分钟代码吗? Oddly enough , I experimented with making both returns (FALSE) and it still proceeded to pass the report! 奇怪的是,我尝试了两种回报率(FALSE),但仍然通过了报告! Oracle Reports is so inconsistent that it's infuriating. Oracle Reports如此不一致,以至于令人发指。 Any response is greatly appreciated. 任何答复,我们将不胜感激。

If wos_report_param.sys_date is a TIMESTAMP (note that it's rather confusing to name a column sys_date when there is a sysdate function that returns a DATE ), and assuming that wos_report_param.sys_date is a timestamp in the past, your logic can be simplified quite a bit 如果wos_report_param.sys_dateTIMESTAMP (请注意,当有sysdate函数返回DATE ,将sys_date列命名是相当混乱的),并假设wos_report_param.sys_date是过去的时间戳,则可以简化您的逻辑一点

IF( current_timestamp - entrydate > numtodsinterval( validTimeLength, 'second' ) )
THEN
  RETURN true;
ELSE 
  RETURN false;
END IF;

If my guess is correct and wos_report_param.sys_date is a timestamp in the past, then the diffseconds you are computing will be a negative number which explains why your procedure always returns false . 如果我的猜测是正确的,并且wos_report_param.sys_date是过去的时间戳,那么您正在计算的diffseconds将为负数,这说明了为什么过程始终返回false You need to subtract the earlier date from the later date in order to yield a positive rather than a negative interval. 您需要从较晚的日期中减去较早的日期,以便产生一个正数而不是负数间隔。 Or you could throw an abs around your diffseconds calculation. 否则,您可以在diffseconds计算周围diffseconds abs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM