Using the LOAD DATA LOCAL INFILE
num column Store every 6 digits
How can I parameterize the load command to iterate through the array?
Mysql version 8.0.23
In File text
id length 1,
cnt length 2,
num length 500
--------------------
1 3AB1001AB1002AB1003
table A
id | cnt | num |
---|---|---|
1 | 3 | AB1001AB1002AB1003 |
i want output like this table
table B
id | cnt | num |
---|---|---|
1 | 3 | AB1001 |
1 | 3 | AB1002 |
1 | 3 | AB1003 |
2
Answers
You can use a trigger to split a row from table ‘a’ into 3 rows for ‘b’.
The trigger is following:
Before insert data using the LOAD DATA LOCAL INFILE, you have to create a trigger on table ‘a’.
Regards.
I was able to test this table:
I put the line of text you show into a file
p.csv
:I ran the mysql client with the option to enable local data loading:
Then I loaded the data file this way:
It worked!
Read more about the LOAD DATA INFILE statement here: https://dev.mysql.com/doc/refman/8.0/en/load-data.html
And read about the SUBSTR() function here: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substr