您好,有人可以告诉我此查询出了什么问题。
DECLARE @json LONGTEXT; SET @json = '[ { "name":"John Smith", "address":"780 Mission St, San Francisco, CA 94103"}, { "name":"Sally Brown", "address":"75 37th Ave S, St Cloud, MN 94103"}, { "name":"John Johnson", "address":"1262 Roosevelt Trail, Raymond, ME 04071"} ]'; ##SELECT @json; SELECT * FROM JSON_TABLE (@json, '$[*]' COLUMNS ( name VARCHAR(40) PATH '$.name', address VARCHAR(100) PATH '$.address'));
我得到的错误是
您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册,以获取在’(@json,’$ [*]’COLUMNS(name VARCHAR(40)PATH’$ .name’,’在第1行
仅出于信息目的,我使用TOAD作为工具将sql实例连接到云。
首先,在这种情况下,您无需在mysql中声明变量。只需使用“ SET”关键字即可。最后,您需要为“选择”查询放置一个别名。像这样:
SET @json = '[ { "name":"John Smith", "address":"780 Mission St, San Francisco, CA 94103"}, { "name":"Sally Brown", "address":"75 37th Ave S, St Cloud, MN 94103"}, { "name":"John Johnson", "address":"1262 Roosevelt Trail, Raymond, ME 04071"} ]'; ##SELECT @json; SELECT * FROM JSON_TABLE (@json, '$[*]' COLUMNS ( `name` VARCHAR(40) PATH '$.name', `address` VARCHAR(100) PATH '$.address')) AS T;