473,666 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pipe delimitating function

75 New Member
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



Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.  start_date VARCHAR2(20);
  3.  end_date VARCHAR2(20);
  4.  filename    VARCHAR2(1000);
  5.  input_file   utl_file.file_type;
  6.  input_buffer INTEGER;
  7.  vNewLine  VARCHAR2(1000);
  8.  BEGIN
  9.        input_file := utl_file.fopen ('/tmp','ADDER_GENEVA_REVENUE_REQUEST_23102007121005.    dat', 'R');
  10.        utl_file.get_line(input_file,vNewLine);
  11.          LOOP
  12.          EXIT WHEN LENGTH(vNewLine) <= 0);
  13.          dbms_output.put_line(vNewLine);
  14.          IF(LENGTH(vNewLine) > 13) THEN          
  15.          start_date := SUBSTR(vNewLine,5,8);
  16.          end_date:= SUBSTR(vNewLine,14,8);
  17.           INSERT INTO  am_test VALUES(start_date,end_date);
  18.           COMMIT;
  19.          END IF;
  20.          vNewLine:= NULL;
  21.         start_date:= NULL;
  22.         end_date:= NULL;
  23.          END LOOP;
  24.       EXCEPTION
  25.          WHEN OTHERS THEN
  26.                  utl_file.fclose(input_file);
  27.       END;
  28.  
Jan 18 '08 #1
16 2252
amitpatel66
2,367 Recognized Expert Top Contributor
Try this:

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.  start_date VARCHAR2(20);
  3.  end_date VARCHAR2(20);
  4.  filename    VARCHAR2(1000);
  5.  input_file   utl_file.file_type;
  6.  input_buffer INTEGER;
  7.  vNewLine  VARCHAR2(1000);
  8.  BEGIN
  9.        input_file := utl_file.fopen ('/tmp','ADDER_GENEVA_REVENUE_REQUEST_23102007121005.    dat', 'R');
  10.        utl_file.get_line(input_file,vNewLine);
  11.          LOOP
  12.          EXIT WHEN LENGTH(vNewLine) <= 0);
  13.          dbms_output.put_line(vNewLine);
  14.          start_date := SUBSTR(vNewLine,INSTR(vNewLine,'|',1,1) + 1, 8);
  15.          end_date:= SUBSTR(vNewLine,INSTR(vNewLine,'|',1,2) + 1,8);
  16.           IF(start_date IS NOT NULL AND end_Date IS NOT NULL) THEN
  17.           INSERT INTO  am_test VALUES(start_date,end_date);
  18.           COMMIT;
  19.          END IF;
  20.          vNewLine:= NULL;
  21.         start_date:= NULL;
  22.         end_date:= NULL;
  23.          END LOOP;
  24.       EXCEPTION
  25.          WHEN OTHERS THEN
  26.                  utl_file.fclose(input_file);
  27.       END;
  28.  
Jan 18 '08 #2
orajit
75 New Member
Thanks for ur solution .. its working ...:)
Jan 18 '08 #3
amitpatel66
2,367 Recognized Expert Top Contributor
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
Jan 18 '08 #4
orajit
75 New Member
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.
Feb 6 '08 #5
amitpatel66
2,367 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1.  
  2. DECLARE
  3.  start_date VARCHAR2(20);
  4.  end_date VARCHAR2(20);
  5.  acct_num VARCHAR2(20);
  6.  filename    VARCHAR2(1000);
  7.  input_file   utl_file.file_type;
  8.  input_buffer INTEGER;
  9.  vNewLine  VARCHAR2(1000);
  10.  BEGIN
  11.        input_file := utl_file.fopen ('/tmp','ADDER_GENEVA_REVENUE_REQUEST_23102007121005.      dat', 'R');
  12.        utl_file.get_line(input_file,vNewLine);
  13.          LOOP
  14.          EXIT WHEN LENGTH(vNewLine) <= 0);
  15.          dbms_output.put_line(vNewLine);
  16.          start_date := SUBSTR(vNewLine,INSTR(vNewLine,'|',1,1) + 1, 8);
  17.          end_date:= SUBSTR(vNewLine,INSTR(vNewLine,'|',1,2) + 1,8);
  18.          acct_num:= SUBSTR(vNewLine,INSTR(vNewLine,'|',1,3) + 1,INSTR(vNewLine,'|',1,4)-1);
  19.           IF(start_date IS NOT NULL AND end_Date IS NOT NULL AND acct_num IS NOT NULL) THEN
  20.           INSERT INTO  am_test VALUES(start_date,end_date,acct_num);
  21.           COMMIT;
  22.          END IF;
  23.          vNewLine:= NULL;
  24.         start_date:= NULL;
  25.         end_date:= NULL;
  26.         acct_num:= NULL;
  27.          END LOOP;
  28.       EXCEPTION
  29.          WHEN OTHERS THEN
  30.                  utl_file.fclose(input_file);
  31.       END;
  32.  
  33.  
Feb 6 '08 #6
orajit
75 New Member
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


Expand|Select|Wrap|Line Numbers
  1. ..
  2. declare 
  3.       vl_c_vNewLine varchar2  (1000):='001|R|21152007|23102007|GP11223344|B|LION';
  4.       v_in varchar2(1000);
  5. begin 
  6.       select SUBSTR(vl_c_vNewLine,INSTR(vl_c_vNewLine,'|',1,3) + 1,INSTR(vl_c_vNewLine,'|',1,4)-1)
  7.       into v_in from dual ;
  8.       dbms_output.put_line(v_in);
  9. end ;
  10.  
Feb 7 '08 #7
amitpatel66
2,367 Recognized Expert Top Contributor
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. declare 
  3.       vl_c_vNewLine varchar2  (1000):='001|R|21152007|23102007|GP11223344|B|LION';
  4.       v_in varchar2(1000);
  5. begin 
  6.       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)
  7.       into v_in from dual ;
  8.       dbms_output.put_line(v_in);
  9. end ;
  10.  
Feb 7 '08 #8
orajit
75 New Member
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
Feb 8 '08 #9
debasisdas
8,127 Recognized Expert Expert
Why don't you use SQL * Loader.
Feb 8 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
12145
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
7
3700
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!
4
7817
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...
0
1436
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(),...
1
2613
by: Lewap | last post by:
Hi! I've piece of code like follow: <code> LPTSTR lpszPipename = (LPTSTR) "\\\\.\\pipe\\testpipe"; hPipe = CreateNamedPipe(
2
5058
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...
2
1664
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
1
2019
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. ...
0
8454
marktang
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...
0
8362
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,...
0
8878
Oralloy
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...
0
8785
jinu1996
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...
0
7389
agi2029
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...
1
6200
isladogs
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...
0
5671
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();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.