Home » SQL & PL/SQL » SQL & PL/SQL » DBMS_OUTPUT.GET_LINES Usage
DBMS_OUTPUT.GET_LINES Usage [message #38927] Tue, 28 May 2002 12:21 Go to next message
Mohammad Syed
Messages: 18
Registered: November 2000
Junior Member
I cant seem to get the GET_LINES procedure to work. I found that there arent any examples of using this procedure anywhere. If anyone can tell me why the following block returns an error, I would greatly appreciate it. Thanks in advance.

DECLARE

TYPE t_txt IS TABLE OF VARCHAR2(255);
txtArray t_txt := t_txt() ;

numLines INTEGER := 2 ;

BEGIN

DBMS_OUTPUT.ENABLE(90000);
DBMS_OUTPUT.PUT_LINE('A');
DBMS_OUTPUT.PUT_LINE('kshdjshkjhds');


DBMS_OUTPUT.GET_LINES(txtArray,numLines);

END;
/
Re: DBMS_OUTPUT.GET_LINES Usage [message #38940 is a reply to message #38927] Wed, 29 May 2002 10:46 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
It is a tricky thing to get to work. Getting a sample working and being able to rely on it in a production environment is tricky. See if this helps.

CREATE TABLE DEBUG_SQL (seq number, timestamp date, comments varchar2(200));

CREATE OR REPLACE PROCEDURE put_debug_sql (i_seq IN INTEGER, i_msg VARCHAR)
IS
   PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   INSERT INTO debug_sql VALUES (i_seq, SYSDATE, i_msg);
   COMMIT;
END;
/

----------------------------------------------------------------
DELETE debug_sql;

SET serveroutput off;
SET feedback on

BEGIN
   DBMS_OUTPUT.enable;
   DBMS_OUTPUT.put_line ('hello world');
   DBMS_OUTPUT.put ('HELLO ');
   DBMS_OUTPUT.put_line ('USA');
END;
/

DECLARE
   v_line     VARCHAR2 (200);
   v_status   NUMBER;
   n          NUMBER         := 1;
BEGIN
   LOOP
      DBMS_OUTPUT.get_line (v_line, v_status);

      IF v_status = 0
      THEN
         put_debug_sql (n, v_line);
         n := n + 1;
      ELSE
         EXIT;
      END IF;
   END LOOP;
END;
/

BEGIN
   DBMS_OUTPUT.disable;
END;
/

COLUMN Comments format a30;
SELECT * FROM debug_sql ORDER BY seq;

Re: DBMS_OUTPUT.GET_LINES Usage [message #38943 is a reply to message #38927] Wed, 29 May 2002 15:57 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
The trick here is to define the pl/sql table based on the datatype from the dbms_output package.

sql>set serveroutput on
sql>declare 
  2    txtArray  dbms_output.chararr;
  3    numLines  integer := 2 ;
  4  begin
  5    dbms_output.put_line('First line');
  6    dbms_output.put_line('Second line');
  7    dbms_output.get_lines(txtarray, numlines);
  8    for i in 1..txtarray.count loop
  9      dbms_output.put_line( 'From get_lines: ' || txtarray(i) );
 10    end loop;
 11  end;
 12  /
From get_lines: First line
From get_lines: Second line
 
PL/SQL procedure successfully completed.
Re: DBMS_OUTPUT.GET_LINES Usage [message #38952 is a reply to message #38943] Thu, 30 May 2002 12:13 Go to previous message
Mohammad Syed
Messages: 18
Registered: November 2000
Junior Member
Todd. WHat can I say? Your a saint !!! Thanks for the help. I noticed that PUT_LINE won't flush the buffer if a GET_LINES call is contained within the same block, which is evident in lines 5 and 6 of your sample script. This was very herlpful indeed. Thanks again.
Previous Topic: how to drop all objects in one statement in a user
Next Topic: Triggers
Goto Forum:
  


Current Time: Tue May 21 18:32:22 CDT 2024