【问题标题】:Why the output is printing twice while executing loop in plsql?为什么在plsql中执行循环时输出打印两次?
【发布时间】:2021-06-21 23:20:58
【问题描述】:
set serveroutput on;
Declare
    d_name varchar(25);
    cursor dep_cur is
    select distinct department_name from department;
BEGIN 
    dbms_output.put_line('Department Names are :');
    open dep_cur;
    
    LOOP
        fetch dep_cur
            into d_name;
              
        exit when dep_cur%notfound;    
        dbms_output.put_line(d_name);  
    END LOOP;
    close dep_cur;
END;
/

输出:

Department Names are :                                                          
ADMIN                                                                           
TESTING                                                                         
DEVELOPMENT                                                                     
Department Names are :                                                          
ADMIN                                                                           
TESTING                                                                         
DEVELOPMENT                                                                     

预期输出:

Department Names are :     
ADMIN
DEVELOPMENT

【问题讨论】:

标签: plsql plsqldeveloper plsql-package


【解决方案1】:

这是因为您有一个匿名的 BEGIN-END 块,末尾带有分号和正斜杠。在这种情况下,斜杠再次执行代码块。

有用的资源:

【讨论】:

  • 它在删除斜线后工作,但删除分号并仅使用斜线会出错
  • 好的,谢谢。通过删除那句话更新了我的答案:)
猜你喜欢
  • 2022-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-12
相关资源
最近更新 更多