Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

import text file into oracle db.

Posted on 2000-05-15
19
210 Views
Last Modified: 2012-05-04
Ok, i want to import text file into oracle database table with php script.
Text file format is:
---
010101
blabla1
blabla2
010102
blabla2
blabla4
---
010101 / 010102 = ID
text which is under ID number is included into this ID group.

in db table i need to get:

ID        TEXT
-------------------
010101     blabla1
010101     blabla2
010102     blabla3
010102     blabla4

and so on..

how can I do it? any sample code?

thank you.
kristapz.
0
Comment
Question by:kristapz
  • 10
  • 8
19 Comments
 

Author Comment

by:kristapz
ID: 2810524
Adjusted points from 200 to 300
0
 
LVL 1

Expert Comment

by:olegtim
ID: 2814432
us111 where are you? we need you here :)
0
 

Author Comment

by:kristapz
ID: 2814476
hey..
noone can help me ?
please.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:us111
ID: 2814554
I don't try, get the idea:

<?
$tab = file("your_file.txt");   // get the file into an array

$n = count($tab) ;

for ($i=0; $i<$n; $i=+3)
{ $ID = $tab[$i];
   $Text1 = $tab[$i+1];
   $Text2 = $tab[$i+2];
   
   $query = "INSERT INTO table (ID, Text) values ('$ID', '$Text1');
   // execute the query, your stuff
   $query = "INSERT INTO table (ID, Text) values ('$ID', '$Text2');
   // execute the query, your stuff
}
?>

Sorry, never use Oracle functions....
0
 

Author Comment

by:kristapz
ID: 2814721
but problem is that there is no only two records under each id. there can be 10.. 100 or 1000 records. i don't know how many they are under each id.

0
 
LVL 8

Expert Comment

by:us111
ID: 2815267
I will try to find out a solution
0
 
LVL 8

Expert Comment

by:us111
ID: 2816505
could you change you text file ?
what's the good format for your ID ?
0
 
LVL 8

Expert Comment

by:us111
ID: 2816513
By changing your text file, I mean something like this :

010101
blabla1
blabla2
~~~~
010102
blabla2
blabla4
~~~~
010103
blabla2
blabla4
0
 

Author Comment

by:kristapz
ID: 2816577
hmm, well.. these IDs i need to replace with other IDs when imported.. like:
010101 replace with 942, 010102 with 965 and so on..

what about changing this file..
it's big..
i suppose this ~~~ can be inserted with some shell script.. but i'm not strong in unix shell scripts so i don't know how to do it..

 & i can insert these lines if it will change something.

i used command file() to add all lines in array.. but i couldn't find any way how to check when starts one id and when other..
result was: 480 000 rows with first line from script in db :)


regards,
kristapz.
0
 
LVL 8

Expert Comment

by:us111
ID: 2817242
if you want to avoid ~~~ (separator as example)
I need to know the exact format of the ID in the text file
010101.
always 6 numbers ?
Can  'blabla' be 6 numbers like ID?
The solution is to know the format of the ID in your textfile.
Then you can detect  when the line starts a new ID.
0
 

Author Comment

by:kristapz
ID: 2817520
length(id) = 6. allways.
length(text) > 6. allways.

blabla is text, not number.

0
 

Author Comment

by:kristapz
ID: 2817683
length(id) = 6. allways.
length(text) > 6. allways.

blabla is text, not number.

0
 
LVL 8

Expert Comment

by:us111
ID: 2817958
<?
$f = fopen("yourfile.txt", "r");
$LENGHT = 6 + 2;  // carriage

$ID = fgets($f, 4096);
while (!feof($f))
{      $text = fgets($f, 4096);
      
      while (!feof($f) && strlen($text) > $LENGHT)
      {      //$query = "INSERT INTO table (ID, Text) values ('$ID', '$Text')";
            // Execute the oracle query, I don't know how...
            print "$ID  : $text<br>";
            $text = fgets($f, 4096);
    }
      $ID = $text;
}
fclose($f);
?>


will output
010101     blabla1
010101     blabla2
010102     blabla3
010102     blabla4
0
 

Author Comment

by:kristapz
ID: 2818082

Thank you, us111. This worked fine. :)
0
 

Author Comment

by:kristapz
ID: 2818088
This question has a deletion request Pending
0
 
LVL 8

Expert Comment

by:us111
ID: 2818098
This question no longer is pending deletion
0
 
LVL 8

Accepted Solution

by:
us111 earned 300 total points
ID: 2818099
Hey !! deletion request ???
And my point for this answer :)
don't forget :)
0
 

Author Comment

by:kristapz
ID: 2819299
ouh.. sorry.. :(
didn't really get this system.
i thought i need to delete this question..
ok.. nevermind :)

So, what i need to do so as you can get your points?
0
 

Author Comment

by:kristapz
ID: 2819302
oh.. **** :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fulfillment API php code sample 1 58
Google Maps API and PHP 25 49
Moving from Mcrypt to OpenSSL 18 45
PHP error function not working on AWS 10 69
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question