将 JSON 插入 MySQL 表中?
让我们创建一个表,并设置一个类型为 JSON 的列值
mysql> create table DemoTable1832 ( ListOfNames JSON ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1832(ListOfNames) values('["Sam", "Mike", "Carol"]'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1832(ListOfNames) values('["David", "Bob"]'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1832(ListOfNames) values('["Adam", "John","Sam"]'); Query OK, 1 row affected (0.00 sec)
使用 select 语句从表中显示所有记录 −
mysql> select * from DemoTable1832;
这将产生以下输出 −
+--------------------------+ | ListOfNames | +--------------------------+ | ["Sam", "Mike", "Carol"] | | ["David", "Bob"] | | ["Adam", "John", "Sam"] | +--------------------------+ 3 rows in set (0.00 sec)
广告