【问题标题】:Adjusting the format of PL/SQL output调整 PL/SQL 输出的格式
【发布时间】:2016-03-19 00:20:31
【问题描述】:
FOR rec_c IN cus_cur LOOP
 DBMS_OUTPUT.PUT_LINE(TO_CHAR(rec_c.CNO)||'  '||rec_c.person.name||'   '||rec_c.person.address.street||'   '||TO_CHAR(rec_c.person.address.zip));
FOR i IN 1..rec_c.person.phones.count loop
DBMS_OUTPUT.put_LINE(rec_c.person.phones(i));
END LOOP;
END LOOP;

下图是代码的输出:

如何管理如下图所示的输出?

【问题讨论】:

  • 您不必费心将图像中的文本复制到帖子中,以便人们利用空闲时间回答您的问题。你在扯我的链子
  • 使用DBMS_OUTPUT.PUT()(而不是DBMS_OUTPUT.PUT_LINE()),如果你把它和RPAD( value, width, ' ' )结合起来,那么你应该得到你的答案。

标签: oracle plsql sqlplus


【解决方案1】:

类似:

FOR rec_c IN cus_cur LOOP
  DBMS_OUTPUT.PUT( RPAD( rec_c.CNO,                    6, ' ' ) );
  DBMS_OUTPUT.PUT( RPAD( rec_c.person.name,           11, ' ' ) );
  DBMS_OUTPUT.PUT( RPAD( rec_c.person.address.street, 14, ' ' ) );
  DBMS_OUTPUT.PUT( RPAD( rec_c.person.address.zip,     7, ' ' ) );

  IF rec_c.person.phones IS NOT EMPTY THEN
    DBMS_OUTPUT.PUT_LINE(rec_c.person.phones(1));
    FOR i IN 2..rec_c.person.phones.count LOOP
      DBMS_OUTPUT.PUT_LINE( RPAD( ' ', 38, ' ' ) );
      DBMS_OUTPUT.PUT_LINE(rec_c.person.phones(i));
    END LOOP;
  ELSE
    DBMS_OUTPUT.PUT_LINE( NULL );
  END IF;
END LOOP;

【讨论】:

    【解决方案2】:

    在 sqlplus 中执行上述块之前,只需将 linesize 设置为 200 或更大,例如:

    set linesize 200;
    set serveroutput on;
    Begin
      -- Your code
    End;
    /
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 2019-09-16
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 2014-04-09
      • 2015-02-24
      相关资源
      最近更新 更多