MySQL 5.6中的JSON字段中选择json_extract函数不可用?来手动新增一下!

DELIMITER $$
DROP FUNCTION IF EXISTS `JSON_EXTRACT`$$
CREATE FUNCTION `JSON_EXTRACT`(
 details TEXT,
 required_field VARCHAR (255)
) RETURNS TEXT CHARSET latin1
BEGIN
SET details = SUBSTRING_INDEX(details, "{", -1);
SET details = SUBSTRING_INDEX(details, "}", 1);
RETURN TRIM(
BOTH '"' FROM SUBSTRING_INDEX(
    SUBSTRING_INDEX(
        SUBSTRING_INDEX(
            details,
            CONCAT(
                '"',
                SUBSTRING_INDEX(required_field,'$.', - 1),
                '":'
            ),
            - 1
        ),
        ',"',
        1
    ),
    ':',
    -1
  )
) ;
END$$
DELIMITER ;

你可能感兴趣的:(mysql,json,android)