【问题标题】:pl/sql ,oracle add heading in cursorpl/sql ,oracle 在游标中添加标题
【发布时间】:2022-11-28 01:01:29
【问题描述】:

我如何在我的代码中为顶部显示的表格添加标题,如下图所示:

enter image description here

declare 
E_Name employ.name%type; 
E_Salary employ.salary%type; 
CURSOR c_employees is 
SELECT name , salary  from employ order by salary desc; 
BEGIN 
OPEN c_employees; 
LOOP 
FETCH c_employees into E_Name,E_Salary ; 
EXIT WHEN c_employees%notfound;
dbms_output.put_line( rpad(E_Name, 20, '.') || ' ' || rpad('$', (E_Salary/100), '$')||'      '||E_Salary); 
END LOOP; 
CLOSE c_employees;
END; 
/

【问题讨论】:

    标签: sql oracle plsql sqlplus


    【解决方案1】:

    包括另外两个 DBMS_OUTPUT.PUT_LINEs,它们将显示该标题(第 2 行和第 3 行)。

    例如(使用我的表,因为我没有你的):

    SQL> begin
      2    dbms_output.put_line('Emloyee name    Salary');
      3    dbms_output.put_line('------------    ------');
      4
      5    for cur_r in (select ename, sal from emp where deptno = 10) loop
      6      dbms_output.put_line(rpad(cur_r.ename, 12, ' ') ||'    '||
      7                           to_char(cur_r.sal, '99990'));
      8    end loop;
      9  end;
     10  /
    Emloyee name    Salary
    ------------    ------
    CLARK             2450
    KING              5000
    MILLER            1300
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2023-04-06
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多