使用JSON数据类型首先设置JSON数据,然后插入。让我们首先创建一个表-
mysql> create table DemoTable1876 ( EmployeeInformation JSON );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1876 values('{ '> "EmployeeData":{ '> "Name": "Chris", '> "Age": 27 '> } '> }' ); mysql> insert into DemoTable1876 values('{ '> "EmployeeData":{ '> "Name": "David", '> "Age": 24 '> } '> }' );
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1876;
这将产生以下输出-
+------------------------------------------------+ | EmployeeInformation | +------------------------------------------------+ | {"EmployeeData": {"Age": 27, "Name": "Chris"}} | | {"EmployeeData": {"Age": 24, "Name": "David"}} | +------------------------------------------------+ 2 rows in set (0.00 sec)