-2

我正在尝试在 oracle 中重写以下查询我使用 sql server 编写它

--check if there is no exam at the same time
IF EXISTS (
    SELECT DISTINCT 'TRUE'
    FROM FinalExams
    WHERE ClassID = @pClassID
        AND SectionID = @pSectionID
        AND ExamDate = @pExamDate
        AND @pStartHoure BETWEEN DATEADD(minute, - 1, StartHoure)
            AND DATEADD(minute, - 1, FinishHoure)
        AND @pFinishHoure NOT BETWEEN DATEADD(minute, - 1, StartHoure)
            AND DATEADD(minute, - 1, FinishHoure)
        OR StartHoure > @pStartHoure
        AND FinishHoure < @pFinishHoure
    )

有人可以帮忙吗?

4

1 回答 1

1

这就是您在 Oracle 中完成它的方式:

DECLARE
  v_cnt NUMBER;
BEGIN
  SELECT COUNT(1)
    INTO v_cnt
    FROM dual
  WHERE EXISTS (
    SELECT 1
    FROM FinalExams
    WHERE ClassID = p_ClassID
        AND SectionID = p_SectionID
        AND ExamDate = p_ExamDate
        AND p_StartHoure BETWEEN StartHoure - INTERVAL '1' MINUTE
            AND FinishHoure - INTERVAL '1' MINUTE
        AND p_FinishHoure NOT BETWEEN StartHoure - INTERVAL '1' MINUTE
            AND FinishHoure - INTERVAL '1' MINUTE
        OR StartHoure > p_StartHoure
        AND FinishHoure < p_FinishHoure
    );

  IF v_cnt > 0 THEN
    -- your code here
  END IF;
END;

当然,这只是一个例子。我假设@pClassID和其他都是变量。在您的程序中尝试这种方法。

于 2013-11-04T12:01:13.240 回答