sql使用'->>'运算符获取错误

cld4siwp  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(330)
CREATE PROCEDURE `getAssetDetailsforPDF`(
) BEGIN
Select
    class.Name as AssetName,
    getOperatingZoneName(
        ifnull(getoperatingzone(class.ID), 0)
    ) as OperatingZone,
    getTimetoFailure(
        class.ID
    ) as TagValue,
    class1.Name as LineName,
    details.Defintion - > > '$."Asset ID"' as definition
from
    asset_classification class
    left join
        asset_classification class1
    on  class1.ParentId = 2
    left join
        asset_details details
    on  details.Id in(
            select
                class.ID
        )
Where
    class.MCT_typeId = 5
and class.ParentId in(
        Select
            class1.ID
    )
group by
    class.Id
;
END
;
;

我有这个sql查询,在将sql文件导入phpmyadmin数据库时出错。
sql语法有错误;请查看与您的mysql服务器版本对应的手册,以获取“>”$“asset id”附近使用的正确语法
这里编辑的是mysql版本:

fzwojiic

fzwojiic1#

可能是您的mysql不支持“->>'$…”这样的运算符。相反,您可以使用mysql的json_extract()函数,如下所示:

CREATE PROCEDURE `getAssetDetailsforPDF`(
) BEGIN
Select
    class.Name as AssetName,
    getOperatingZoneName(
        ifnull(getoperatingzone(class.ID), 0)
    ) as OperatingZone,
    getTimetoFailure(
        class.ID
    ) as TagValue,
    class1.Name as LineName,
json_extract(details.Defintion,'$."Asset ID"') as definition

from
    asset_classification class
    left join
        asset_classification class1
    on  class1.ParentId = 2
    left join
        asset_details details
    on  details.Id in(
            select
                class.ID
        )
Where
    class.MCT_typeId = 5
and class.ParentId in(
        Select
            class1.ID
    )
group by
    class.Id
;
END
;
;

相关问题