Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

import text file into oracle db.

Posted on 2000-05-15
19
Medium Priority
?
225 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
Industry Leaders: 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 dynamically set the form action using jQuery.

715 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