MySQL Forums
Forum List  »  General

How to add multiple rows and colums from a datafile?
Posted by: Bjarke Sandbeck
Date: December 11, 2011 12:37PM

Hello

I'm trying to find out how I can insert data from an ASCII file, that contain serval informations wich I need, and even more wich I don't need.
It's not a CVS file, and I can't get the file as CVS.

What I in theory want to do is:

---

LOAD DATA LOCAL INFILE '/home/userdir/txt.file' INTO TABLE db1.product_table
FIELDS TERMINATED BY '00I\r\n' ENCLOSED BY ''
LINES TERMINATED BY '\r\n' STARTING BY '00I\r\n01' (product_id),
LINES TERMINATED BY '\r\n' STARTING BY '00I\r\n01' (product_sku),
LINES TERMINATED BY '\r\n' STARTING BY '\r\n31' (product_s_desc),
LINES TERMINATED BY '\r\n' STARTING BY '\r\n26' (product_name);

---

My Datafile 'txt.file' looks like this (one product only):

00I

013818528

021182

031

040

05308421

061

071

081

0918

111

121

153014260308421

161

1728

18969

1920040915

2020040915

2120070601

22112

230

240

251

26GILLETTE M3POWER BLADES

2795

281

29

30

31GILLETTE M3Power Blades

32

33

341

350

361

371

401

410

420

43

4425685

45

46

47BC01B

48GILLETTE0WICKP25685M13POWERBLADES0000004ST

491

501

511

522

5399

541

552

562

572

582

592

60

61

62

631

641

651

66

67

681

69

720

74

761

771

780

790

801

811

831

85

86

870

880

891

900

911

920

930

941

950

960

97

98

990

A00

A11

For each new product, the set starts with the line "00I", and before that, there is always a ASCII CR/LF, and the next line is always starting with 01, and what comes after the "01" is my SKU number, but also need to be my ID.
Lines wich is starting with "31" right after an CR/LF, contains the short description of the product, and for each time lines starts with 26 after an CR/LF, we have the field containing our product-name.

I'm a bit lost right now, on how I can load that from my file, using the MySQL shell.

Does anyone have a hint on what I can do?


Kind Regards
Bjarke

Options: ReplyQuote


Subject
Written By
Posted
How to add multiple rows and colums from a datafile?
December 11, 2011 12:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.