Doubt in utl_file
hi all,
i am using utl_file for the first time and got the error. pl.
help.
1 declare
2 x utl_file.file_type;
3 begin
4 x := utl_file.fopen('d:\babu\oracle','first.txt','w');
5 utl_file.putf(x,'hi there how are you');
6* end ;
SQL> /
declare
ERROR at line 1:
ORA-06509: PL/SQL: ICD vector missing for this package
ORA-06512: at "SCOTT.UTL_FILE", line 140
ORA-06512: at line 4
thanks,
babu
Try the code below. I have included two different formats for
specifying the directory. Which directory format will work
depends on your operating system. If one doesn't work, then try
the other. If neither works, then the utl_file package may not
be set up properly on your system. Based on your error message,
I suspect that may be part of the problem. Did you run
utlfile.sql? Did you include:
utl_file_dir = d:\babu\oracle
or
utl_file_dir = /babu/oracle
or
utl_file_dir = *
in your init.ora file? Did you re-start your database after
adding the line to the init.ora file, so that the change takes
effect?
DECLARE
x UTL_FILE.FILE_TYPE;
BEGIN
-- if the first line below doesn't work,
-- then try the line below that instead:
x := UTL_FILE.FOPEN ('d:\babu\oracle', 'first.txt' ,'w');
-- x := UTL_FILE.FOPEN ('/babu/oracle', 'first.txt' ,'w');
UTL_FILE.PUT_LINE (x, 'hi there how are you');
UTL_FILE.FCLOSE (x);
END;
EDIT d:\babu\oracle\first.txt
Similar Messages
-
How to read a specific value or a portion of text using utl_file.
hi,
I have a small requirement which goes as follows. I have a text file which is a resultof the sql query and it contains 16 columns as PIPE delimited text . I am using the UTL_FILE package concept to read the data. In general when we use the UTL_FILE.GET_LINE we read the entire line of text. But i need to read the 10th column of the query or the PIPE delimited text .
Please advice.
My query goes something like this:
declare
f utl_file.file_type;
s long;
c number := 0;
begin
f := utl_file.fopen('ABC_EXTRACTS','sample1.txt','R');
loop
utl_file.get_line(f,s);
insert into s values (s);
c := c + 1;
end loop;
exception
when NO_DATA_FOUND then
utl_file.fclose(f);
dbms_output.put_line('No. of rows inserted : ' || c);
end;Why don't you use varchar2 instead of long data type. I doubt you can read a portion from a file using utl_file but after doing the fetch you can do substring over the varchar2 variable and retrieve just the 10th column.
sample sql:
If your DB is 10g or higher, you can use the below regular expression to retrieve value based on your need.
PRAZY@11gR1> select regexp_substr('111|222|333|444|555|666|777|888|999|000|aaa|bbb|','[^|]+',1,10) from dual;
REG
000
Elapsed: 00:00:00.00Btwn, if the text file has fixed number of columns at all time, why don't you use a external table instead?
Regards,
Prazy
Edited by: Prazy on Mar 22, 2010 4:11 PM -
Problem : Load PDF or similiar files( stored at operating system) into an oracle table using SQl*Loader .
and than Unload the files back from oracle tables to prevoius format.
I 've used SQL*LOADER .... " sqlldr " command as :
" sqlldr scott/[email protected] control=c:\sqlldr\control.ctl log=c:\any.txt "
Control file is written as :
LOAD DATA
INFILE 'c:\sqlldr\r_sqlldr.txt'
REPLACE
INTO table r_sqlldr
Fields terminated by ','
id sequence (max,1) ,
fname char(20),
data LOBFILE(fname) terminated by EOF )
It loads files ( Pdf, Image and more...) that are mentioned in file r_sqlldr.txt into oracle table r_sqlldr
Text file ( used as source ) is written as :
c:\kalam.pdf,
c:\CTSlogo1.bmp
c:\any1.txt
after this load ....i used UTL_FILE to unload data and write procedure like ...
CREATE OR REPLACE PROCEDURE R_UTL AS
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER ;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
SELECT data
INTO l_blob
FROM r_sqlldr
where id= 1;
l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
DBMS_OUTPUT.PUT_LINE('blob length : ' || l_blob_len);
IF (l_blob_len < 32767) THEN
l_amount :=l_blob_len;
ELSE
l_amount := 32767;
END IF;
DBMS_LOB.OPEN(l_blob, DBMS_LOB.LOB_READONLY);
l_file := UTL_FILE.FOPEN('DBDIR1','Kalam_out.pdf','w', 32767);
DBMS_OUTPUT.PUT_LINE('File opened');
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.READ (l_blob, l_amount, l_pos, l_buffer);
DBMS_OUTPUT.PUT_LINE('Blob read');
l_pos := l_pos + l_amount;
UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
DBMS_OUTPUT.PUT_LINE('writing to file');
UTL_FILE.FFLUSH(l_file);
UTL_FILE.NEW_LINE(l_file);
END LOOP;
UTL_FILE.FFLUSH(l_file);
UTL_FILE.FCLOSE(l_file);
DBMS_OUTPUT.PUT_LINE('File closed');
DBMS_LOB.CLOSE(l_blob);
EXCEPTION
WHEN OTHERS THEN
IF UTL_FILE.IS_OPEN(l_file) THEN
UTL_FILE.FCLOSE(l_file);
END IF;
DBMS_OUTPUT.PUT_LINE('Its working at last');
END R_UTL;
This loads data from r_sqlldr table (BOLBS) to files on operating system ,,,
-> Same procedure with minor changes is used to unload other similar files like Images and text files.
In above example : Loading : 3 files 1) Kalam.pdf 2) CTSlogo1.bmp 3) any1.txt are loaded into oracle table r_sqlldr 's 3 rows respectively.
file names into fname column and corresponding data into data ( BLOB) column.
Unload : And than these files are loaded back into their previous format to operating system using UTL_FILE feature of oracle.
so PROBLEM IS : Actual capacity (size ) of these files is getting unloaded back but with quality decreased. And PDF file doesnt even view its data. means size is almot equal to source file but data are lost when i open it.....
and for images .... imgaes are getting loaded an unloaded but with colors changed ....
Also features ( like FFLUSH ) of Oracle 've been used but it never worked
ANY SUGGESTIONS OR aLTERNATE SOLUTION TO LOAD AND UNLOAD PDFs through Oracle ARE REQUESTED.
------------------------------------------------------------------------------------------------------------------------Thanks Justin ...for a quick response ...
well ... i am loading data into BLOB only and using SQL*Loader ...
I've never used dbms_lob.loadFromFile to do the loads ...
i 've opend a file on network and than used dbms_lob.read and
UTL_FILE.PUT_RAW to read and write data into target file.
actually ...my process is working fine with text files but not with PDF and IMAGES ...
and your doubt of ..."Is the data the proper length after reading it in?" ..m not getting wat r you asking ...but ... i think regarding data length ..there is no problem... except ... source PDF length is 90.4 kb ..and Target is 90.8 kb..
thats it...
So Request u to add some more help ......or should i provide some more details ?? -
SYS.UTL_FILE does not exists...
Hi!
I use 'utl_file.fopen' in a PL/SQL Package. It works fine with ORACLE 8.1.7 and now with ORALCE 9.2 it breaks.
First I have create a directory 'UTL_FILE_TMP' and grant it to the PL/SQL user.
At the code 'v_file := utl_file.fopen('UTL_FILE_TMP',v_name, 'a');' I get the ORAERR 04067 --> SYS.UTL_FILE does not exists...
Have I install the package seperatly and when yes, how can I do?
Regars
-micI really doubt that you have a directory called UTL_FILE_TMP, "C:\UTL_FILE_TMP" on a winows machine, "u01/UTL_FILE_TMP" on a unix machine I can believe, but a volume labeled "UTL_FILE_TMP", I don't You MUST have the full directory path the the directory and the directory MUST be writable by the user (typically oracle) that is running the database code.
-
Hi,
I am trying to create a text file from PL/SQL, I am unable to open file with UTL_FILE.FOPEN it is giving "Invalid Path" error. I have created Directory with sys account and granted read/write to the public.
Please can any one help me.
Regards,
VenkatFrom your question, I am having a doubt that u have created a Directory Object in the Database. But using utl_file, you can only open files from the OS. Also the path you are giving should exists in the sever where Oracle is installed, not in the client machine.
-Magesh -
Hi,
First doubt:
When I execute the SQL*LOADER the following error occurs:
SQL*LOADER-350: Erro de sintaxe na linha 6.
Esperando especificagco de coluna valida, ", ou ")"; localizado "VARCHAR2".
(NAME POSITION(01:64) VARCHAR2,
^
The control file is like this:
ARQUIVO1.CTL
LOAD DATA
INFILE 'C:\testes\ARQUIVO1.TXT'
BADFILE 'C:\testes\ARQ1_ERRO.TXT'
TRUNCATE
INTO TABLE CARLA.TEMP_TESTE
(NAME POSITION(01:64) VARCHAR2,
ENDERECO POSITION(65:81) VARCHAR2,
TELEFONE POSITION(82:95) VARCHAR2)
Somebody, knows what happens?
Second doubt: How can I execute sqlldr in a procedure? Is there any command that simulates the DOS line command? Is there any example?
Thanks
CarlaHere are a couple of links to pages on Tom Kyte's site. The first one shows how to use java to enable execution of an operating system file from pl/sql. Just store your SQL*Loader commands in a .bat file and use Tom's code to enable execution of the .bat file from pl/sql. The second one uses utl_file that acts like a "mini sqlloader" in pl/sql and includes an example that demonstrates some data validation, checking for numeric values. I have used both methods succesfully. For large files, SQL*Loader is much faster than utl_file.
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:952229840241
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:464420312302 -
hi i have a doubt....
in fbl1n transaction, there are open items and cleared items.
in it the cleared items for certain document types such as invoice etc is not present in the open item table (bsik)
however the cleared items for document types such as general voucher its present in the open items table (bsik)
is this possible as all cleared item entries shld b present in the open item table with an indicator set for cleared or not...
plz exlain!Hi
There are 2 tables(open and Closed Items) in FI for Account Payables and Account Receivables and GL accounts
1.Account payables: BSIK is Open Items and BSAK is Closed items
2.Account Receivables; BSID and BSAD for OPEN and closed items
3/GL accounts : BSIS and BSAS for Open and Closed Items
<b>Reward points for useful Answers</b>
Regards
Anji -
Doubt in creation of a new object
Hi All,
I have one doubt in creation of a new object.If a new object is to be created and it is not a subtype
of any existing object, then what should we enter in the Program field for creating the object?
I hope I am clear with my question.
Thanks in Advance,
Saket.Hi Saket,
Following will be required for created a custom business object.
1. Object Type - ZTEST (Internal Techincal Key)
2. Object Name - ZTESTNAME (Technical Key Name)
3. Name - TEST (Name of BO, it is used while selecting the object type)
4. Description - (Short Description of BO)
5. Program - ZTESTPROGRAM (ABAP program in which the methods of the object type are implemented)
6. Application - A or B.. etc (Area to which your BO is related)
Please remember that you can learn these basic things by giving F1 help on those fields and in HELP.SAP.COM.
Regards,
Gautham Paspala -
Help needed in utl_file
Hi,
I have two groups in data model of my report. I am using utl_file in a formula column of report last group.it's working fine.
but my problem is if customer has more than one invoice lines
then all that lines not comes under only particular customer only at a time.
For example my output is coming like this:
Customer address: 3345 LIMITED-STUDIOS : 00033-45 PARR STREETLIVERPOOLCHESHIRE
Invoice Lines: 0001000402106-JUL-07INV 10.47
Customer address: 3345 LIMITED-STUDIOS : 00033-45 PARR STREETLIVERPOOLCHESHIRE
Invoice Lines: 0001000402713-JUL-07INV 10.77
But I am trying to get output like this:
Customer address: 3345 LIMITED-STUDIOS : 00033-45 PARR STREETLIVERPOOLCHESHIRE
Invoice Lines: 0001000402106-JUL-07INV 10.47
0001000402713-JUL-07INV 10.77
I am using fallowing code in my formula column:
function CF_UTL_FILEFormula return Char is
v_file_data utl_file.file_type;
begin
utl_file.put_line(v_file_data,:SEND_CUSTOMER_NAME:SEND_ADDRESS1:SEND_ADDRESS2:SEND_ADDRESS3:SEND_ADDRESS4:SEND_CITY:SEND_STATE:SEND_COUNTRY_DESC:SEND_POSTAL_CODE);
utl_file.put_line(v_file_data,LN1:CF_LOCATION:C_DELIVERY_DATE:INVOICE_NUMBER:TRX_DATE:c_transaction_type:CD_TRX_AMOUNT);
utl_file.fclose(v_file_data);
end;
Please help me how can I do this?What's the source of your Summary Column? It's not allowed to choose here the formula column in whcih you reference the summary column back. But another column should work.
As alternativ add a formula column in the upper group with
utl_file.put_line(v_file_data,:SEND_CUSTOMER_NAME:SEND_ADDRESS1:SEND_ADDRESS2:SEND_ADDRESS3:SEND_ADDRESS4:SEND_CITY:SEND_STATE:SEND_COUNTRY_DESC:SEND_POSTAL_CODE);
and remove the same line out of the other formula column. -
Hi Everyone,
Can we read and validate the attachment of the mail.If so how to do it.
Thanks in advance,
SakthiHi Sakthi,
Please refere the below links:
http://help.sap.com/saphelp_nw2004s/helpdata/en/ad/bf93409c663228e10000000a1550b0/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/0d/52b240ac052817e10000000a1550b0/frameset.htm
Let me know if you have any doubts regarding this.
Thanks,
sekhar. -
PI' RFC Connection pool doubt.
Hi PI exports:
i have a doubt about pi' RFC Connection pool ,pi RFC receive channel can set the conn pool size ,but when start the rfc receiver channel ,is there always only one Connection pool ,or there is only one Connection pool instance?
thinks
Edited by: kevin liang on Oct 19, 2009 6:45 AMHi,
Connection poolins size means how many number of connection you want to make open to send data to ECC, We can define maximum number of connection in Receiver RFC Adapter,Go to additional parameters section and define Max Number of connection give the number there,thats it.Internally it works as Connection poolin mechanism.
Regards,
Raj -
Small Doubt Regarding SY-MANDT
Hi All,
SELECT changenr FROM cdhdr CLIENT SPECIFIED INTO CORRESPONDING FIELDS OF TABLE it_cdhdr
WHERE mandant = syst-mandt
AND objectclas = 'MATERIAL'
AND objectid = wa_matl-matnr
AND tcode = 'MM02'.
I have written the select stament as shown above.
In this i have a doubt like adding a field sy-mandt in the where condition will increase the Efficiency of program or not.
regards,
raghu.Hi..
No doubt the efficency would be affected but from business point of view there will many things that need to be checked as in:
If you are viewing data from CDHDR and CDPOS which is client specific then you are not viewing complete data.
These tables give us and document changes made to a particular object in SAP but if anything is cross client like company code(lets assume) then changes to it wont be visible in all the clients..
so there can be some key information you can miss out while working on some of the objects.
else in this case its good to make query cross client.
regards
vishal -
Doubts with control break statements on internal table loops (AT/ENDAT)
Hi, i've had a couple of doubts for a long while which I hope someone can clarify today:
1) I know how to use the AT statements, however, i'm not sure I get correctly what this part of help regarding this commands means:
<i>"The control level structure with internal tables is static. It corresponds exactly to the sequence of columns in the internal table (from left to right). In this context, the criteria according to which you sort the internal table are unimportant."</i>
I've always sorted the internal table before the control break and it works that way. For example:
SORT ITAB BY EBELN EBELP.
LOOP AT ITAB.
AT NEW EBELN.
* Code for the order header
ENDAT.
ENDLOOP.
If I <b>don't</b> sort the internal table, it doesn't work! (i get dupplicated processing). In the example, if i have more than one register with the same EBELN and they're not consecutive, the header gets processed twice. I really don't get that part of the help text.
2) I know this: <i>"At the start of a new control level (i.e. immediately after AT), the following occurs in the output area of the current LOOP statement:
All character type fields (on the right) are filled with "*" after the current control level key.
All other fields (on the right) are set to their initial values after the current control level key."</i>
My doubt is: WHY is that this way? Because sometimes (most times) I need those fields INSIDE the statement! So when that happened i've solved it in one of three ways:
LOOP AT ITAB INTO WA_ITAB.
WA_ITAB_AUX = WA_ITAB.
AT NEW FIELD.
WA_ITAB = WA_ITAB_AUX.
* ...Rest of the code for the first register
ENDAT.
ENDLOOP.
LOOP AT ITAB INTO WA_ITAB.
AT NEW FIELD.
READ TABLE ITAB INDEX SY-TABIX INTO WA_ITAB.
* ...Rest of the code for the first register
ENDAT.
ENDLOOP.
* (Without AT)
LOOP AT ITAB INTO WA_ITAB.
IF WA_ITAB-FIELD <> FIELD_AUX.
FIELD_AUX = WA_ITAB_FIELD.
* ...Rest of the code for the first register
ENDIF.
ENDLOOP.
Is there any problem with this way of coding? Can be done better?
Thank you very much in advance.Hi..,
1)
See if u sort the table on a field on which u r using AT ENDAT .. then all the records which are having the same value for that field will form a group or those reocrds will be at one place.. so when u sort the table for all the records AT ENDAT will get executed onli once..
If u dont sort this table on this field then all these records will be at different places and in between there may be records with different value for this field.. so this AT ENDAT will get executed for each record !!
2)
No u cannot use the Right hand fields of the field in the table .. Because these AT events work as Group based operations... So till that field on which AT ENDAT is working it breaks that record into two groups.. One is the left hand fields including that field.. and right hand fields as another group.. and makes the right hand group as stars ****. Thats y u can observe that even any one field in the left hand group changes the AT ENDAT will get executed !!!!
Hope u understood !!!
regards,
sai ramesh -
CREATE PACKAGE EMP_PKG AS
CURSOR EMP_CUR IS
SELECT EMPNO,DEPTNO,SAL,HIREDATE
FROM EMP
WHERE DEPTNO=30;
PROCEDURE P_EMP;
PROCEDURE P_GET_SAL(V_EMPNO NUMBER);
PROCEDURE P_GET_LOC(V_EMPNO NUMBER);
Now inside my Package Body
INSIDE THE MAINPROCEDURE P_EMP
I WILL BE CALLING THE BELOW TWO PROCEDURES
PROCEDURE P_EMP
BEGIN
FOR I IN EMP_CUR LOOP
P_GET_SAL(I.EMPNO);-- DO I NEED TO LOOP AGAIN IN P_GET_SAL PROC?
P_GET_LOC(I.DEPTNO);
END LOOP;
END;
NOW WHAT IAM DOING IS
in my P_GET_SAL Procedure is
PROCEDURE P_GET_SAL(V_EMPNO NUMBER)
V_SAL EMP.SAL%TYPE;
BEGIN
FOR I IN EMP_CUR LOOP
SELECT SAL INTO V_SAL FROM EMP
WHERE EMPNO=I.EMPNO --DOUBT HERE
END;
I WANT TO KNOW WHETHER I NEED TO LOOP AGAIN
HERE OR INSTEAD OF THAT
PROCEDURE P_GET_SAL(V_EMPNO NUMBER)
V_SAL EMP.SAL%TYPE;
BEGIN
SELECT SAL INTO V_SAL FROM EMP
WHERE EMPNO =V_EMPNO;
END;
SINCE iam calling V_EMPNO WITH CURSOR FROM MY
MAINPROCEDURE ..
WILL THE PROCEDURE USES THE CURSOR VALUES
AND LOOP ITSELF FOR EVERY EMPLOYEE TO
GET THE SALALRY ?
PLEASE LET ME KNOW SINCE MY PACKAGE IS MORE THAN 3000
LINES I cant proceed unless its confirmed i can
do so ..Hi all,
Thanks for Looking into my Problem
I Got answer by MySelf ..i dont need to loop again my sub procedures
if i try to do that iam getting the error
ERROR at line 1:
ORA-06511: PL/SQL: cursor already open
Thank you all once again .. -
Doubt on Rows and Coloums in BEx Query Designer.
Hello, Experts.
I have a Doubt in BEx Query Designer.
In the Rows I have a Fiscal year Period, if the user enters the Fiscal year period for e.g. : 001/2006 .
in the columns i have forecast for the Fiscal year period which user entered ( 001/2006 ), and we have another column pervious ( Prior )fiscal year period ( 001/2005 ).
My Questions is , as we are Restricting with 001/2006 will the query retrieve the values of 2005 or not?
Thanks in Advance .
Sharpyes i am Doing Offest.
I moved this Fiscal year Period to Free char, and i Restricted with Pervious Fical Year period and Fical year period . it worked. but
when i kept this in Rows and deleted Previous Fiscal Year period . it is displaying blanks. in prior years forecast.
is it because i am Ristricting it to only fical year period which user entered
Colums--> Forcast ( User Entered year ) Prior year
Rows
Fiscal year period
Fiscal year period( user enterd )
Thanks
Maybe you are looking for
-
8.6.1 HELP and TOOLS- OPTIONS not working
Hi, after installing 8.6.1 I'm not able to access help for any function, except on tookit functions. The context help works, but there is no detailed help (except Toolkit functions). If I access LabVIEW help, the window shows the tree on the right
-
Personalize link not appearing in Portal
Hello Gurus We had installed EP 7.0 sometime back but I have observed today that the poersonalize link is not appearing for a user that I created. Can someone please tell me how to correct this? Thanks.
-
JMX/RMI and Automatic Code Downloading
There is a brief discussion of automatic code downloading in the JMX Best Practices document (http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/best-practices.jsp#mozTocId348704), but not enough to actually implement it. Would som
-
Enterprise Role Concept in ERM
Hello, We want to implement Enterprise Role(Not Portal) concept in ERM. Anybody has implemented this concept of composite roles from different single roles belonging to different SAP components. Ex : Marketing Management Enterprise Role is a collecti
-
Purchase only Photoshop from CS5 with multiple licenses for class
Hello Adobe Community, I am teaching a class of 24 students, and they are looking to purchase only Photoshop from the create suite for PC. They are a non-profit organization. I'm looking to see what the best option is for me and my class. Being a non