使用encists()函数在功能主体内部不起作用mariaDB查询

发布于 2025-02-14 01:39:34 字数 1220 浏览 2 评论 0原文

我正在尝试使用此查询检查是否存在例程:

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

我使其正常工作的解决方案

,不使用extists()

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;

仍然想知道为什么使用存在()内部功能会导致该错误。

I'm trying to check if a routine exists, using this query:

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

It works. So I wrapped it in a function:

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;

So I can use it like this:

select fn_routine_exists('sp_result');

However, it gives me an error:

[22003][1264] Out of range value for column 'CHARACTER_MAXIMUM_LENGTH' at row 1

Workarounds

I've made it working, making no use of 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;

Still wondering why using EXISTS() inside function makes that error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2025-02-21 01:39:34

这听起来像是一个错误。

您已经有一些过程/函数,比

我无法在最新的10.3、10.4或10.6上复制此功能,而功能返回了longblob(该功能应该具有4G结果,但它被截断了)。

请创建新错误报告包括玛丽亚德版本和sp_result的功能头,以及选择 *从信息_schema.routines中选择 * rutine_name ='sp_result';(如果可能)。

This sounds like a bug.

You've got some procedure/function that returns more than the 2G for the information_schema.ROUTINES CHARACTER_MAXIMUM_LENGTH field and somehow this only triggers in a routine.

I've been unable to reproduce this on the latest 10.3, 10.4 or 10.6 with a function returning a longblob (which should have a 4G result, but it got truncated).

Please create new bug report including the MariaDB version and the function header of sp_result, and select * from information_schema.ROUTINES where ROUTINE_NAME='sp_result'; if possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文