I have created one file
c;/temp/test.txt
000|23102007
001| 21102007|231020 07|GB11223344
001| 20102007|221020 07|GB11223345
001| 19102007|221020 07|GB11223346
999|3
The highlighted text are started date and end date and account number .
Suppose I wanted to insert the date into am_test the from the test.txt by using following code
I dont wanted to use hardcoded values in my code means
IF(LENGTH(vNewL ine) > 13) THEN ... like this
I wanted to insert '|' seperated values in my table .
cud u please tell me how to to it .
Thnaks -
DECLARE
-
start_date VARCHAR2(20);
-
end_date VARCHAR2(20);
-
filename VARCHAR2(1000);
-
input_file utl_file.file_type;
-
input_buffer INTEGER;
-
vNewLine VARCHAR2(1000);
-
BEGIN
-
input_file := utl_file.fopen ('/tmp','ADDER_GENEVA_REVENUE_REQUEST_23102007121005. dat', 'R');
-
utl_file.get_line(input_file,vNewLine);
-
LOOP
-
EXIT WHEN LENGTH(vNewLine) <= 0);
-
dbms_output.put_line(vNewLine);
-
IF(LENGTH(vNewLine) > 13) THEN
-
start_date := SUBSTR(vNewLine,5,8);
-
end_date:= SUBSTR(vNewLine,14,8);
-
INSERT INTO am_test VALUES(start_date,end_date);
-
COMMIT;
-
END IF;
-
vNewLine:= NULL;
-
start_date:= NULL;
-
end_date:= NULL;
-
END LOOP;
-
EXCEPTION
-
WHEN OTHERS THEN
-
utl_file.fclose(input_file);
-
END;
-
16 2252
Try this: -
DECLARE
-
start_date VARCHAR2(20);
-
end_date VARCHAR2(20);
-
filename VARCHAR2(1000);
-
input_file utl_file.file_type;
-
input_buffer INTEGER;
-
vNewLine VARCHAR2(1000);
-
BEGIN
-
input_file := utl_file.fopen ('/tmp','ADDER_GENEVA_REVENUE_REQUEST_23102007121005. dat', 'R');
-
utl_file.get_line(input_file,vNewLine);
-
LOOP
-
EXIT WHEN LENGTH(vNewLine) <= 0);
-
dbms_output.put_line(vNewLine);
-
start_date := SUBSTR(vNewLine,INSTR(vNewLine,'|',1,1) + 1, 8);
-
end_date:= SUBSTR(vNewLine,INSTR(vNewLine,'|',1,2) + 1,8);
-
IF(start_date IS NOT NULL AND end_Date IS NOT NULL) THEN
-
INSERT INTO am_test VALUES(start_date,end_date);
-
COMMIT;
-
END IF;
-
vNewLine:= NULL;
-
start_date:= NULL;
-
end_date:= NULL;
-
END LOOP;
-
EXCEPTION
-
WHEN OTHERS THEN
-
utl_file.fclose(input_file);
-
END;
-
Thanks for ur solution .. its working ...:)
Thanks for ur solution .. its working ...:)
You are welcome!! :)
I would like you to go through the POSTING GUIDELINES which would help you understand how to make use of CODE TAGS and many other forum guidelines which needs to be followed while posting in this forum!!
MODERATOR
Re: utl_file
--------------------------------------------------------------------------------
if i have my txt file as shown below ...
000|23102007
001|R|21102007| 23102007|GD1121 12111|B|LIss
001|R|20102007| 22102007|GD112| B|WOss
001|R|19102007| 22102007|GD1133 34444223346||WO ss
001|R|19102007| 22102007|GD111| |WOss
001|R|19102007| 22102007|GD1133 44||WOss
999|5
Now i wanted to read and insert account number using above code ... The account number is shown as bold (GD133331223344 ,GD112 etc)
Could u please advice me how to do it.
-
-
DECLARE
-
start_date VARCHAR2(20);
-
end_date VARCHAR2(20);
-
acct_num VARCHAR2(20);
-
filename VARCHAR2(1000);
-
input_file utl_file.file_type;
-
input_buffer INTEGER;
-
vNewLine VARCHAR2(1000);
-
BEGIN
-
input_file := utl_file.fopen ('/tmp','ADDER_GENEVA_REVENUE_REQUEST_23102007121005. dat', 'R');
-
utl_file.get_line(input_file,vNewLine);
-
LOOP
-
EXIT WHEN LENGTH(vNewLine) <= 0);
-
dbms_output.put_line(vNewLine);
-
start_date := SUBSTR(vNewLine,INSTR(vNewLine,'|',1,1) + 1, 8);
-
end_date:= SUBSTR(vNewLine,INSTR(vNewLine,'|',1,2) + 1,8);
-
acct_num:= SUBSTR(vNewLine,INSTR(vNewLine,'|',1,3) + 1,INSTR(vNewLine,'|',1,4)-1);
-
IF(start_date IS NOT NULL AND end_Date IS NOT NULL AND acct_num IS NOT NULL) THEN
-
INSERT INTO am_test VALUES(start_date,end_date,acct_num);
-
COMMIT;
-
END IF;
-
vNewLine:= NULL;
-
start_date:= NULL;
-
end_date:= NULL;
-
acct_num:= NULL;
-
END LOOP;
-
EXCEPTION
-
WHEN OTHERS THEN
-
utl_file.fclose(input_file);
-
END;
-
-
If use ur code for account number
SUBSTR(vl_c_vNe wLine,INSTR(vl_ c_vNewLine,'|', 1,3) + 1,INSTR(vl_c_vN ewLine,'|',1,4)-1)
Then it will give me output as 23102007|GP1122 3344|B|L
I wanted only GP11223344..cou ld u plz tell me how to find it - ..
-
declare
-
vl_c_vNewLine varchar2 (1000):='001|R|21152007|23102007|GP11223344|B|LION';
-
v_in varchar2(1000);
-
begin
-
select SUBSTR(vl_c_vNewLine,INSTR(vl_c_vNewLine,'|',1,3) + 1,INSTR(vl_c_vNewLine,'|',1,4)-1)
-
into v_in from dual ;
-
dbms_output.put_line(v_in);
-
end ;
-
Try this: -
-
declare
-
vl_c_vNewLine varchar2 (1000):='001|R|21152007|23102007|GP11223344|B|LION';
-
v_in varchar2(1000);
-
begin
-
select SUBSTR(vl_c_vNewLine,INSTR(vl_c_vNewLine,'|',1,4) + 1,(INSTR(vl_c_vNewLine,'|',1,5) - INSTR(vl_c_vNewLine,'|',1,4))-1)
-
into v_in from dual ;
-
dbms_output.put_line(v_in);
-
end ;
-
First of all Thanks for your valuable solution and time for my question related to UTL_FILE.
Sir, I am facing one problem . I wanted to build a procedure that will give me Pipe delimitating values and insert it in the table .
I am giving you the same example .suppose I have text file called pile.txt and that contains following info
000|23102007 ----header
001|R|21102007| 23102007|GP1122 3344|B|LION
001|R|20102007| 22102007|GP1122 3345|B|WOMBAT
001|R|19102007| 22102007|GP1122 3346||WOMBAT
999|3 ---footer
Now I wanted to store each pipe separated value including null in a variable and insert into the table (except header and footer).
Could you Please suggest and function that will give me '|' (pipe) separated values .
Please advice .. Looking for your valuable advice once again ,,,
Thanks
Why don't you use SQL * Loader.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Frank de Bot |
last post by:
Hi,
occasionaly I find in my apache logs that fastcgi had a broken pipe
error with php running as fastcgi. the logs are like this:
--
> (32)Broken pipe:
> FastCGI: comm with server /opt/guide/ppi.searchy.net/cgi-bin/php.fcgi"
> aborted: write failed
> FastCGI: incomplete
|
by: Greg |
last post by:
I am trying to implement the UNIX pipe command using C but with the
"->" operator. Everything works fine with 1 pipe, but when I try to
use 2 or more, it hangs up when reading the pipe_in filestream. If
ANYONE could offer ANY suggestion as to why this is happening it would
be much appreciated.
Thanks in advance!
|
by: bill |
last post by:
I am confused by the behavior of the following code. The function
copy() takes two FILE *'s and copies the data from one to the other.
In the main routine, I create a pipe and copy stdin to the write end
while copying the read end to stdout. If the child handles copying the
read end of the pipe to stdout, the main program returns. If the child
handles copying stdin to the write end of the pipe, the parent hangs in
copy(), blocking on...
|
by: Nick |
last post by:
hi,all
I have a question about named pipe.
How does the pipe server know the client closed the connection?
We can refer the example for CreateNamedPipe() function in MSDN.
In block mode, once ConnectNamedPipe() returns, it means the client
called CreateFile(),
and after finish reading and writing, client call CloseHandle(), at
this point, how does the pipe server know the pipe has been closed? And
if client did not call CloseHandle(),...
|
by: Lewap |
last post by:
Hi!
I've piece of code like follow:
<code>
LPTSTR lpszPipename = (LPTSTR) "\\\\.\\pipe\\testpipe";
hPipe = CreateNamedPipe(
| |
by: FB's .NET Dev PC |
last post by:
I am writing two services in VB.NET, one of which needs to send text strings
to the other. After reading, I
decided (perhaps incorrectly) that named pipes would be the best
interprocess communication method
for this task.
I set about creating, on the pipe's server side, a new thread which would
instantiate a blocking inbound message pipe, and the
client side which would write to that pipe when needed. Being on the same
PC, security is...
|
by: Steve R. Hastings |
last post by:
While studying iterators and generator expressions, I started wishing I
had some tools for processing the values. I wanted to be able to chain
together a set of functions, sort of like the "pipelines" you can make
with command-line programs.
So, I wrote a module called iterwrap.py. You can download it from here:
http://home.blarg.net/~steveha/iterwrap.tar.gz
|
by: bmwz8 |
last post by:
I am trying to implement 3 pipe functions in Windows NT environment.
There are to be multiple pipes with a buffer size of 32 characters. I
am to implement mypipe(), myread(), and mywrite() calls. Also create
multiple readers and writers in threads that use the pipe. I already
have the function prototype setup, I just
need an idea or direction on where to go about to begin implementing
the functions. Any help would be greatly appreciated.
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |