Solved

import text file into oracle db.

Posted on 2000-05-15
19
182 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now