我想使用这样的功能
CREATE FUNCTION substr_beginning_end (long_text text, substr_beginning VARCHAR(50), substr_end VARCHAR(20))
RETURNS VARCHAR(2000) DETERMINISTIC
RETURN SUBSTR(long_text,
POSITION(substr_beginning IN long_text) + LENGTH(substr_beginning),
LOCATE(substr_end, long_text, POSITION(substr_beginning IN long_text))-POSITION(substr_beginning IN long_text) - LENGTH(substr_beginning)
);
但我只有数据库和过程的执行权限。
有没有办法只使用函数而无需在数据库中创建此类函数的权限?
由于我没有得到答案,只有评论,所以我根据此链接进行了以下操作在查询中创建临时变量:
SELECT
CONCAT_WS( if(@campo1_substr_beginning := 'feature01":"', '',''),
if(@campo1_substr_end := '",', '',''),
SUBSTR(request, POSITION(@campo1_substr_beginning IN request) + LENGTH(@campo1_substr_beginning),
LOCATE(@campo1_substr_end, request, POSITION(@campo1_substr_beginning IN request))
- POSITION(@campo1_substr_beginning IN request)
- LENGTH(@campo1_substr_beginning)
) ) AS 'campo1',
CONCAT_WS( if(@campo3_substr_beginning := '"feature02":', '',''),
if(@campo3_substr_end := ',', '',''),
SUBSTR(request, POSITION(@campo3_substr_beginning IN request) + LENGTH(@campo3_substr_beginning),
LOCATE(@campo3_substr_end, request, POSITION(@campo3_substr_beginning IN request))
- POSITION(@campo3_substr_beginning IN request)
- LENGTH(@campo3_substr_beginning)
) ) AS 'campo3',
request,
response
FROM event_log elog
WHERE
....
也许如果有人想到一种更好的方法,不需要重命名每个字段的变量(campo1_substr ....和campo2_substr ...),请告诉我!
谢谢。