SQL & PL/SQL :: File Spool Using UTL_FILE

Apr 27, 2012

How to spool the Japanese characters in table using UTL_FILE. I tried with utl_file.fopen it's general,it's spooling. but i am not sure it this right way or not. in this case we need to change any character.

We can't see this characters in TOAD. Only possible in PLSQL developer

create table test1(name varchar2(1000),fname varchar2(1000))

insert into test1 values ('名を入力してください。','姓を入力してください。')

commit;

View 6 Replies


ADVERTISEMENT

SQL & PL/SQL :: How To Handle A File With UTL_FILE

Mar 11, 2013

I Got a scnario like a upload file contains

1.Header(Contains the File Name,Branch Name,MIS date)
2.Body(Customer Details)
3.Footer (File Name,Contians Total Number of Records and Number of Customers)

Like

CustomerDet_11-12-2013.csv,Chennai,11-12-2013
101,AAA,Savings,'M',10000
102,BBB,Current,'O',2000
103,CCC,Deposit Acct,'F',3000
CustomerDet_11-12-2013.csv,3,15000

How to handle this scnario through UTL_File

View 31 Replies View Related

SQL & PL/SQL :: Updating A File With UTL_FILE

May 3, 2010

I have an application that creates files using the utl_file package. It works fine but one of the lines in the file should hold the number of bytes in the file (on a line formatted like 'FileSize: 2104'). Unfortunately this line is not the last line of the file and the lines that follow it are variable in length.

My approach therefore is as follows:
1. Write the 'FileSize: ' line during file creation.
2. Write the remaining lines of data to the file (but don't close it).
3. Use utl_fgetattr to find the file size.
4. Go back and find the 'FileSize' line I need to update, using get_line to read it into the buffer.
5. Append the filesize (plus the number of characters that the variable I use to store the filesize value) to the buffer string.
6. Write the line back to the file using put_line.

However I keep getting invalid file operation errors however I try to re-access the file...

PROCEDURE setUtlFileSize (pFileName IN VARCHAR2,
pFileHandle IN utl_file.file_type) IS
vbFileExists BOOLEAN;
viFileLen NUMBER;
viFileBlockSize NUMBER;
vsFileRecord VARCHAR2(2000);
[code].......

This gives me the following output.... (for two files)... currently I am using some generic exception handling just to show me the error.

File Length: 2106
File Position: 0
-29283,ORA-29283: invalid file operation
File Length: 497
File Position: 0
-29283,ORA-29283: invalid file operation
Process exited.

Two things here concern me: The File Position suggests that the current offset position is set to the start of the file... but since I had not closed or performed any other operation since the last put_line and fflush (which are used to add lines to the file) I had expected that the offset position would be the same as the file length?

Secondly: Even if the position had been reset to the start of the file I don't understand why the get_line gives me the oracle error.

View 1 Replies View Related

SQL & PL/SQL :: File Encoding UTL_FILE

Apr 21, 2011

I'm using

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

I'm creating a file using UTL_FILE.FOPEN and UTL_FILE.PUTF

But I don't know the file I created is in which encoding ASCII, UTF-8, EBCDIC etc.

1.) How can I create files in my desired encoding using UTL_FILE?
2.) Does UTL_FILE use database encoding? If yes then how to find out database encoding?
3.) Which encoding is used by UTL_FILE by default?

View 4 Replies View Related

To Use UTL_FILE Package To Create OS File

Apr 26, 2013

I want to use UTL_FILE package to create OS file. How to resolve this error. Oracle11g under XP.

SQL> create directory my_dir as 'c: emp';

Directory created.

1 create or replace procedure test_1(md in varchar2)
2 is
3 file utl_file.file_type;
4 begin
5 file := utl_file.fopen(md,'abc.log','w');
6 utl_file.put_line(file,'EMPLOYE REPORT');
7 utl_file.fclose(file);
8* end;
SQL> /

Procedure created.

SQL> execute test_1('MY_DIR');
BEGIN test_1('MY_DIR'); END;

RROR at line 1:
RA-06510: PL/SQL: unhandled user-defined exception
RA-06512: at "SYS.UTL_FILE", line 98
RA-06512: at "SYS.UTL_FILE", line 157
RA-06512: at "SCOTT.TEST_1", line 5
RA-06512: at line 1

View 2 Replies View Related

SQL & PL/SQL :: Read Excel File Using UTL_FILE Package

Jul 23, 2010

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
PL/SQL Release 11.1.0.6.0 - Production
"CORE 11.1.0.6.0 Production"

Is there a way to read Excel file using UTL_FILE package ?

Like our usual method:
l_utlfile := utl_file.fopen(p_dir, p_filename, 'R',2000);
p_filename is event.xls

Or do we need to convert that file to .csv or .txt ?

View 5 Replies View Related

SQL & PL/SQL :: UTL_FILE.PUT_LINE Is Not Writing Data To A File?

Jan 18, 2011

I want to extract data from a table and write into a txt file using UTL_FILE utility.I have written the below query. I am able to see query is returning data.But it is not creating file and writing data into it.

CREATE OR REPLACE DIRECTORY DOC_PATH AS '/apps/orarpt/SJDEV/utl'
CREATE OR REPLACE PROCEDURE xxcfi_outbound_test (errbuf OUT VARCHAR2,
retcode OUT VARCHAR2)
AS
CURSOR emp_cur

[code].....

View 1 Replies View Related

PL/SQL :: Spool File With CTE Query?

Jul 10, 2013

I am using something like below , the query runs fine in oracle SQL developer.But I would like to generate a text file by running the script, so I added the Spool command, and those settings,

  I tried to run it in SQL developer or SQLplus, they both fail.In SQL developer: I got: ORA-00933: SQL command not properly ended00933. 00000 -  "SQL command not properly ended"*Cause:    *Action:Error at Line: 16 Column: 1,542In SQLPlus, but I got an error: SP2-0734: unknown command beginning "CteRace As..." - rest of line ignored.it seems it doesn't understand the common expression table. -- SQL code below:set heading offset feedback offset newpage noneset echo offset termout

[code]...

View 3 Replies View Related

Create File With (other) User Having Read Permission When Using Utl_file?

Dec 23, 2012

We have a requirement to create a file using UTL_FILE package. so we tried to generate the file in directory at UNIX level,for example "/tmp" which means when we executing the stored procedure which in turn calls UTL_FILE package and create a file say "a.txt". On checking the permission for "a.txt", it shows as follows

-rw-r----- oracle dba a.txt

this means read and write for oracle user, read for dba group and no permission for other user.

our requirement is to have the following privileges at UNIX level.

-rw-r--r-- oracle dba a.txt

Is it possible to do at oracle level since the file is owned by oracle user or at UNIX level (with out logging to oracle user)?

Environment: UNIX AIX 6.1 and Oracle 11.2.0.3

View 3 Replies View Related

SQL & PL/SQL :: Loading Unique Text File Names With Utl_file

Oct 9, 2012

I am using an Oracle 8i database.We intend creating a dbms_job that would run every 5 minutes. The job executes a script that would use utl_file to read two text files (a header file and detail file) from a particular directory and load the data into temporary tables. The naming convention of the files are Parts_Master_DD/MM/YY HH:MI:SS and Parts_Stats_DD/MM/YY HH:MI:SS. Both files to be stored in the same directory.

If the file name was constant ie. Parts_Master, Parts_Stats I would not have a problem. However with each file name now going to be unique, how do I handle this using utl_file. To add to my dilemma, within an hour more than one set of files could be piped to the directory to be read into the database.

View 3 Replies View Related

Format Output File By Command Spool

Jan 20, 2011

I use sqplus in oracle to output the command output to text file .

I use below set environment variable.

SQL> set echo off;
SQL> set linesize 3999;
SQL> set feedback off;
SQL> set feedback off;
SQL> set termout off;
SQL> set pagesize 0;
SQL> spool mapping.txt
select C_SIM_MSISDN,C_SIM_IMSI from RCA_SMART_CARD order by C_SIM_MSISDN;

In ouput file , it look like

SQL> select C_SIM_MSISDN,C_SIM_IMSI from RCA_SMART_CARD order by C_SIM_MSISDN;
060010007 10007
:
:
:
SQL> spool off;

any setting or command that allow me to remove the first sql command line" SQL>select XXXX" and the last command "SQL>spool off" after start up the "spool mapping.txt"

View 1 Replies View Related

Client Tools :: Add Application Name In A Spool File?

Jul 26, 2011

To add application name in a spool file, I am using the below way.

sqlplus username/pwd@tns @xyz.sql APP0115

SQL> define appname="'&1'"
Enter value for 1: APP0115
SQL> prompt &appname
'APP0115'
SQL> spool &appname._html_jobs.csv;
SP2-0768: Illegal SPOOL command
Usage: SPOOL { <file> | OFF | OUT }
where <file> is file_name[.ext] [CRE[ATE]|REP[LACE]|APP[END]]

But I am getting the above error in the spool file clause because of single quote printing infront of the spool file. But the method of defining a character is "'&1'". So I cannot avoid this single quote in the define clause.

'APP0115'

print the appname like APP0115 instead 'APP0115'.then only I can use this in the spool file clause?

View 3 Replies View Related

Globalization :: Spool Brazilian Characters To A File

Jun 6, 2013

Oracle version Oracle Database 11g Release 11.2.0.1.0 - 64bit Production running on CentOS Linux release 6.0 (Final), kernel 2.6.32-71.29.1.el6.x86_64.

I am having a hard time spooling a file and displaying special Brazilian characters, even though I can see them correctly in SQLDeveloper:
LEOPOLDO COUTO DE MAGALHÃES JÚNIOR

Spool:
LEOPOLDO COUTO DE MAGALH?ES JUNIOR

I've tried changing the NLS_LANG at the session level, but that cannot be done. I don't want to change the default language of my DB, but really need these characters to display correctly in a file.

View 16 Replies View Related

PL/SQL :: Spool File Output From Unix To Windows

May 22, 2013

I'm running a sql file in Unix (using SQLPLUS command) and i want the file output to be sent to local windows directory. I specified the windows directory name in my Spool command (Spool C:/<Directory Name> ) , But it is not working

Our Unix server is a FTP server but i don't want to FTP the spool file from unix to Windows as the spool file is Huge and it takes hours for the transfer to complete (and we have to run the script multiple times).

Is there a way i can have the spool file created in Local windows directory when i run my sql script in Unix?

View 5 Replies View Related

PL/SQL :: Data To Existing File Using Spool Command?

Jul 19, 2012

I am calling a stored procedure from a shell script. This stored procedure is having a CLOB object as an OUT parameter. How to write the data in CLOB object a existing file which is there in my client system. Below is the shell and sql scripts.

Shell script
( echo "hello" ) > /root/file.txt
sqlplus -s $user/$pass@$tns @/root/proc.sql /root/file.txt << EOF
EOFSQL script
set pages 0
set trimspool off

[Code]...

spool offThis code writes contents of the OUT variable to file.txt, but my existing data ('hello') is lost.

I figured the it...Use append in the spool command...

View 1 Replies View Related

Client Tools :: Creating Spool File Dynamically

Aug 20, 2010

how to create a file in a folder based on todays date. i need to know how to define a variable in sqlplus and assign a value to it.Here is the code below. The code gets executed without creating a spool file.

DEFINE _DATE = replace('C:\_sysdate_EU001.csv', '_sysdate_', TO_CHAR(SYSDATE, 'DD-MON-YYYY'))
spool _DATE
set serveroutput on size 100000
select * from dual;
spool off

View 14 Replies View Related

Client Tools :: Format Output File By Command Spool?

Jan 20, 2011

I use sqplus in oracle to output the command output to text file .

I use below set environment varialble.

SQL> set echo off;
SQL> set linesize 3999;
SQL> set feedback off;
SQL> set feedback off;
SQL> set termout off;
SQL> set pagesize 0;
SQL> spool mapping.txt
select C_SIM_MSISDN,C_SIM_IMSI from RCA_SMART_CARD order by C_SIM_MSISDN;

In ouput file , it look like

SQL> select C_SIM_MSISDN,C_SIM_IMSI from RCA_SMART_CARD order by C_SIM_MSISDN;
060010007 10007
:
:
:
SQL> spool off;

any setting or command that allow me to remove the first sql command line" SQL>select XXXX" and the last command "SQL>spool off" after start up the "spool mapping.txt"

View 8 Replies View Related

Client Tools :: Spool Clob Column To A Flag File

Jul 15, 2013

I would like to spool a clob column to a flag file, however some of the clob are greater than 32k, and I have to have the same record in a single line in the file. Is there any way to achieve this through spooling?

set heading off
set feedback off
set term off
set long 1000000
set longchunksize 500000
set line 32767
set trimspool on
set pagesize 50000
spool file.txt
@--this is my select statement.
spool off
exit

View 1 Replies View Related

Client Tools :: How To Spool Clob Data Into Flat File

Oct 11, 2011

I want to spool CLOB data into flat file ?

View 6 Replies View Related

Client Tools :: How To Get SQL Query Output Into Text File Without Spool Statement

Mar 7, 2011

I would like to store my sql query output into text file.Like for example:

select name from emp where emp_id=101;
Here output should be in text file as
swapna.

I dont want to use spool statement here,since If I use it,spool statement will also be printed in text file which is not my requirement.I just want to take only output.

View 1 Replies View Related

SQL & PL/SQL :: Loop In UTL_FILE Is Not Getting Closed

Nov 1, 2013

I am trying read a File to find out the error message through UTL_FILE.m. But the loop used inside is not getting closed.

CREATE OR REPLACE procedure alert_mail_A
as
v_flag varchar2(10);
mesg varchar2(100);
c1 utl_smtp.connection; -- passing the datatype to a variable.
c varchar2 (1000);
B utl_file.file_type;
[code]........

View 1 Replies View Related

SQL & PL/SQL :: Utl_file Error In Oracle 9i?

Oct 5, 2010

I have make utl_file. Its run in oracle 10 g. But when i run oracle 9i it give some error.

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 "HR.EXP_DATA", line 9
ORA-06512: at line 1.

[code]......

View 3 Replies View Related

SQL & PL/SQL :: Oracle 9i - UTL_FILE Package?

Oct 4, 2010

oracle 9i, I am reading about UTL_FILE package.make this in Hr Schema.Where hire date between date 1 and date 2.

View 8 Replies View Related

SQL & PL/SQL :: Excel Created Using Utl_file Is Larger

Jul 1, 2010

when I am running a cursor and printing its data into an excel file using utl_file, the file size is nearly 50mb. But if I run the cursor and copy its data manually into an excel sheet the file size is only 22mb. I am unable to undersatnd why there is difference in file size.

View 6 Replies View Related

SQL & PL/SQL :: Moving Files After Using UTL_FILE Package?

Feb 21, 2013

We have a p/slq procedure that reads a *.txt file using the UTL_FILE package. The contents of the file are then inserted into a database table.

At the end of the procedure we close the open file using UTL_FILE.FCLOSE.

There is a program (non-oracle)that attempts to move the file to a new location after being read into Oracle. The problem is that the application cannot move the file as the file is locked. ie message displays that the file is open and cannot be moved to a new location.

Is there anything else that we are missing besides the UTL_FILE.FCLOSE.

View 5 Replies View Related

SQL & PL/SQL :: Writing Multiple Files Using UTL_FILE

Aug 16, 2012

I'm trying to read the data from flat file and write data into multiple files based on the condition. The value of each line is checked with the Flag Table (Id NUMBER, FlagType VARCHAR(25), Flag CHAR(1)), If the Flag is True then new file has to be created and corresponding line has to be moved into new file otherwise it has to continue with the same file.

CREATE OR REPLACE PROCEDURE rw_demo (File_In VARCHAR2, File_out VARCHAR2) IS
InFile utl_file.file_type;
OutFile utl_file.file_type;
vNewLine VARCHAR2(4000);
i PLS_INTEGER;
j PLS_INTEGER := 0;
SeekFlag BOOLEAN := TRUE;
[code].........

View 24 Replies View Related

SQL & PL/SQL :: Extra Characters While Utl_file.get_line()

Jul 21, 2010

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
PL/SQL Release 11.1.0.6.0 - Production
"CORE 11.1.0.6.0 Production"

i am trying to read the file, for which i m using the following:

l_utlfile_hdr := utl_file.fopen(p_dir,'header_evnt.txt', 'R');

utl_file.get_line(l_utlfile_hdr, l_hdr_evnt);

it gets these three characters at the start of the line
l_hdr_evnt = 

So i saved header_evnt.txt as UTF-8, and used utl_file.fopen_nchar, utl_file.get_line_nchar, which got rid of first two characters, but still has ¿. How to get rid of that?

View 18 Replies View Related

SQL & PL/SQL :: Read International Characters Through Utl_file Function

Jul 19, 2010

i am using oracle 10g enterprise edition.whether its possible to read international characters from the text file using the utl_file function..?

View 1 Replies View Related

Spool All Privileges Of A Particular User

Nov 21, 2012

I am trying cleaner and simple way to spool out all privileges of a user "ABC" in a way that it generates grant statement for them.

View 6 Replies View Related

SQL & PL/SQL :: How To Export Package Body Using Spool Command

Jan 8, 2013

I am trying to Spool a Package Body into a file using sqlplus. I tried 2 days:

WAY1
SET LINESIZE 32000;
SET PAGESIZE 0;
SET TRIMSPOOL ON;
SET ECHO OFF;
SET TERM OFF;
SET FEEDBACK OFF;

[code]....

WAY2
.....
SELECT dbms_metadata.get_ddl( 'PACKAGE', 'SPI_xxxx_PCK', 'owner') FROM dual;
......

In Way1, I got different DDL or partial DDL. In Way2, I got only first 2 lines of Package body. I am running this command from Schema user only.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved