调整PL / SQL输出的格式

时间:2016-03-19 00:20:32

标签: oracle plsql sqlplus

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;

下图是代码的输出:

enter image description here

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

enter image description here

2 个答案:

答案 0 :(得分:0)

类似的东西:

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;

答案 1 :(得分:0)

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

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