Jump to content

substring load data infile


edwardoit

Recommended Posts

hi all,

 

guys, question:

 

how can i use "load data infile" with mysql only not php code.

regarding this "load data infile", can i use substring to upload my files???

example: this single line from my file consists of 9 fields... 

 

0001GB000020000300050006700070008000100020040050060007008

 

so it would store something like this:

 

0001GB 000020000 3000 500067 00070008 0001 0002004 00500 60007008

 

thanks in advance...

Link to comment
https://forums.phpfreaks.com/topic/93073-substring-load-data-infile/
Share on other sites

Thanks for the reply men...

 

but i just newly read this somewhere else. maybe this would help others too

 

it says something like this:

 

- CREATE TABLE temp_data (dataline VARCHAR(255));

- LOAD DATA INFILE 'data.txt' INTO TABLE temp_data
FIELDS TERMINATED BY '' ENCLOSED BY '';

INSERT INTO test (server_time, usr, sys, wio, idle)
SELECT
TRIM( SUBSTRING(dataline, 1,  ),
TRIM( SUBSTRING(dataline, 9,  ),
TRIM( SUBSTRING(dataline, 17,  ),
TRIM( SUBSTRING(dataline, 25,  ),
TRIM( SUBSTRING(dataline, 33,  )
FROM temp_data;

TRUNCATE TABLE temp_data;

 

Good luck to me.  8)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.