Rumah > Soal Jawab > teks badan
P粉6765887382023-08-15 13:06:06
创建表test (id INT AUTO_INCREMENT PRIMARY KEY, page_name VARCHAR(64), language CHAR(2), item_id INT, item_text VARCHAR(255) );
SET @data := ' [ ["home","fr",1,"French text item 1"], ["home","fr",2,"French text item 2"], ["home","fr",3,"French text item 3"], ["home","fr",4,"French text item 4"], ["home","fr",5,"French text item 5"] ] ';
INSERT INTO test (page_name, language, item_id, item_text) SELECT page_name, language, item_id, item_text FROM JSON_TABLE(@data, '$[*]' COLUMNS ( page_name VARCHAR(64) PATH '$[0]', language CHAR(2) PATH '$[1]', item_id INT PATH '$[2]', item_text VARCHAR(255) PATH '$[3]' ) ) jsontable;
SELECT * FROM test;
id | nama_halaman | bahasa | item_id | item_text |
---|---|---|---|---|
1 | rumah | fr | 1 | Item teks bahasa Perancis 1 |
2 | rumah | fr | 2 | Item teks bahasa Perancis 2 |
3 | rumah | fr | 3 | Item teks bahasa Perancis 3 |
4 | rumah | fr | 4 | Item teks bahasa Perancis 4 |
5 | rumah | fr | 5 | Item teks bahasa Perancis 5 |