Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Vladimir .

Asked: October 18, 2016 - 12:48 am UTC

Last updated: October 19, 2016 - 12:50 am UTC

Version: 11g

Viewed 10K+ times! This question is

You Asked

Hello Tom, First thanks for helping me out.

Few days ago you explained how to insert dbms_output into temporary tables or nested table. This was the example:

This example works perfectly if I have write permission in the database, Is there a way I can do something similar without writting in the database (I only have read access). I need to use the output to create some reports and dbms_output does not allow me to use that output. I have tried UTL_File but I do not have access to the server neither. I don't know what else I can do. Thank you again.

SQL> create or replace type dbms_output_obj as object ( machine varchar2(20), diff_time date );
  2  /
Type created.

SQL>
SQL> create or replace type dbms_output_list as table of dbms_output_obj;
  2  /

Type created.

SQL> set serverout on
SQL> declare
  2    t dbms_output_list := dbms_output_list();
  3  begin
  4    t.extend;
  5    t(1) := dbms_output_obj('Machine 1',sysdate);
  6
  7    t.extend;
  8    t(2) := dbms_output_obj('Machine 2',sysdate);
  9
 10    t.extend;
 11    t(3) := dbms_output_obj('Machine 3',sysdate);
 12
 13
 14    for i in ( select * from table(t))
 15    loop
 16      dbms_output.put_line(i.machine);
 17      dbms_output.put_line(i.diff_time);
 18    end loop;
 19  end;
 20  /
Machine 1
05-OCT-16
Machine 2
05-OCT-16
Machine 3
05-OCT-16

and Connor said...

If you want to *query* data, you need a place to store it.

If you cannot have a place to store it on your current database, you need another place.

You could create a local database, and then copy the output using dbms_output.get_line across a database link. eg

--
-- database 'db1'
--
SQL> create or replace
  2  procedure P is
  3  begin
  4    dbms_output.put_line('line1');
  5    dbms_output.put_line('line2');
  6    dbms_output.put_line('line3');
  7  end;
  8  /

Procedure created.
--
-- local database
--
SQL> create table t ( v varchar2(100));

Table created.

SQL>
SQL> declare
  2    x varchar2(1000);
  3    status int;
  4  begin
  5    dbms_output.enable@db1;
  6    p@np12;
  7    loop
  8      dbms_output.get_line@db1( x,status);
  9      exit when status != 0;
 10      insert into t values ( x ) ;
 11    end loop;
 12  end;
 13  /

PL/SQL procedure successfully completed.

SQL>
SQL> select * from t;

V
------------------------------------------------
line1
line2
line3


But I cannot begin to tell you what a silly idea this is :-)

It is a massive over complication of an issue which seems to be to about getting the appropriate privileges.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

is there something else I could do?

vladimir, October 18, 2016 - 4:01 am UTC

Thank you, it is another great idea, but I don't have the privileges for creating all of that (db link, sp, local table). Is there something else I could do only with read access. Thank you, and sorry if its a silly question. thanks
Connor McDonald
October 19, 2016 - 12:50 am UTC

get the appropriate privileges...


simple
as
that

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library