You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MariaDB函数体内使用EXISTS()查询触发列值越界错误

问题现象

使用如下SQL语句可直接正常执行,作用是判断指定名称的数据库例程是否存在:

select exists(select 1 from information_schema.ROUTINES where ROUTINE_NAME = $name_of_routine);

将该逻辑封装为自定义函数:

create
    definer = MES_DHSol@`%` function fn_routine_exists($name_of_routine varchar(64)) returns tinyint(1)
begin
    return exists(select 1 from information_schema.ROUTINES where ROUTINE_NAME = $name_of_routine);
end;

封装后通过以下语句调用函数:

select fn_routine_exists('sp_result');

调用时抛出如下报错:

[22003][1264] Out of range value for column 'CHARACTER_MAXIMUM_LENGTH' at row 1
临时规避方案

移除函数内的EXISTS()写法,改写查询逻辑后函数可正常运行,改写后的函数代码如下:

create
    definer = MES_DHSol@`%` function fn_routine_exists($name_of_routine varchar(64)) returns tinyint(1)
begin
    declare v_exists tinyint(1) default false;

    select true
    from information_schema.ROUTINES
    where ROUTINE_NAME = $name_of_routine
    into v_exists;
    
    return v_exists;
end;

目前暂未定位到在存储函数体内使用EXISTS()子查询触发该报错的根本原因。


内容的提问来源于stack exchange,提问作者Potados

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 21:27:25