【问题标题】:comparing cursor values for equality in plsql在plsql中比较游标值是否相等
【发布时间】:2012-11-05 02:02:30
【问题描述】:
declare
  course_id char(10);
  course_idA char(10);

cursor task3 
  is
      select c_id from certificationrequirement
      where pcp_id = 101;

cursor task3A
  is 
      select o.c_id from courseoffering o
      join co_enrolment ce
      on o.co_id = ce.co_id
      where ce.s_regno = 401 and ce.coe_completionstatus = 'P';

Begin
  open task3;

    DBMS_OUTPUT.PUT_LINE ( 'List of Course to take ');
    loop

      FETCH task3 into course_id;
      exit when task3%NOTFOUND;

      DBMS_OUTPUT.PUT_LINE ( course_id);

    end loop;
  close task3;

  open task3A;

    DBMS_OUTPUT.PUT_LINE ( 'List of Courses student has passed ');

    loop

      FETCH task3A into course_idA;
      exit when task3A%NOTFOUND;

      DBMS_OUTPUT.PUT_LINE (course_idA);

    end loop;
  close task3A;

  if (cursor task3 = cursor task3A )
  Then
    DBMS_OUTPUT.PUT_LINE ( 'Student can attempt the Certification exam ');
  Else
    DBMS_OUTPUT.PUT_LINE ( 'Student cannot attempt the Certification exam ');
  END if;
end;

我正在使用一个光标列出学生需要为特定学位学习的所有课程。 第二个光标列出学生已经通过了多少门课程以获得他正在学习的学位。 如果两个光标中的两个值相等,他将有资格参加退出考试,否则他将无法参加。我已经写下了比较代码,但我认为上面的方法不是正确的。

【问题讨论】:

  • 想法是比较两个值是否相等对吗?那为什么要使用select语句而不使用游标呢?

标签: sql plsql cursor


【解决方案1】:
if (task3%rowcount = task3A%rowcount  )
              Then
              DBMS_OUTPUT.PUT_LINE ( 'Student can attempt the Certification exam ');
              Else
              DBMS_OUTPUT.PUT_LINE ( 'Student cannot attempt the Certification exam ');
              END if;

我找到了我的问题的答案,它对我来说非常有效:))

【讨论】:

    猜你喜欢
    • 2014-09-29
    • 2012-02-16
    • 2016-10-20
    • 2015-03-13
    • 2015-09-16
    • 1970-01-01
    • 2012-10-03
    • 2013-08-18
    相关资源
    最近更新 更多