scribes
i would like to write /export the results of a query to a text file
logic
1)execute query and
2) export to a text file
21 14163
Try using the SPOOL command.
Try something like this: -
-
SQL> SET FEEDBACK OFF
-
SQL> SET VERIFY OFF
-
SQL> SET TERMOUT OFF
-
SQL> SET HEADING OFF
-
SQL> SPOOL C:/data.txt
-
SQL> SELECT * FROM emp;
-
SQL> SPOOL OFF
-
-
Now view your data file in C:\ Drive
-
CREATE OR REPLACE DIRECTORY LOGG_DIR AS 'C:\TEST'
-
DECLARE
-
fileID UTL_FILE.FILE_TYPE;
-
LINE_BUFF VARCHAR2(1000);
-
BEGIN
-
fileID := UTL_FILE.FOPEN (LOGG_DIR, 'emp.dat', 'W');
-
FOR emprec IN (SELECT * FROM SO_SERVICES)
-
LOOP
-
LINE_BUFF :=TO_CHAR (emprec.ACCT_NO) ;
-
UTL_FILE.PUT_LINE ( FILEID ,LINE_BUFF);
-
END LOOP;
-
UTL_FILE.FCLOSE (fileID);
-
END;
-
-
/
-
ARE
R at line 2:
00901: invalid CREATE command
hi am using code like ths and get the error at the bottom -
-
CREATE OR REPLACE DIRECTORY LOGG_DIR AS 'C:\TEST'
-
DECLARE
-
fileID UTL_FILE.FILE_TYPE;
-
LINE_BUFF VARCHAR2(1000);
-
BEGIN
-
fileID := UTL_FILE.FOPEN (LOGG_DIR, 'emp.dat', 'W');
-
FOR emprec IN (SELECT * FROM SO_SERVICES)
-
LOOP
-
LINE_BUFF :=TO_CHAR (emprec.ACCT_NO) ;
-
UTL_FILE.PUT_LINE ( FILEID ,LINE_BUFF);
-
END LOOP;
-
UTL_FILE.FCLOSE (fileID);
-
END;
-
-
/
-
ARE
R at line 2:
00901: invalid CREATE command Please enclose your source code in [code] tags for better readability
Try something like this: -
-
SQL> CREATE OR REPLACE DIRECTORY LOGG_DIR AS 'C:\TEST';
-
-
SQL>DECLARE
-
fileID UTL_FILE.FILE_TYPE;
-
LINE_BUFF VARCHAR2(1000);
-
BEGIN
-
fileID := UTL_FILE.FOPEN (LOGG_DIR, 'emp.dat', 'W');
-
FOR emprec IN (SELECT * FROM SO_SERVICES)
-
LOOP
-
LINE_BUFF :=TO_CHAR (emprec.ACCT_NO) ;
-
UTL_FILE.PUT_LINE ( FILEID ,LINE_BUFF);
-
END LOOP;
-
UTL_FILE.FCLOSE (fileID);
-
END;
-
/
-
Duplicate Threads Merged for better management of the forum
MODERATOR
RAN IT AND THE ERRORS ARE AT BOTTOM -
-
1 DECLARE
-
2 fileID UTL_FILE.FILE_TYPE;
-
3 LINE_BUFF VARCHAR2(1000);
-
4 BEGIN
-
5 fileID := UTL_FILE.FOPEN ('C:\TEST', 'emp.dat
-
6 FOR emprec IN (SELECT * FROM SO_SERVICES)
-
7 LOOP
-
8 LINE_BUFF :=TO_CHAR (emprec.ACCT_NO) ;
-
9 UTL_FILE.PUT_LINE ( FILEID ,LINE_BUFF);
-
10 END LOOP;
-
11 UTL_FILE.FCLOSE (fileID);
-
12* END;
-
SQL> /
-
DECLARE
-
*
-
ERROR at line 1:
-
ORA-06510: PL/SQL: unhandled user-defined exception
-
ORA-06512: at "SYS.UTL_FILE", line 120
-
ORA-06512: at "SYS.UTL_FILE", line 204
-
ORA-06512: at line 5
-
-
Try This: -
-
DECLARE
-
fileID UTL_FILE.FILE_TYPE;
-
LINE_BUFF VARCHAR2(1000);
-
BEGIN
-
fileID := UTL_FILE.FOPEN ('C:\TEST', 'emp.dat
-
FOR emprec IN (SELECT * FROM SO_SERVICES)
-
LOOP
-
LINE_BUFF :=TO_CHAR (emprec.ACCT_NO) ;
-
UTL_FILE.PUT_LINE ( FILEID ,LINE_BUFF);
-
END LOOP;
-
UTL_FILE.FCLOSE (fileID);
-
EXCEPTION
-
WHEN OTHERS THEN
-
DBMS_OUTPUT.PUT_LINE('Errrrrrrr');
-
END;
-
-
get :PL/SQL procedure successfully completed but the data aint there in the specified file.
get :PL/SQL procedure successfully completed but the data aint there in the specified file.
Do this and let me know does it print 'Errrrrr':
THen run that piece of code
Do this and let me know does it print 'Errrrrr':
THen run that piece of code
Do the following: -
-
SQL> CREATE OR REPLACE DIRECTORY LOGG_DIR AS 'C:\TEST';
-
-
SQL> GRANT READ,WRITE ON DIRECTORY LOGG_DIR TO PUBLIC;
-
-
SQL> SET SERVEROUTPUT ON
-
-
SQL> <The piece of Code that I have given in my previous Post>
-
-
Post back what happens when you do these steps?
Did As U Said And Printed Errrrrrrrrrr
Can U Get A Dummy One Working For Me Man Am In Need
To get the exact error message, please run this code and post back the error message for reference -
-
DECLARE
-
fileID UTL_FILE.FILE_TYPE;
-
LINE_BUFF VARCHAR2(1000);
-
BEGIN
-
fileID := UTL_FILE.FOPEN ('C:\TEST', 'emp.dat
-
FOR emprec IN (SELECT * FROM SO_SERVICES)
-
LOOP
-
LINE_BUFF :=TO_CHAR (emprec.ACCT_NO) ;
-
UTL_FILE.PUT_LINE ( FILEID ,LINE_BUFF);
-
END LOOP;
-
UTL_FILE.FCLOSE (fileID);
-
EXCEPTION
-
WHEN OTHERS THEN
-
DBMS_OUTPUT.PUT_LINE(SQLCODE||','||SQLERRM);
-
END;
-
-
You can search in this forum by typing in the keyword utl_file in the SEARCH box at the top right corner of the forum windowto get some sample codes.
But you run the code that I have provided you in my previous post to check what could be the exact error and post back the error for reference.
HI RAN THE CODE AND THIS IS THE ERROR;;;
1,User-Defined Exception
HI WAS DOING SOME REDING AND CAME ACROOS::::
Here's the format of the parameter for file access in the INIT.ORA file:
utl_file_dir = <directory>
PROBLEM IS WHERE DO I DECLARE THIS IN MY CODE
scribes
am trying to use utl_file and need to declare the directory in init.ora and i went to the oracle registry folder and i cant seem to find it....help please
HI WAS DOING SOME REDING AND CAME ACROOS::::
Here's the format of the parameter for file access in the INIT.ORA file:
utl_file_dir = <directory>
PROBLEM IS WHERE DO I DECLARE THIS IN MY CODE
If you want to change the value of utl_file_dir, then you need to change that init.ora file and bounce the database server to take in to effect the modified value
scribes
am trying to use utl_file and need to declare the directory in init.ora and i went to the oracle registry folder and i cant seem to find it....help please
You need to assign the directory value to utl_file_dir parameter in init.ora file. The init .ora file is present in ORACLE_HOME/dbs path. Check for INIT.ORA File, assign the directory value to the utl_file_dir parameter and bounce the DB server. You can ask your DBA to do this for you.
Duplicate Threads merged for better management of forum
MODERATOR
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Igor Shulgin |
last post by:
Hi!
What is standard and direct way (within Oracle 9.2 stored procedures)
for
writing binary data from Oracle to external file on disk?
We have...
|
by: Siddhant Kumar |
last post by:
I want to write a Text file containing data (either , or Tab
delimited) using stored procedure. can any one guide me how to do
this.? or point to a...
|
by: Leo Martin Orfei |
last post by:
Hi,
Anybody know/have functions or package to create text
file from postgres function?
I want to execute a function to take some fields from...
|
by: tim |
last post by:
Someone using Python Midi Package from
http://www.mxm.dk/products/public/ lately?
I want to do the following :
write some note events in a midi...
|
by: dkarthick |
last post by:
How to execute UTL_FILE Package in plsql?
|
by: anithas |
last post by:
I need to write the o/p from an Oracle Pl/SQL to a txt file.
I tried the following , but i get an error
declare
f utl_file.file_type;
s...
|
by: djramesh04 |
last post by:
ORA-29280: invalid directory path
ORA-06512: at "SYS.UTL_FILE", line 33
ORA-06512: at "SYS.UTL_FILE", line 436
ORA-06512: at...
|
by: murthydb2 |
last post by:
Hi
My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or...
|
by: narendrareddy |
last post by:
Hi ,
assume a flat file name emp.txt contains the following data
10000100001 narendranathreddy tallapireddy 01-01-2007 male
10000100002...
|
by: tammygombez |
last post by:
Hey everyone!
I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: CD Tom |
last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |