Use RPAD to format cursor variable : RPAD « Character String Functions « Oracle PL/SQL Tutorial






SQL> create table product(
  2     product_id number(4)     not null,
  3     product_description varchar2(20) not null
  4  );

Table created.

SQL>
SQL> insert into product values (1,'Java');

1 row created.

SQL> insert into product values (2,'Oracle');

1 row created.

SQL> insert into product values (3,'C#');

1 row created.

SQL> insert into product values (4,'Javascript');

1 row created.

SQL> insert into product values (5,'Python');

1 row created.

SQL>
SQL>
SQL> DECLARE
  2    TYPE rc is REF CURSOR;
  3    refCursorValue rc;
  4    myRecord product%ROWTYPE;
  5  BEGIN
  6    OPEN refCursorValue FOR SELECT * from product;
  7
  8    LOOP
  9      FETCH refCursorValue INTO myRecord;
 10      EXIT WHEN refCursorValue%NOTFOUND;
 11      dbms_output.put_line(to_char(myRecord.product_id)||' '||
 12      rpad(myRecord.product_description,20,' '));
 13
 14    END LOOP;
 15
 16    CLOSE refCursorValue;
 17  END;
 18  /
1 Java
2 Oracle
3 C#
4 Javascript
5 Python

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> drop table product;

Table dropped.








11.12.RPAD
11.12.1.Rpad
11.12.2.RPAD(x, width [, pad_string]) pads x with spaces to right to bring the total length of the string up to width characters
11.12.3.RPAD() with number column
11.12.4.Call RPAD function in PL/SQL
11.12.5.Right padding the name of department
11.12.6.Use both lpad() and rpad() to create a string
11.12.7.Use RPAD to format cursor variable
11.12.8.Use rpad to represent the level
11.12.9.Use rpad function with define column default value
11.12.10.Use rpad to format a report