473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Pipe delimitating function

75
I have created one file
c;/temp/test.txt

000|23102007
001|21102007|23102007|GB11223344
001|20102007|22102007|GB11223345
001|19102007|22102007|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(vNewLine) > 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 2229
amitpatel66
2,367 Expert 2GB
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
Thanks for ur solution .. its working ...:)
Jan 18 '08 #3
amitpatel66
2,367 Expert 2GB
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
Re: utl_file
--------------------------------------------------------------------------------

if i have my txt file as shown below ...


000|23102007
001|R|21102007|23102007|GD112112111|B|LIss
001|R|20102007|22102007|GD112|B|WOss
001|R|19102007|22102007|GD113334444223346||WOss
001|R|19102007|22102007|GD111||WOss
001|R|19102007|22102007|GD113344||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 Expert 2GB
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
If use ur code for account number
SUBSTR(vl_c_vNewLine,INSTR(vl_c_vNewLine,'|',1,3) + 1,INSTR(vl_c_vNewLine,'|',1,4)-1)

Then it will give me output as 23102007|GP11223344|B|L

I wanted only GP11223344..could 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 Expert 2GB
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
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|GP11223344|B|LION
001|R|20102007|22102007|GP11223345|B|WOMBAT
001|R|19102007|22102007|GP11223346||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 Expert 4TB
Why don't you use SQL * Loader.
Feb 8 '08 #10
orajit
75
No.. i dont want to use sql loader I have tried with external table also but i am facing problem with header and footer . I dont want header and footer containt in my table .
I want only highligted text to be inserted into my table .

My table has following columns
st date
end date
acc_no
flag
prod

000|23102007---header
001|R||21102007 |23102007 |GP11223344 |B |LION
999|1--footer

could u please tell me how to do this .. Is there any method by using external table ..

Thanks
Feb 8 '08 #11
amitpatel66
2,367 Expert 2GB
No.. i dont want to use sql loader I have tried with external table also but i am facing problem with header and footer . I dont want header and footer containt in my table .
I want only highligted text to be inserted into my table .

My table has following columns
st date
end date
acc_no
flag
prod

000|23102007---header
001|R||21102007 |23102007 |GP11223344 |B |LION
999|1--footer

could u please tell me how to do this .. Is there any method by using external table ..

Thanks
I think I had given you the solution in your previous thread for this requirement. You just need to modify that slightly to store the value of last two columns flag and prod.
Feb 8 '08 #12
amitpatel66
2,367 Expert 2GB
Threads merged for better management of forum

MODERATOR
Feb 8 '08 #13
orajit
75
can U please send it for flag and product ....
Feb 8 '08 #14
amitpatel66
2,367 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1.  
  2. DECLARE
  3.  start_date VARCHAR2(20):= NULL;
  4.  end_date VARCHAR2(20):= NULL;
  5.  acct_num VARCHAR2(20):= NULL;
  6.  flag VARCHAR2(2) := NULL;
  7.  prod VARCHAR2(20) := NULL;
  8.  filename    VARCHAR2(1000);
  9.  input_file   utl_file.file_type;
  10.  input_buffer INTEGER;
  11.  vNewLine  VARCHAR2(1000);
  12.  BEGIN
  13.        input_file := utl_file.fopen ('/tmp','ADDER_GENEVA_REVENUE_REQUEST_23102007121005.        dat', 'R');
  14.        utl_file.get_line(input_file,vNewLine);
  15.          LOOP
  16.          EXIT WHEN LENGTH(vNewLine) <= 0);
  17.          dbms_output.put_line(vNewLine);
  18.          start_date := SUBSTR(vNewLine,INSTR(vNewLine,'|',1,1) + 1, 8);
  19.          end_date:= SUBSTR(vNewLine,INSTR(vNewLine,'|',1,2) + 1,8);
  20.          acct_num:= SUBSTR(vl_c_vNewLine,INSTR(vl_c_vNewLine,'|',1,4) + 1,(INSTR(vl_c_vNewLine,'|',1,5) - INSTR(vl_c_vNewLine,'|',1,4))-1);
  21.          flag:= SUBSTR(vl_c_vNewLine,INSTR(vl_c_vNewLine,'|',1,5) + 1,(INSTR(vl_c_vNewLine,'|',1,6) - INSTR(vl_c_vNewLine,'|',1,5))-1);
  22.          prod:= SUBSTR(vl_c_vNewLine,INSTR(vl_c_vNewLine,'|',1,6) + 1,(INSTR(vl_c_vNewLine,'|',1,7) - INSTR(vl_c_vNewLine,'|',1,6))-1);
  23.           --IF(start_date IS NOT NULL AND end_Date IS NOT NULL AND acct_num IS NOT NULL) THEN
  24.           INSERT INTO  am_test VALUES(start_date,end_date,acct_num,flag,prod);
  25.           COMMIT;
  26.          --END IF;
  27.          vNewLine:= NULL;
  28.         start_date:= NULL;
  29.         end_date:= NULL;
  30.         acct_num:= NULL;
  31.         flag:= NULL;
  32.         prod:= NULL;
  33.          END LOOP;
  34.       EXCEPTION
  35.          WHEN OTHERS THEN
  36.                  utl_file.fclose(input_file);
  37.       END;
  38.  
Feb 8 '08 #15
orajit
75
Thank You very much ..I am ending the discussion for UTL_FILE :)

Thanks for your help for all ..
Feb 8 '08 #16
amitpatel66
2,367 Expert 2GB
Thank You very much ..I am ending the discussion for UTL_FILE :)

Thanks for your help for all ..
You are welcome any time :)

MODERATOR
Feb 8 '08 #17

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

Similar topics

2
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...
7
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...
4
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...
0
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...
1
by: Lewap | last post by:
Hi! I've piece of code like follow: <code> LPTSTR lpszPipename = (LPTSTR) "\\\\.\\pipe\\testpipe"; hPipe = CreateNamedPipe(
2
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...
2
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...
1
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.