- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to save the contents from PL/SQL into a te...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 11:16 AM
тАО12-10-2003 11:16 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 12:28 PM
тАО12-10-2003 12:28 PM
Re: How to save the contents from PL/SQL into a text file
1. If you are using dbms_output.put_line, then using the 'spool' command to output to a file might be the easiest.
2. Take a look at the UTL_FILE package. This allows you to open, read, write, and append to a file on the OS level. This might be an easier solution which would let you output the information directly to a file. It should be noted that this file will then be owned by the OS user that is running the database (most likely 'oracle' and not the user running the plsql code.
Thanks,
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 02:39 PM
тАО12-10-2003 02:39 PM
Re: How to save the contents from PL/SQL into a text file
SQL>select * from emp;
...
..
SQL>spool off
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 03:33 PM
тАО12-10-2003 03:33 PM
Re: How to save the contents from PL/SQL into a text file
If you are running your PL/SQL using sqlplus you can simply use: spool
Else, use UTL_FILE package inside your PL/SQL block
You need to check your database setting for that: your utl_file_dir in init.ora
or using SQLPLUS/SVRMGRL
show parameter utl_file_dir
Note that in 9i Release 2, UTL_FILE uses a "directory" object instead of the utl_file_dir init.ora parameter and these directory objects are created when needed, without touching the parameter files, without restarting.
If you need a small example, please let us know...
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 04:03 PM
тАО12-10-2003 04:03 PM
Re: How to save the contents from PL/SQL into a text file
set serveroutput on
declare
max_amnt float(8);
begin
select max(amnt) into max_amnt
from sales_history
where partno = '12345';
DBMS_OUTPUT.PUT_LINE ('The max amount is ' || amnt);
end;
The above pl/sql statement works fine and display 'The max amount is xxxx ' on screen.
If I try to use spool to put the output into a file, where should I put the spool and spool off ? or how can I use another way to do that ?
Thank you all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 04:05 PM
тАО12-10-2003 04:05 PM
Re: How to save the contents from PL/SQL into a text file
DBMS_OUTPUT.PUT_LINE ('The max amount is ' || max_amnt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 06:15 PM
тАО12-10-2003 06:15 PM
Re: How to save the contents from PL/SQL into a text file
the spool command is a SQLPLUS command! so you should put it outside the PLSQL block of statements.
thus,
spool myfile.txt;
set serveroutput on
declare
max_amnt float(8);
begin
select max(amnt) into max_amnt
from sales_history
where partno = '12345';
DBMS_OUTPUT.PUT_LINE ('The max amount is ' || max_amnt);
end;
spool off;
cheers
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2003 08:37 PM
тАО12-10-2003 08:37 PM
SolutionInstead, try:
set serveroutput on size 1000000 format wrap
spool myfile
declare
max_amnt float(8);
begin
select max(amnt) into max_amnt
from sales_history
where partno = '12345';
DBMS_OUTPUT.PUT_LINE ('The max amount is ' || max_amnt);
end;
/
spool off
This will create myfile.lst in the current directory. If it already existed it will have been overwritten.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 12:03 AM
тАО12-11-2003 12:03 AM
Re: How to save the contents from PL/SQL into a text file
You do need the / to execute the PL/SQL block.
As for your sqlplus environment, you may consider to default it (login.sql) as follows:
==========================================
column global_name new_value gname
set termout off
select lower(user)||'@'||global_name global_name from global_name;
set termout on
set sqlprompt '&gname> '
set timing on
set long 4000
set termout on
set underline '_'
set verify off
set feedback 5
set pagesize 500
set linesize 1000
set arraysize 11
set heading on
set serveroutput on size 1000000
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 01:50 AM
тАО12-11-2003 01:50 AM