MySQL 权限——未经用户许可无法创建函数

问题描述 投票:0回答:1

我想使用这样的功能

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)
        );

但我只有数据库和过程的执行权限。

有没有办法只使用函数而无需在数据库中创建此类函数的权限?

mysql function permissions subquery prepared-statement
1个回答
0
投票

由于我没有得到答案,只有评论,所以我根据此链接进行了以下操作在查询中创建临时变量

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 ...),请告诉我!

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.