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
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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.