【问题标题】:PL/SQL cursor returning duplicatesPL/SQL 游标返回重复项
【发布时间】:2019-05-03 12:55:31
【问题描述】:

我的光标每行返回两次,我不知道如何停止。任何人都可以帮忙吗?非常感谢。

Create or replace PROCEDURE p_event_loc (Passed_variable in varchar) 
IS
  Cursor c1 is 
    select en, ln, pn
      from Et, Rn, Ln2, Pt
      where Rn.status = 1
        and Pt.pid = Rn.pid
        and Et.eid = Rn.eid
        and Ln2.lid = Et.lid;
  E_en Et.en%type;
  L_ln Ln2.ln%type;
  P_pn Pt.pn%type;
BEGIN
  Open c1;
  Loop
    fetch c1 into E_en, L_ln, P_pn;
    exit when c1%notfound; 
    dbms_output.put_line(Passed_variable|| ' is registered for ' || E_en 
      || ' at ' || L_ln);
  End loop;
  Close c1;
END;

【问题讨论】:

  • 查询(您在游标声明中使用)在单独运行时是否也返回重复项?如果是这样,请修复 WHERE 子句(如果可能)或 - 按照用户something 在他们的回答中的建议 - 将 DISTINCT 应​​用于 tle 列列表。
  • 请编辑您的问题并提供证明问题的测试数据。谢谢。

标签: oracle plsql cursors


【解决方案1】:

要删除重复词,请在选择后使用 distinct 关键字:

 select distinct en, ln, pn

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 2014-05-14
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 2021-01-21
    相关资源
    最近更新 更多