Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

import text file into oracle db.

Posted on 2000-05-15
19
Medium Priority
?
226 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1200 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

876 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