Read text file insert into table using utl_file
Hi
i have script for read and insert into table but i want error records load into error table so i sent you my script and please fix the error log table
script
DECLARE
v_line VARCHAR2(2000);
v_file utl_file.file_type;
v_dir VARCHAR2(250);
v_filename VARCHAR2(50);
BEGIN
v_dir :='MID5010_DOC1TP';
v_filename := 'OPT_CM_BASE.txt';
v_file := utl_file.fopen(v_dir, v_filename, 'r');
LOOP
BEGIN
utl_file.get_line(v_file, v_line);
EXCEPTION
WHEN no_data_found THEN
EXIT;
END ;
v_line := REPLACE(v_line,'|','|~');
INSERT
INTO optum_icd10cm_base VALUES
( REPLACE(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,1),'a~','a'),'.'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,2),'a~','a'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,3),'a~','a'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,4),'a~','a'),
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,5),'a~','a'),
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,6)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,6),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,6),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,7)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,7),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,7),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,8)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,8),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,8),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,9)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,9),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,9),'a~','a'),'mm-dd-yyyy')
END,
CASE
WHEN LENGTH(regexp_substr(v_line,'[^|~]+',1,10)) < 10
THEN to_date(ltrim(TRANSLATE(regexp_substr(v_line,'[^|~]+',1,10),'a~','a'),'0'),'mm-yyyy')
ELSE to_date(TRANSLATE(regexp_substr(v_line,'[^|]+',1,10),'a~','a'),'mm-dd-yyyy')
END,
TRANSLATE(regexp_substr(v_line,'[^|~]+',1,11),'a~','a')
-----commit;
END LOOP;
utl_file.fclose(v_file);
END;
text file
A50.0||Short|Long|Full|01-01-2009|01-2009||01-01-2013|09-18-2012|C|
A50.1||Short|Long|Full|01-01-2009|01-01-2009||001-2013|09-18-2012|C|
A50.2||Short|Long|Full|01-01-2009|01-01-2009|67|01-01-2013|09-18-2012|C|
A50.3||Short|Long|Full|011-2009|01-01-2009||01-01-2013|09-18-2012|C|
A50.4||Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|5|
A50.5|R|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A50.6||Short|Long||01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A50.7||Short||Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
2345||Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.5|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.6|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.7|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.8|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A60.9|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A70.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
B222|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.5|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.6|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.7|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.8|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A4.9|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.2|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
A5.3|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
D642|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
A5.5|D|Short|Long|Full|01-01-2009|01-01-2009|01-10-2013|01-01-2013|09-18-2012|C|
A5.6|D|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.7|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A001|C|Short Updated|Long Updated|Full Updated|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A009|C|Short Updated|Long Updated|Full Updated|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A5.10|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A0109|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.0|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.1|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.2|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.3|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.4|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.5|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.6|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
F10.7|N|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A30|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A316|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
A317|C|Short|Long|Full|01-01-2009|01-01-2009||01-01-2013|09-18-2012|C|
----clearly read text file insert into table and error records load into error table
please help me
hI
i am using utl_file prepared script but i got error like 01861. 00000 - "literal does not match format string"
script:
DECLARE
f utl_file.file_type;
s VARCHAR2(32000);
f1 VARCHAR2(100);
f2 varchar2(100);
F3 VARCHAR2(100);
F4 VARCHAR2(100);
F5 VARCHAR2(100);
F6 DATE;
F7 DATE;
F8 DATE;
F9 DATE;
F10 DATE;
f11 CHAR(1);
BEGIN
--DBMS_OUTPUT.ENABLE(100000);
f := utl_file.fopen('MID5010_DOC1TP', 'OPT_CM_BASE.txt', 'R');
LOOP
BEGIN
UTL_FILE.GET_LINE(f, s);
f1 := REGEXP_SUBSTR (s,'[^|]+',1,1);
f2 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,2);
F3 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,3);
F4 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,4);
F5 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,5);
F6 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,6),'mm-dd-yyyy');
F8 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,8),'mm-dd-yyyy');
F7 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,7),'mm-dd-yyyy');
F9 := to_date(REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+',1,9),'mm-dd-yyyy');
F10 :=to_date(REGEXP_SUBSTR (REPLACE(s,'||','||') ,'[^|]+',1,10),'mm-dd-yyyy');
f11 := REGEXP_SUBSTR (REPLACE(s,'||','||'),'[^|]+', 1,11);
INSERT
INTO OPTUM_ICD10CM_BASE
( CODE,
STATUS,
SHORT_DESCRIPTION,
LONG_DESCRIPTION,
FULL_DESCRIPTION,
CODE_EFFECTIVE_DATE,
CHANGE_EFFECTIVE_DATE,
TERMINATION_DATE,
RELEASE_DATE,
CREATION_DATE,
VALIDITY
VALUES
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
f11
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
UTL_FILE.FCLOSE(F);
END;
please help me(in my org looks utl_file standards only)
Similar Messages
-
Exporting data from text file to a table using utl_file
Dear all,
I have a text file as below and i have a table having 12 columns. Now i need to insert this text file into the table story_books.
CREATE TABLE story_books
book_id NUMBER,
Category VARCHAR2(100 BYTE),
Book_type VARCHAR2(100 BYTE),
Name VARCHAR2(700 BYTE),
Location VARCHAR2(700 BYTE),
Ownership_code VARCHAR2(700 BYTE),
Author VARCHAR2(700 BYTE),
Less_Sel_fact VARCHAR2(700 BYTE),
Reason VARCHAR2(700 BYTE),
Buying VARCHAR2(700 BYTE),
Suspected Book VARCHAR2(700 BYTE),
Conditions VARCHAR2(700 BYTE)
-------------------------text file---------------
Books Out Table: Books
Book. Type Name Location Ownership Code
Story SL hyd SS-HYD
Known Author: Unknown
Less Selling Factors: Thunderstorms
Reason: Unknown
Buying (if applicable):
Not Applicable
Suspected Book:
Unknown
Conditions to increace sales:
Advertisement in all areas
i was able to read the data and storing if it is in the same line.But i dont know how to read below data
Book. Type Name Location Ownership Code
Story SL hyd SS-HYD
In this data i have to search for 'Book. type' and then i need to save the word 'Story' to the column 'Book_type'
Then i need to search for 'Name' and i need to save 'SL' into the column into 'Name'
Then i need to search for 'Location' and i need to save 'hyd' into the column into 'Location'
I was able to extract the data if it is in below format using utl_file.get_line
Known Author: Unknown
Less Selling Factors: Thunderstorms
Reason: Unknown
Any one can explain me how to solve the above criteria.
Thanks in advance.Dear all,
I have a text file as below and i have a table having 12 columns. Now i need to insert this text file into the table story_books.
CREATE TABLE story_books
book_id NUMBER,
Category VARCHAR2(100 BYTE),
Book_type VARCHAR2(100 BYTE),
Name VARCHAR2(700 BYTE),
Location VARCHAR2(700 BYTE),
Ownership_code VARCHAR2(700 BYTE),
Author VARCHAR2(700 BYTE),
Less_Sel_fact VARCHAR2(700 BYTE),
Reason VARCHAR2(700 BYTE),
Buying VARCHAR2(700 BYTE),
Suspected Book VARCHAR2(700 BYTE),
Conditions VARCHAR2(700 BYTE)
-------------------------text file---------------
Books Out Table: Books
Book. Type Name Location Ownership Code
Story SL hyd SS-HYD
Known Author: Unknown
Less Selling Factors: Thunderstorms
Reason: Unknown
Buying (if applicable):
Not Applicable
Suspected Book:
Unknown
Conditions to increace sales:
Advertisement in all areas
i was able to read the data and storing if it is in the same line.But i dont know how to read below data
Book. Type Name Location Ownership Code
Story SL hyd SS-HYD
In this data i have to search for 'Book. type' and then i need to save the word 'Story' to the column 'Book_type'
Then i need to search for 'Name' and i need to save 'SL' into the column into 'Name'
Then i need to search for 'Location' and i need to save 'hyd' into the column into 'Location'
I was able to extract the data if it is in below format using utl_file.get_line
Known Author: Unknown
Less Selling Factors: Thunderstorms
Reason: Unknown
Any one can explain me how to solve the above criteria.
Thanks in advance. -
Import data from text file to a table using t-sql
Hi,
I am trying to import data from a text file to a table using the below query but it is returning an error.
SELECT *, 2 FROM OPENROWSET(BULK 'W:\file.txt',
FORMATFILE = 'W:\format_file.xml', FIRSTROW = 1, LASTROW = 1) as f
The error is:
Bulk load data conversion error (truncation) for row 1, column 1 (COPYRIGHT_DETAIL_CODE).<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="1" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="5" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="5" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="10" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="1" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="1" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="10" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="10" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="8" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="8" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="8" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="12" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="5" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="13" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="8" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="14" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="2" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="15" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="3" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="16" xsi:type="CharTerm" TERMINATOR=" " MAX_LENGTH="4" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
<FIELD ID="17" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="43" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="Name1" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="2" NAME="Name2" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="3" NAME="Name3" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="4" NAME="Name4" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="5" NAME="Name5" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="6" NAME="Name6" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="7" NAME="Name7" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="8" NAME="Name8" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="9" NAME="Name9" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="10" NAME="Name10" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="11" NAME="Name11" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="12" NAME="Name12" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="13" NAME="Name13" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="14" NAME="Name14" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="15" NAME="Name15" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="16" NAME="Name16" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="17" NAME="Name17" xsi:type="SQLVARYCHAR"/>
</ROW>
</BCPFORMAT>
The format file that I am using is just like the same one above.
-
Loading the data from a text file to a table using pl/sql
Hi Experts,
I want to load the data from a text (sample1.txt) file to a table using pl/sql
I have used the below pl/sql code
declare
f utl_file.file_type;
s varchar2(200);
c number := 0;
begin
f := utl_file.fopen('TRY','sample1.txt','R');
loop
utl_file.get_line(f,s);
insert into sampletable (a,b,c) values (s,s,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;
and my sample1.txt file looks like
1
2
3
The data is getting inserted, with below manner
select * from sampletable;
A B C
1 1 1
2 2 2
3 3 3
I want the data to get inserted as
A B C
1 2 3
The text file that I have is having three lines, and each line's first value should go to each column
Please help...
Thanksdeclare
f utl_file.file_type;
s1 varchar2(200);
s2 varchar2(200);
s3 varchar2(200);
c number := 0;
begin
f := utl_file.fopen('TRY','sample1.txt','R');
utl_file.get_line(f,s1);
utl_file.get_line(f,s2);
utl_file.get_line(f,s3);
insert into sampletable (a,b,c) values (s1,s2,s3);
c := c + 1;
utl_file.fclose(f);
exception
when NO_DATA_FOUND then
if utl_file.is_open(f) then utl_file.fclose(f); ens if;
dbms_output.put_line('No. of rows inserted : ' || c);
end;SY. -
Help needed in reading text file to database table
Hello experts,
i have to insert the values from the column of this text file and insert them in my database table.
I have done a few file to table insertions but i'm having some trouble with this one.
Any suggestions plz
thanks
liab_report 1.00 Page: 1
CDC:00537 / Mon Jun-21-2010 LIABILITY REPORT Mon Jun-21-2010 22:06:26
DRAW 1; SET 1; November 7, 2009
TOTAL PAID ON TOTAL EXPIRED ON TOTAL FRAC OUTSTANDING
WINNERS 06/21/10 PAID 06/21/10 EXPIRED ROUND
DIVISION AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT
Div1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Div2 701040.00 0.00 660146.00 0.00 40894.00 0.00 0.00
Div3 1444128.00 0.00 1330056.00 0.00 114072.00 0.00 0.00
Div4 4711900.00 0.00 3889700.00 0.00 822200.00 0.00 0.00
6857068.00 0.00 5879902.00 0.00 977166.00 0.00 0.00
DRAW 2; SET 1; November 14, 2009
TOTAL PAID ON TOTAL EXPIRED ON TOTAL FRAC OUTSTANDING
WINNERS 06/21/10 PAID 06/21/10 EXPIRED ROUND
DIVISION AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT
Div1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Div2 817817.00 0.00 817817.00 0.00 0.00 0.00 0.00
Div3 1687405.00 0.00 1611742.00 0.00 75663.00 0.00 0.00
Div4 3402100.00 0.00 3034200.00 0.00 367900.00 0.00 0.00
5907322.00 0.00 5463759.00 0.00 443563.00 0.00 0.00
DRAW 3; SET 1; November 21, 2009
TOTAL PAID ON TOTAL EXPIRED ON TOTAL FRAC OUTSTANDING
WINNERS 06/21/10 PAID 06/21/10 EXPIRED ROUND
DIVISION AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT AMOUNT
Div1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Div2 779933.00 0.00 769804.00 0.00 10129.00 0.00 0.00
Div3 1605548.00 0.00 1525104.00 0.00 80444.00 0.00 0.00
Div4 4891700.00 0.00 4256800.00 0.00 634000.00 0.00 900.00
7277181.00 0.00 6551708.00 0.00 724573.00 0.00 900.00Plz clarify whether u want to load text file as a file into database or value of this text file into database. If values are to be loaded from this text file, U can better format the text file and use SQL loader to load the file into database. By formatting the database, i mean remove the unnecessary headings and characters, kee only the values to be loaded idelimited by ' '(space) or ','(comma). Create a control file and load it into the target table.
-
Reading text file to populate table
I am getting following error
5/10/01 1:08 PM Execution failed: ORA-20053: Read Error
5/10/01 1:08 PM ORA-06512: at line 8
5/10/01 1:08 PM End Executing PL/SQL block
When I run the same program in for loop for 100 times it runs fine. But does not work if I run the loop till end of file.
PROCEDURE READTEXT ( p_FileDir IN varchar2,
p_FileName IN varchar2,
p_OpenMode IN varchar2)
AS
v_file utl_file.file_type;
v_line varchar2(2700);
v_rec_id bu340.rec_id%type;
v_num_lines bu340.num_lines%type;
v_typist_orig bu340.typist_orig%type;
BEGIN
v_file := utl_file.fopen(p_FileDir,p_FileName,p_OpenMode);
LOOP
BEGIN
utl_file.get_line(v_file,v_LINE);
EXCEPTION
when NO_DATA_FOUND then
EXIT;
END;
v_rec_id := substr(v_line,1,4);
v_typist_orig := substr(v_line,7,2);
INSERT INTO BU340 (rec_id,typist_orig)
VALUES (v_rec_id,v_typist_orig);
END LOOP;
utl_file.fclose(v_file);
commit;
EXCEPTION
when utl_file.invalid_operation then
utl_file.fclose(v_file);
raise_application_error(-20051,'Invalid Operation');
when utl_file.invalid_FileHandle then
utl_file.fclose(v_file);
raise_application_error(-20052,'Invalid FileHandle');
when utl_file.read_error then
utl_file.fclose(v_file);
raise_application_error(-20053,'Read Error');
when others then
utl_file.fclose(v_file);
raise;
END;
nullI guess what is happening is since you have more than 100 records it runs fine if you try 1 .. 100 but if you try end of file it enters the code for exception. The Exit is not working the way you want it to work so it falls through due to which you are getting a read error since there is no data.
Your Code sample :
LOOP
BEGIN
utl_file.get_line(v_file,v_LINE);
EXCEPTION
when NO_DATA_FOUND then
EXIT;
END;
v_rec_id := substr(v_line,1,4);
You can try either of this
1. Remove Begin and End statement.
2. EXCEPTION
EXIT when NO_DATA_FOUND;
I guess it is of some help.
null -
Insert into table using dynamic data
Oracle form 6i
Hai
I need to insert my data into a table. I have generated my data from text file and data in a form now i need to insert these data into one table. How can insert my field to that table if there is data in table i need to update and there is no data i need to insert.. Pls tell me the solution..
Regards
Srikkanth.MCreate the on-insert trigger and check the data is thre or not through the Primary key value in this trigger. If data is thre then update or it not there then insert in the same trigger.
Thanks,
SUN -
How to INSERT into table using CORRELATED subquery
I have 3 tables:
1.TEMP_PHONE(person_id, phonenumber, phone_type) - this holds all phone numbers relating to a person(just a temporary holding area)
2.PHONE_CONNECT(PERSON_ID, PHONE_ID) this table shows all the phone numbers relating to an individual. Phone_id is a unique number to identify a phonenumber and type(cell, work, home) - so in this table a person can have multiple phone ids)
3.MASTER_PHONE(PHONE_ID, PHONENUMBER, PHONE_TYPE) this is a master phone table. each combination of phone number and type has a unique identifier-phone_id.
What i need to figure out is how to populate PHONE_CONNECT with the information from TEMP_PHONE IF PERSON_ID already exists but phone_id is different. In other words, if the person gets a new phone number, i need to insert a new row into phone_connect.
Before that step is started, the master_phone is populated first with a new phone_id associated to the phonenumber/type
any help would be much appreciated. Thanks in advance.
So far, this is what i have come up with, but not sure if it makes sense:
insert into phone_connect(person_id)
select a.person_id
from temp_phone a
where
person_id = (select b.person_id from phone_connect b, master_phone c
where
a.person_id=b.person_id
and b.phone_id <> c.phone_id
and c.phonenumber||c.phone_type=a.phonenumber||a.phone_type);
update phone_connect c
set phone_id=(
select b.phone_id
from temp_phone a, master_phone b
where a.person_id = c.person_id
and a.phonenumber||a.phone_type = b.phonenumber||b.phone_type)
where phone_id is null;It does. You are right. But that's what i need help with. I don't think my code is correct. After the insert, the code is actually updating the same exact record I just inserted. I'm sure this all can be done with one insert. I just really don't know how to show that in my code.
I need to insert a new record into phone_connect with person_id and phone_id. phone_id is already populated in master_phone. I guess my problem is how to go about creating the joins to all three tables to make sure im inserting the data correctly, or not inserting data that already exists. -
INSERT INTO TABLE using SELECT takes long time
Hello Friends,
--- Oracle version 10.2.0.4.0
--- I am trying to insert around 2.5 lakhs records in a table using INSERT ..SELECT. The insert takes long time and seems to be hung.
--- When i try to SELECT the query fetches the rows in 10 seconds.
--- Any clue why it is taking so much timevishalrs wrote:
Hello Friends,hello
>
>
--- Oracle version 10.2.0.4.0
alright
--- I am trying to insert around 2.5 lakhs records in a table using INSERT ..SELECT. The insert takes long time and seems to be hung.
I don't know how a lakh is, but it sounds like a lot...
--- When i try to SELECT the query fetches the rows in 10 seconds.
how did you test this? and did you fetch the last record, or just the first couple of hundred.
--- Any clue why it is taking so much timeWithout seeing anything, it's impossible to tell the reason.
Search the forum for "When your query takes too long" -
i am not able to read text file in 10g forms. using webutil.pll and webutil.lib
here i posted the code . i am not getting message 2, client_text_io.fopen is not working what could be the reason.
DECLARE
in_file client_TEXT_IO.FILE_TYPE;
V_LINE_COUNT number;
linebuf VARCHAR2(1800);
V_var1 varchar2(80);
V_var2 varchar2(80);
V_var3 varchar2(80);
V_var4 varchar2(80);
V_var5 varchar2(80);
filename VARCHAR2(30);
l_var number;
blnRet BOOLEAN;
begin
DELETE FROM NIRU_TEMP;
:file_path:=LTRIM(RTRIM(:file_path));
MESSAGE('1');
in_file := client_text_io.fopen(UPPER(:file_path),'r');
MESSAGE('2');
loop
V_LINE_COUNT := V_LINE_COUNT + 1;
client_text_io.get_line(in_file,linebuf);
MESSAGE('5');
V_var1 := substr(linebuf,1,(instr(linebuf,',')-1)) ;
MESSAGE('6'||V_VAR1);
MESSAGE('6'||V_VAR1);
l_var := length(v_var1);
V_var2 := substr(linebuf,l_var+2,(instr(linebuf,','))) ;
--V_var3 := substr(linebuf,15 ,10 );
V_var2 :=LTRIM(RTRIM(V_var2));
MESSAGE('6'||V_var2);
MESSAGE('6'||V_var2);
:p_id := v_var1;
:p_desc :=v_var2;
--IF V_var2 = '' THEN
--V_var3 :='';
--else
--V_var3 := TO_NUMBER(V_var2) ;
--end if;
--V_var5 := substr(linebuf,26 ,70 );
INSERT INTO NIRU_TEMP VALUES (V_var1,V_var2);
client_text_io.new_line;
:System.Message_Level := '20';
commit;
:System.Message_Level := '0';
--<<end_loop>>
--null;
next_record;
end loop;
client_TEXT_IO.FCLOSE(in_file);
exception
WHEN OTHERS THEN
MESSAGE('ERROR'||SQLCODE||' '||SQLERRM);
--exit;
end;Hello Francois,
You have a solution for this problem?
I have a problem like this. While reading a text file, such as size of 7MB, long, between 15-30 minutes.
See...
declare
arq client_text_io.file_type;
linha varchar2(800);
v_total number := 0;
v_icms number := 0;
begin
:valor_total := 0;
:valor_icms := 0;
arq := client_text_io.fopen(:arquivo,'r');
loop
client_text_io.get_line(arq,linha);
if substr(linha,1,1) = '1' then
v_total := v_total + (to_number(substr(linha,302,13))/100);
v_icms := v_icms + (to_number(substr(linha,262,13))/100);
end if;
end loop;
client_text_io.fclose(arq);
exception
when no_data_found then
:valor_total := v_total;
:valor_icms := v_icms;
message('Realizado com sucesso!');
message('Realizado com sucesso!');
end; -
How to extract data from text file to database table
Hi ,
I am trying to upload data in text file to database table using GUI_UPLOAD function .what would be the program for that.
thanks in advance.Hi,
I don't think you have a standard sap program to upload data from file to database table...
Instead you can create a custom program like this..
DATA: T_FILEDATA(1000) OCCURS 0 WITH HEADER LINE.
DATA: T_ZTABLE LIKE ZTABLE OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\TEST.TXT'
tables
data_tab = T_FILEDATA
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT T_FILEDATA.
T_ZTABLE = T_FILEDATA.
APPEND T_ZTABLE.
ENDLOOP.
MODIFY ZTABLE FROM TABLE T_ZTABLE.
COMMIT WORK..
Thanks,
Naren -
How to read text file contain chinese character ?
Hi XI Expert,
I have scenario to read text file contain Chinese Character using sender file adapter. but every i was check from sxmb_moni all the chinese character looks different. and also the target file also i has changes.
Please advise me how to maintaine the chinese character in PI 7.0 SP17.
Thank You and Best Regards
FernandHi,
Refer these threads..
Receiver file adapter corrupting characters
Problem in converting special characters in input text file
Here is one more useful guide..
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42
Regards,
Sarvesh
Edited by: Sarvesh Singh on Nov 17, 2008 3:47 PM -
HOW TO READ DATA FROM A FILE AND INSERT INTO A TABLE USING UTL_FILE
Hi..
I have a file.I want to read the data from file and load it into a table using utl_file.
how can I do it?
Any reply apreciated...Hi,
This is not your requirment but u can try this :
CREATE OR REPLACE DIRECTORY text_file AS 'D:\TEXT_FILE\';
GRANT READ ON DIRECTORY text_file TO fah;
GRANT WRITE ON DIRECTORY text_file TO fah;
DROP TABLE load_a;
CREATE TABLE load_a
(a1 varchar2(20),
a2 varchar2(200))
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY text_file
ACCESS PARAMETERS
(FIELDS TERMINATED BY ','
LOCATION ('data.txt')
select * from load_a;
CREATE TABLE A AS select * from load_a;
SELECT * FROM A
Regards
Faheem Latif -
How can one read a Excel File and Upload into Table using Pl/SQL Code.
How can one read a Excel File and Upload into Table using Pl/SQL Code.
1. Excel File is on My PC.
2. And I want to write a Stored Procedure or Package to do that.
3. DataBase is on Other Server. Client-Server Environment.
4. I am Using Toad or PlSql developer tool.If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
1. Get your DBA to create directory object in oracle using the following command:
create directory TEST_DIR as ‘directory_path’;
Note: This directory is on the server.
2. Grant read,write on directory directory_object_name to username;
You can find out the directory_object_name value from dba_directories view if you are using the system user account.
3. Logon as the user as mentioned above.
Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
function getData(p_filename in varchar2,
p_filepath in varchar2
) RETURN VARCHAR2 is
input_file utl_file.file_type;
--declare a buffer to read text data
input_buffer varchar2(4000);
begin
--using the UTL_FILE in built package
input_file := utl_file.fopen(p_filepath, p_filename, 'R');
utl_file.get_line(input_file, input_buffer);
--debug
--dbms_output.put_line(input_buffer);
utl_file.fclose(input_file);
--return data
return input_buffer;
end;
Hope this helps. -
To read text file using utl_file
I would like to read test_file_out.txt which is in c:\temp folder.
create or replace create or replace directory dir_temp as 'c:\temp';
grant read, write on directory dir_temp to system;
then when i execute the below code i get the error .
// to read text file using utl_file
DECLARE
FileIn UTL_FILE.FILE_TYPE;
v_sql VARCHAR2 (1000);
BEGIN
FileIn := UTL_FILE.FOPEN ('DIR_TEMP', 'test_file_out.txt', 'R');
UTL_FILE.PUT_LINE (FileIn, v_sql);
dbms_output.put_line(v_sql);
UTL_FILE.FCLOSE (FileIn);
END;
ERROR:
invalid file operation
i would like to use ult_file only and also can you let me know to read the text file and place its contents in tmp_emp table?Are you trying to read the contents of the file into the local variable? Or write the contents of the local variable to the file?
Your text talks about reading the file. And you open the file in read mode. But then you call the UTL_FILE.PUT_LINE method which, as SomeoneElse points out, attempts to write data to the file. Since the file is open in read-only mode, you cannot write to the file.
If the goal is really to read from the file, replace the UTL_FILE.PUT_LINE calls with UTL_FILE.GET_LINE. If the goal is really to write to the file, you'll need to open the file in write mode ('W' rather than 'R' in the FOPEN call).
Justin
Maybe you are looking for
-
Mac Pro 2.66 ghz, Intel Core 2 duo Upgradeability
I want to purchase a 2.66ghz Mac pro, now in my price point, but want to know if I can upgrade the Procs from the TWO Dual cores to two Quads to make an 8 core sometime next year. Can the existing MOBO handle this upgrade or do I have to replace it?
-
Message is incomplete. No Sender found ( in BPM )
Hi my scenario is as follows BPM: receive Send Transform Synchronous Send Transform Send I'm getting error in Synch Send as <i>Message is incomplete. No Sender found</i> I checked receiver Determinations and Interface Determinations and everything
-
Can't export to tape on Premier Pro CS4 Extended
When I attempt to export to tape from Premier Pro CS4 Extended, version 4.1.0, to a DV Cam, the tape rolls and records (with device control) but I get no video or audio. I have: -selected the timeline for the sequence -the work area bar is over the e
-
Hi, I am trying to execute my print program but i am getting error that "FM called wrongly" . My requirement is i want to display vendor details using smartforms.For this i took internal table with 5 fields.There is no syntactical errors in the progr
-
PI/XI for Tendering functionalities
We have a requirement for simple bidding with C-folders (tendering process) in SRM (Two-Stage:Two-Envelope bidding procedure) but we dont have PI/XI. is it possible to do this functionalitiy in SAP SRM 7.0 without PI/XI ? Regards Mihir