Solved

import text file into oracle db.

Posted on 2000-05-15
19
224 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
[X]
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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

617 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