Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 7th, 2003, 06:51 AM
etca2720 etca2720 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Charleroi, Belgique
Posts: 18 etca2720 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question PL/SQL problem

I would like to read a table and save the results (bold) in a text file.


**** Here's my actual PL/SQL code :
CREATE OR REPLACE procedure generate_ldif
IS
cursor user_nt is
select usr_nt from ntusr where ...;
var_usr_nt ntusr.USR_NT%type;
begin
open user_nt;
loop
fetch user_nt into var_usr_nt,var_adr_lot;
exit when user_nt%NOTFOUND;

dbms_output.put_line('Username:'||trim(var_usr_nt));
dbms_output.put_line('...');
dbms_output.put_line('...');

end loop;
close user_nt;
end;
--------------------------------------------------------------------------------
**** Here's my SQL code who executes this PL/SQL code:
set feedback OFF
set pagesize 0
set linesize 200
set serveroutput ON;
SPOOL genLDIF.tmp
execute generate_ldif;
spool off;
exit
--------------------------------------------------------------------------------
**** Here's my batch file whoe executes the SQL :
sqlplus.exe usr/pwd@inst @Generate_LDIF.sql
--------------------------------------------------------------------------------
**** This error appears :
*
ERROR at line 1:
ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes
ORA-06512: at "SYS.DBMS_OUTPUT", line 106
ORA-06512: at "SYS.DBMS_OUTPUT", line 65
ORA-06512: at "GESPER.GENERATE_LDIF", line 22
ORA-06512: at line 1
--------------------------------------------------------------------------------

-->
I would like to see the results in a text file (genLDIF.tmp), another way to proceed ?

Last edited by etca2720 : July 7th, 2003 at 06:54 AM.

Reply With Quote
  #2  
Old July 7th, 2003, 06:56 AM
omiossec omiossec is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Paris, France
Posts: 375 omiossec User rank is Lance Corporal (50 - 100 Reputation Level)omiossec User rank is Lance Corporal (50 - 100 Reputation Level)omiossec User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 16 h 4 m 46 sec
Reputation Power: 6
Send a message via ICQ to omiossec Send a message via AIM to omiossec
I don't think that is a MySql problem, this is an oracle probleme
__________________
Olivier Miossec
http://www.lasso-developpeur.net

Reply With Quote
  #3  
Old July 7th, 2003, 06:57 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Moving....

Reply With Quote
  #4  
Old July 7th, 2003, 08:13 AM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
use the pl/sql spool command.
spool genLDIF.tmp
.....
spool off
also you will need to sert your serveroutp size higher.
SET serveroutput ON SIZE 1000000

If you are working on the server itself you can also use the oracle utl_file package.

Reply With Quote
  #5  
Old July 7th, 2003, 08:26 AM
etca2720 etca2720 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Charleroi, Belgique
Posts: 18 etca2720 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks!
This command solves my problem :
set serveroutput ON SIZE 1000000;

Reply With Quote
  #6  
Old July 7th, 2003, 08:50 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 21 h 22 m 10 sec
Reputation Power: 19
You also may want to look at the utl_file Oracle supplied package that allows you to write files.

Reply With Quote
  #7  
Old July 7th, 2003, 08:56 AM
etca2720 etca2720 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Charleroi, Belgique
Posts: 18 etca2720 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool

UTL_FILE create file on the server, not in the client folder...

And how can i write a blank line in the output buffer ?
---------------------------------------------------------
My code :

dbms_output.put_line('a');
dbms_output.put_line('b');
dbms_output.put_line(' ');
dbms_output.put_line('c');

-----------------------------------------------------
I would like to insert a blank line between 'b' and 'c' line (without using ASCII chr(10)&&chr(13) ...


Last edited by etca2720 : July 7th, 2003 at 08:58 AM.

Reply With Quote
  #8  
Old July 7th, 2003, 07:05 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Did dbms_output.put_line(' '); not work for you?

Reply With Quote
  #9  
Old July 8th, 2003, 01:43 AM
etca2720 etca2720 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Charleroi, Belgique
Posts: 18 etca2720 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
dbms_output.put_line(' '); does not work ...

Reply With Quote
  #10  
Old July 8th, 2003, 01:15 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Are you using spool filename.txt to write to a spool file?

Reply With Quote
  #11  
Old July 9th, 2003, 01:38 AM
etca2720 etca2720 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Charleroi, Belgique
Posts: 18 etca2720 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
as said in the beginning of this document :-p
**** Here's my SQL code who executes this PL/SQL code:
set feedback OFF
set pagesize 0
set linesize 200
set serveroutput ON;
SPOOL genLDIF.tmp
execute generate_ldif;
spool off;
exit

Reply With Quote
  #12  
Old July 9th, 2003, 04:13 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,686 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 16 h 27 m 51 sec
Reputation Power: 259
I don't get the point, you are executing a procedure from sql+ and spooling output on a file, right? But in this case a simple select, with formatting instruction is enough, the procedure (IMHO) would be better if used to save the file somewhere, passing path as a parameter.
Like this one I got on a forum:
Quote:
yd@yddb.ora8i.mu> create or replace procedure dump_table_to_csv( p_tname in varchar2,
2 p_dir in varchar2,
3 p_filename in varchar2 )
4 is
5 l_output utl_file.file_type;
6 l_theCursor integer default dbms_sql.open_cursor;
7 l_columnValue varchar2(4000);
8 l_status integer;
9 l_query varchar2(1000)
10 default 'select * from ' || p_tname;
11 l_colCnt number := 0;
12 l_separator varchar2(1);
13 l_descTbl dbms_sql.desc_tab;
14 begin
15 l_output := utl_file.fopen( p_dir, p_filename, 'w' );
16 execute immediate 'alter session set nls_date_format=''dd-mon-yyyy hh24:mi:ss'' ';
17
18 dbms_sql.parse( l_theCursor, l_query, dbms_sql.native );
19 dbms_sql.describe_columns( l_theCursor, l_colCnt, l_descTbl );
20
21 for i in 1 .. l_colCnt loop
22 utl_file.put( l_output, l_separator || '"' || l_descTbl(i).col_name || '"' );
23 dbms_sql.define_column( l_theCursor, i, l_columnValue, 4000 );
24 l_separator := ',';
25 end loop;
26 utl_file.new_line( l_output );
27
28 l_status := dbms_sql.execute(l_theCursor);
29
30 while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
31 l_separator := '';
32 for i in 1 .. l_colCnt loop
33 dbms_sql.column_value( l_theCursor, i, l_columnValue );
34 utl_file.put( l_output, l_separator || l_columnValue );
35 l_separator := ',';
36 end loop;
37 utl_file.new_line( l_output );
38 end loop;
39 dbms_sql.close_cursor(l_theCursor);
40 utl_file.fclose( l_output );
41
42 execute immediate 'alter session set nls_date_format=''dd-MON-yy'' ';
43 exception
44 when others then
45 execute immediate 'alter session set nls_date_format=''dd-MON-yy''';
46 raise;
47 end;
48 /


Can also be easily scheduled as an DBMS_JOB

Last edited by pabloj : July 9th, 2003 at 04:16 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > PL/SQL problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |