Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print out the whole table using anonymous block in pl sql?

Tags:

sql

oracle

plsql

I want to use DBMS_OUTPUT.PUT_LINE, but the number of rows exceeds just 1. There is nothing in the table which increments sequentially, so I can't use a loop. Is there some way to print out each row in the table?

like image 964
n0ob Avatar asked Feb 27 '10 17:02

n0ob


People also ask

How can I see the output of a PL SQL block?

To do this we use a procedure called dbms_output. put_line to place the results in a buffer that SQL*Plus will retrieve and display. SQL*Plus must be told to retrieve data from this buffer in order to display the results. The SQL*Plus command 'set serveroutput on' causes SQL*Plus to retrieve and display the buffer.

How do I run an anonymous block in PL SQL?

Execute a PL/SQL anonymous block using SQL*Plus Second, turn on the server output using the SET SERVEROUTPUT ON command so that the DBMS_OUTPUT. PUT_LINE procedure will display text on the screen. Third, type the code of the block and enter a forward slash ( / ) to instruct SQL*Plus to execute the block.


1 Answers

try with something like this.

SET SERVEROUTPUT ON
     BEGIN
          -- A PL/SQL cursor
          FOR cursor1 IN (SELECT * FROM table1) 
          LOOP
            DBMS_OUTPUT.PUT_LINE('Column 1 = ' || cursor1.column1 ||
                               ', Column 2 = ' || cursor1.column2);
          END LOOP;
     END;
        /
like image 157
Jonathan Avatar answered Nov 15 '22 22:11

Jonathan