原sql
and ISJSON( A.SalesNames ) > 0 AND JSON_VALUE(LOWER(A.SalesName) , '$.name') = @saleName
and ISJSON( A.SalesNames ) > 0 AND JSON_VALUE(LOWER(A.bcd), '$.bcd') = @bcd
需要转换为
and ISJSON( A.SalesNames ) > 0 AND LOWER(A.SalesName)::jsonb @>'{"name":"@saleName"}'
and ISJSON( A.SalesNames ) > 0 AND LOWER(A.bcd)::jsonb @>'{"bcd":"@bcd"}'
用代码实现,粗略估计至少几十行,并且容易出错。用正则替换,1行代码解决:
正则表达式:
json_value(\((((.*?)\s{0,},\s{0,}'\$.)(.*?)')(\)\s{0,}(=\s{0,}(\@\S+))))
替换字符串:$4::jsonb @>'{"$5":"$8"}'