Output employee name with pl/sql, cursor and dbms_output.put_line : DBMS_OUTPUT « System Packages « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> CREATE TABLE EMP(
  2      EMPNO NUMBER(4) NOT NULL,
  3      ENAME VARCHAR2(10),
  4      JOB VARCHAR2(9),
  5      MGR NUMBER(4),
  6      HIREDATE DATE,
  7      SAL NUMBER(7, 2),
  8      COMM NUMBER(7, 2),
  9      DEPTNO NUMBER(2)
 10  );

Table created.

SQL> INSERT INTO EMP VALUES(2, 'Jack', 'Tester', 6,TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30);

1 row created.

SQL> INSERT INTO EMP VALUES(3, 'Wil', 'Tester', 6,TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);

1 row created.

SQL> INSERT INTO EMP VALUES(4, 'Jane', 'Designer', 9,TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);

1 row created.

SQL> INSERT INTO EMP VALUES(5, 'Mary', 'Tester', 6,TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);

1 row created.

SQL> INSERT INTO EMP VALUES(7, 'Chris', 'Designer', 9,TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);

1 row created.

SQL> INSERT INTO EMP VALUES(8, 'Smart', 'Helper', 4,TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);

1 row created.

SQL> INSERT INTO EMP VALUES(9, 'Peter', 'Manager', NULL,TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);

1 row created.

SQL> INSERT INTO EMP VALUES(10, 'Take', 'Tester', 6,TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500, 0, 30);

1 row created.


SQL> INSERT INTO EMP VALUES(13, 'Fake', 'Helper', 4,TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20);

1 row created.

SQL>
SQL> begin
  2   for i in ( select ename from emp ) loop
  3       dbms_output.put_line(i.ename);
  4   end loop;
  5  end;
  6  /
Jack
Wil
Jane
Mary
Chris
Smart
Peter
Take
Fake

PL/SQL procedure successfully completed.

SQL>
SQL> drop table emp;

Table dropped.








31.17.DBMS_OUTPUT
31.17.1.DBMS_OUTPUT.CHARARR
31.17.2.q for quotation with []
31.17.3.Output character or line
31.17.4.Output varchar variable
31.17.5.EXECUTE DBMS_OUTPUT.ENABLE(10000)
31.17.6.Use DBMS_OUTPUT.PUT_LINE to output clob data
31.17.7.Use DBMS_OUTPUT.PUT_LINE to output the table collection indexed by BINARY_INTEGER
31.17.8.Call substr in DBMS_OUTPUT.PUT_LINE
31.17.9.Output Visual line break
31.17.10.dbms_output.new_line
31.17.11.Output employee name with pl/sql, cursor and dbms_output.put_line