我必须在mysql触发器中操纵json对象。为此我已经安装了common_schema。
它安装成功并且直接查询它证明了适当的结果。但是当在mysql触发器中使用相同的查询时,它会抛出错误。 ERROR 1327(42000):未声明的变量:common_schema。
请协助。
下面是使用mysql common_schema ::
的查询 SELECT common_schema.extract_json_value(api.response,'/GUID') AS GUID,
common_schema.extract_json_value(api.response,'/SUBMITDATE') AS SUBMITDATE,
common_schema.extract_json_value(api.response,'/ID') AS subscriber_id
FROM api_response api
ORDER BY id DESC LIMIT 10;
+--------------------------------------+---------------------+---------------+
| GUID | SUBMITDATE | subscriber_id |
+--------------------------------------+---------------------+---------------+
| kf73e550098321f4610003o61mKELLTON2A2 | 2015-07-03 14:55:00 | 173 |
| kf73e550097721f461000cofneKELLTON2A2 | 2015-07-03 14:55:00 | 178 |
| kf73e550096421f461000iqhtfKELLTON2A2 | 2015-07-03 14:55:00 | 175 |
| kf73e550095121f4610008kjwiKELLTON2A2 | 2015-07-03 14:55:00 | 176 |
| kf73e550093621f461000rxq1lKELLTON2A2 | 2015-07-03 14:55:00 | 174 |
| kf73e550092421f461000zh2njKELLTON2A2 | 2015-07-03 14:55:00 | 177 |
| kf73e550091021f461000csbi4KELLTON2A2 | 2015-07-03 14:55:00 | 122 |
| kf73e550089621f461000vqvrdKELLTON2A2 | 2015-07-03 14:55:00 | 121 |
| kf73e550088321f461000sy3dyKELLTON2A2 | 2015-07-03 14:55:00 | 105 |
| kf73e550086821f461000x6bqoKELLTON2A2 | 2015-07-03 14:55:00 | 109 |
+--------------------------------------+---------------------+---------------+
10行(0.06秒)
这是我的触发器::
`为每个行插入api_response后创建TRIGGER response_in_sms_reports
BEGIN
- 变量声明DECLARE subscriber_id INT; DECLARE GUID varchar(250); DECLARE SUBMITDATE datetime; DECLARE is_error INT DEFAULT 1; DECLARE error_code varchar(100); - 触发代码 - 查找执行INSERT到表的人的用户名,将common_schema.extract_json_value(api.response,'/ ID')选择到subscriber_id,common_schema.extract_json_value(api.response,'/ GUID')到GUID,common_schema。 extract_json_value(api.response,'/ SUBMITDATE')到SUBMITDATE,common_schema.extract_json_value(api.response,'/ ERROR')到is_error,common_schema.extract_json_value(api.response,'/ ERROR / CODE')到error_code 来自api_response api
- 将记录插入审计表INSERT INTO sms_reports(guid,list_subscriber_id,submit_date,error,error_code)VALUES(GUID,subscriber_id,SUBMITDATE,is_error,error_code);
END;`
这导致ERROR 1327(42000):未声明的变量:common_schema