📄 sp.result
字号:
begindrop temporary table if exists t3;create temporary table t3 (id int);insert into t3 values (1), (2), (3);return (select count(*) from t3 as a, t3 as b);end|select f11()|ERROR HY000: Can't reopen table: 'a'select f11() from t1|ERROR HY000: Can't reopen table: 'a'create function f12_1() returns intbegindrop temporary table if exists t3;create temporary table t3 (id int);insert into t3 values (1), (2), (3);return f12_2();end|create function f12_2() returns intreturn (select count(*) from t3)|drop temporary table t3|select f12_1()|ERROR 42S02: Table 'test.t3' doesn't existselect f12_1() from t1 limit 1|ERROR 42S02: Table 'test.t3' doesn't existdrop function f0|drop function f1|drop function f2|drop function f3|drop function f4|drop function f5|drop function f6|drop function f7|drop function f8|drop function f9|drop function f10|drop function f11|drop function f12_1|drop function f12_2|drop view v0|drop view v1|drop view v2|delete from t1 |delete from t2 |drop table t4|drop table if exists t3|create table t3 (n int unsigned not null primary key, f bigint unsigned)|drop procedure if exists ifac|create procedure ifac(n int unsigned)begindeclare i int unsigned default 1;if n > 20 thenset n = 20; # bigint overflow otherwiseend if;while i <= n dobegininsert into test.t3 values (i, fac(i));set i = i + 1;end;end while;end|call ifac(20)|select * from t3|n f1 12 23 64 245 1206 7207 50408 403209 36288010 362880011 3991680012 47900160013 622702080014 8717829120015 130767436800016 2092278988800017 35568742809600018 640237370572800019 12164510040883200020 2432902008176640000drop table t3|show function status like '%f%'|Db Name Type Definer Modified Created Security_type Commenttest fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER drop procedure ifac|drop function fac|show function status like '%f%'|Db Name Type Definer Modified Created Security_type Commentdrop table if exists t3|create table t3 (i int unsigned not null primary key,p bigint unsigned not null)|insert into t3 values( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13),( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31),(10, 37), (11, 41), (12, 43), (13, 47), (14, 53),(15, 59), (16, 61), (17, 67), (18, 71), (19, 73),(20, 79), (21, 83), (22, 89), (23, 97), (24, 101),(25, 103), (26, 107), (27, 109), (28, 113), (29, 127),(30, 131), (31, 137), (32, 139), (33, 149), (34, 151),(35, 157), (36, 163), (37, 167), (38, 173), (39, 179),(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)|drop procedure if exists opp|create procedure opp(n bigint unsigned, out pp bool)begindeclare r double;declare b, s bigint unsigned default 0;set r = sqrt(n);again:loopif s = 45 thenset b = b+200, s = 0;elsebegindeclare p bigint unsigned;select t.p into p from test.t3 t where t.i = s;if b+p > r thenset pp = 1;leave again;end if;if mod(n, b+p) = 0 thenset pp = 0;leave again;end if;set s = s+1;end;end if;end loop;end|drop procedure if exists ip|create procedure ip(m int unsigned)begindeclare p bigint unsigned;declare i int unsigned;set i=45, p=201;while i < m dobegindeclare pp bool default 0;call opp(p, pp);if pp theninsert into test.t3 values (i, p);set i = i+1;end if;set p = p+2;end;end while;end|show create procedure opp|Procedure sql_mode Create Procedureopp CREATE DEFINER=`root`@`localhost` PROCEDURE `opp`(n bigint unsigned, out pp bool)begindeclare r double;declare b, s bigint unsigned default 0;set r = sqrt(n);again:loopif s = 45 thenset b = b+200, s = 0;elsebegindeclare p bigint unsigned;select t.p into p from test.t3 t where t.i = s;if b+p > r thenset pp = 1;leave again;end if;if mod(n, b+p) = 0 thenset pp = 0;leave again;end if;set s = s+1;end;end if;end loop;endshow procedure status like '%p%'|Db Name Type Definer Modified Created Security_type Commenttest ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER test opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER call ip(200)|select * from t3 where i=45 or i=100 or i=199|i p45 211100 557199 1229drop table t3|drop procedure opp|drop procedure ip|show procedure status like '%p%'|Db Name Type Definer Modified Created Security_type Commentdrop table if exists t3|create table t3 ( f bigint unsigned not null )|drop procedure if exists fib|create procedure fib(n int unsigned)beginif n > 1 thenbegindeclare x, y bigint unsigned;declare c cursor for select f from t3 order by f desc limit 2;open c;fetch c into y;fetch c into x;close c;insert into t3 values (x+y);call fib(n-1);end;end if;end|set @@max_sp_recursion_depth= 20|insert into t3 values (0), (1)|call fib(3)|select * from t3 order by f asc|f0112delete from t3|insert into t3 values (0), (1)|call fib(10)|select * from t3 order by f asc|f011235813213455drop table t3|drop procedure fib|set @@max_sp_recursion_depth= 0|drop procedure if exists bar|create procedure bar(x char(16), y int)comment "111111111111" sql security invokerinsert into test.t1 values (x, y)|show procedure status like 'bar'|Db Name Type Definer Modified Created Security_type Commenttest bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER 111111111111alter procedure bar comment "2222222222" sql security definer|alter procedure bar comment "3333333333"|alter procedure bar|show create procedure bar|Procedure sql_mode Create Procedurebar CREATE DEFINER=`root`@`localhost` PROCEDURE `bar`(x char(16), y int) COMMENT '3333333333'insert into test.t1 values (x, y)show procedure status like 'bar'|Db Name Type Definer Modified Created Security_type Commenttest bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER 3333333333drop procedure bar|drop procedure if exists p1|create procedure p1 ()select (select s1 from t3) from t3|create table t3 (s1 int)|call p1()|(select s1 from t3)insert into t3 values (1)|call p1()|(select s1 from t3)1drop procedure p1|drop table t3|drop function if exists foo|create function `foo` () returns intreturn 5|select `foo` ()|`foo` ()5drop function `foo`|drop function if exists t1max|create function t1max() returns intbegindeclare x int;select max(data) into x from t1;return x;end|insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|select t1max()|t1max()5drop function t1max|create table t3 (v char(16) not null primary key,c int unsigned not null)|create function getcount(s char(16)) returns intbegindeclare x int;select count(*) into x from t3 where v = s;if x = 0 theninsert into t3 values (s, 1);elseupdate t3 set c = c+1 where v = s;end if;return x;end|select * from t1 where data = getcount("bar")|id datazap 1select * from t3|v cbar 4select getcount("zip")|getcount("zip")0select getcount("zip")|getcount("zip")1select * from t3|v cbar 4zip 2select getcount(id) from t1 where data = 3|getcount(id)0select getcount(id) from t1 where data = 5|getcount(id)1select * from t3|v cbar 4zip 3foo 1drop table t3|drop function getcount|drop table if exists t3|drop procedure if exists h_ee|drop procedure if exists h_es|drop procedure if exists h_en|drop procedure if exists h_ew|drop procedure if exists h_ex|drop procedure if exists h_se|drop procedure if exists h_ss|drop procedure if exists h_sn|drop procedure if exists h_sw|drop procedure if exists h_sx|drop procedure if exists h_ne|drop procedure if exists h_ns|drop procedure if exists h_nn|drop procedure if exists h_we|drop procedure if exists h_ws|drop procedure if exists h_ww|drop procedure if exists h_xe|drop procedure if exists h_xs|drop procedure if exists h_xx|create table t3 (a smallint primary key)|insert into t3 (a) values (1)|create procedure h_ee()deterministicbegindeclare continue handler for 1062 -- ER_DUP_ENTRYselect 'Outer (bad)' as 'h_ee';begindeclare continue handler for 1062 -- ER_DUP_ENTRYselect 'Inner (good)' as 'h_ee';insert into t3 values (1);end;end|create procedure h_es()deterministicbegindeclare continue handler for 1062 -- ER_DUP_ENTRYselect 'Outer (good)' as 'h_es';begin-- integrity constraint violationdeclare continue handler for sqlstate '23000' select 'Inner (bad)' as 'h_es';insert into t3 values (1);end;end|create procedure h_en()deterministicbegindeclare continue handler for 1329 -- ER_SP_FETCH_NO_DATAselect 'Outer (good)' as 'h_en';begindeclare x int;declare continue handler for sqlstate '02000' -- no dataselect 'Inner (bad)' as 'h_en';select a into x from t3 where a = 42;end;end|create procedure h_ew()deterministicbegindeclare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGEselect 'Outer (good)' as 'h_ew';begindeclare continue handler for sqlwarningselect 'Inner (bad)' as 'h_ew';insert into t3 values (123456789012);end;delete from t3;insert into t3 values (1);end|create procedure h_ex()deterministicbegindeclare continue handler for 1062 -- ER_DUP_ENTRYselect 'Outer (good)' as 'h_ex';begindeclare continue handler for sqlexceptionselect 'Inner (bad)' as 'h_ex';insert into t3 values (1);end;end|create procedure h_se()deterministicbegin-- integrity constraint violationdeclare continue handler for sqlstate '23000' select 'Outer (bad)' as 'h_se';begindeclare continue handler for 1062 -- ER_DUP_ENTRYselect 'Inner (good)' as 'h_se';insert into t3 values (1);end;end|create procedure h_ss()deterministicbegin-- integrity constraint violationdeclare continue handler for sqlstate '23000' select 'Outer (bad)' as 'h_ss';begin-- integrity constraint violationdeclare continue handler for sqlstate '23000' select 'Inner (good)' as 'h_ss';insert into t3 values (1);end;end|create procedure h_sn()deterministicbegin-- Note: '02000' is more specific than NOT FOUND ;-- there might be other not found states declare continue handler for sqlstate '02000' -- no dataselect 'Outer (good)' as 'h_sn';begindeclare x int;declare continue handler for not foundselect 'Inner (bad)' as 'h_sn';select a into x from t3 where a = 42;end;end|create procedure h_sw()deterministicbegin-- data exception - numeric value out of rangedeclare continue handler for sqlstate '22003' select 'Outer (good)' as 'h_sw';begindeclare continue handler for sqlwarningselect 'Inner (bad)' as 'h_sw';insert into t3 values (123456789012);end;delete from t3;insert into t3 values (1);end|create procedure h_sx()deterministicbegin-- integrity constraint violationdeclare continue handler for sqlstate '23000' select 'Outer (good)' as 'h_sx';begindeclare continue handler for sqlexceptionselect 'Inner (bad)' as 'h_sx';insert into t3 values (1);end;end|create procedure h_ne()deterministicbegindeclare continue handler for not foundselect 'Outer (bad)' as 'h_ne';begindeclare x int;declare continue handler for 1329 -- ER_SP_FETCH_NO_DATAselect 'Inner (good)' as 'h_ne';select a into x from t3 where a = 42;end;end|create procedure h_ns()deterministicbegindeclare continue handler for not foundselect 'Outer (bad)' as 'h_ns';begindeclare x int;declare continue handler for sqlstate '02000' -- no dataselect 'Inner (good)' as 'h_ns';select a into x from t3 where a = 42;end;end|create procedure h_nn()deterministicbegindeclare continue handler for not foundselect 'Outer (bad)' as 'h_nn';begindeclare x int;declare continue handler for not foundselect 'Inner (good)' as 'h_nn';select a into x from t3 where a = 42;end;end|create procedure h_we()deterministicbegindeclare continue handler for sqlwarningselect 'Outer (bad)' as 'h_we';begindeclare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGEselect 'Inner (good)' as 'h_we';insert into t3 values (123456789012);end;delete from t3;insert into t3 values (1);end|create procedure h_ws()deterministicbegindeclare continue handler for sqlwarningselect 'Outer (bad)' as 'h_ws';begin-- data exception - numeric value out of rangedeclare continue handler for sqlstate '22003' select 'Inner (good)' as 'h_ws';insert into t3 values (123456789012);end;delete from t3;insert into t3 values (1);end|create procedure h_ww()deterministicbegindeclare continue handler for sqlwarningselect 'Outer (bad)' as 'h_ww';begindeclare continue handler for sqlwarningselect 'Inner (good)' as 'h_ww';insert into t3 values (123456789012);end;delete from t3;insert into t3 values (1);end|create procedure h_xe()deterministicbegindeclare continue handler for sqlexceptionselect 'Outer (bad)' as 'h_xe';begindeclare continue handler for 1062 -- ER_DUP_ENTRYselect 'Inner (good)' as 'h_xe';insert into t3 values (1);end;end|create procedure h_xs()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -