使用encists()函数在功能主体内部不起作用mariaDB查询
我正在尝试使用此查询检查是否存在例程:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像是一个错误。
您已经有一些过程/函数,比
我无法在最新的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
, andselect * from information_schema.ROUTINES where ROUTINE_NAME='sp_result';
if possible.