单身选择中的多行

时间:2013-12-19 19:42:43

标签: sql singleton interbase

昨天,我们以前从未见过的遗留软件出现了异常现象。它会触发以下错误: multiple rows in singleton select At procedure 'POINTS_BALANCE'

这是存储过程

CREATE PROCEDURE POINTS_BALANCE (
    OPERATOR CHAR (3),
    PERIOD VARCHAR (75))
RETURNS (
    P_BALANCE INTEGER)
AS 

DECLARE VARIABLE B_DATE timestamp;
DECLARE VARIABLE E_DATE timestamp;
DECLARE VARIABLE ALLOWED_POINTS INTEGER;
begin
  P_BALANCE = NULL;
  SELECT DATE_BEGIN, DATE_END, TOTAL_POINTS FROM SCHED_POINT_PERIODS
    WHERE DESCRIPTION = :PERIOD INTO :B_DATE, :E_DATE, :ALLOWED_POINTS;
  IF (B_DATE IS NULL) THEN
   BEGIN    
    SELECT DATE_BEGIN, DATE_END, TOTAL_POINTS FROM SCHED_POINT_PERIODS
      WHERE cast('NOW' as timestamp) BETWEEN DATE_BEGIN AND DATE_END+1 INTO :B_DATE, :E_DATE,
      :ALLOWED_POINTS;
   END
  IF (B_DATE IS NOT NULL) THEN
    BEGIN
     E_DATE = E_DATE + 1;
     SELECT SUM(POINTS)+:ALLOWED_POINTS FROM SCHED_ACTUAL 
      WHERE OPR = :OPERATOR AND BEGIN_TIME BETWEEN :B_DATE AND :E_DATE 
      INTO :P_BALANCE;
     IF (P_BALANCE IS NULL) THEN
       P_BALANCE = ALLOWED_POINTS;
    END
  SUSPEND;
end

SCHED_ACTUAL是一个表,其中包含每个用户的签到和签出时间 SCHED_POINT_PERIODS是一个表,其中包含每个时段的Allowed_Point值(如2013年春季,2013年秋季,2013年圣诞节)

我不确定哪一个是单身人士。有没有办法可以从这个存储过程中分辨出来?

1 个答案:

答案 0 :(得分:0)

SCHED_POINT_PERIODS应该有非重叠的句号。 (即他们应该是独一无二的)。这是错误所指的单身人士。

我注意到这个重叠通过DB并在内部修复了这个。错误已解决。