mysqlfunction输出语句_MySQLfunctionprocedure

更新时间:2023-06-08 09:07:26 阅读: 评论:0

mysqlfunction输出语句_MySQLfunctionprocedure CREATE DEFINER=`root`@`%` FUNCTION`cc`() RETURNS intBEGIN#Routine body
lect emp_no into @b from employees where emp_no=10060;
黔驴之技
RETURN @b;END
尖利的意思OR
CREATE DEFINER=`root`@`%` FUNCTION`cc`() RETURNS intBEGIN#Routine body
declare b int default null;
lect emp_no into b from employees where emp_no=10060;
RETURN b;END
局部变量b需使⽤declare最先声明
传参
CREATE DEFINER=`root`@`%` FUNCTION `cc`(lastName varchar(60)) RETURNS int
DETERMINISTICBEGIN#Routine body
暖胃汤
declare b int default null;
lect emp_no into b from employees where last_name=lastName collate utf8mb4_general_ci;
RETURN b;END
意大利旅游签证使⽤navicat查询时,出现如下错误,故使⽤collate明确指定collation
no sql function
CREATE DEFINER=`root`@`%` FUNCTION`cc`(x int,y int) RETURNS int
NOSQL
BEGIN#Routine body
declare b int default null;
t b=x+y;
RETURN b;END
使⽤⽤户变量,累加求和
CREATE DEFINER=`root`@`%` FUNCTION`cc`(x int) RETURNS int
READSSQL DATA
BEGIN#Routine body
t @i=1;
t @sum=0;小型车排行榜
while @i<=x do
t @sum=@sum+@i;
t @i=@i+1;
return @sum;END
使⽤局部变量,累加求和,跳过5的倍数
CREATE DEFINER=`root`@`%` FUNCTION`cc`(x int) RETURNS int
READSSQL DATA
BEGIN#Routine body
declare i int default1;
declare sum int default0;
sumwhile:while i<=x do
if i %5 =0then
t i=i+1;
iterate sumwhile;
end if;
t sum=sum+i;
t i=i+1;
end while;
return sum;END
条件判断 if
CREATE DEFINER=`root`@`%` PROCEDURE `nm`(n int,_gender char(1) chart utf8mb4 collate utf8mb4_general_ci)BEGIN#Routine body
if _gender='m'then
lect* from employees where gender=_gender limit n;
elif _gender='f'then
lect* from employees where gender=_gender limit n;
el
lect*from employees limit n;
end if;END
CREATE DEFINER=`root`@`%` PROCEDURE `loop4`(in x int)BEGIN#Routine body
if x=3 then lect * from employees where emp_no like concat('%',x) limit x;
elif x=4 then lect * from employees where emp_no like concat('%',x) limit x;
elif x=5 then lect * from employees where emp_no like concat('%',x) limit x;
el lect*from employees limit x;
end if;END
ca 有两种格式
CREATE DEFINER=`root`@`%` PROCEDURE `nm`(x int)BEGIN#Routine body declare p int;
t p=8;
ca
when x
when x=p then lect *from dept_emp limit x;
when x>p then lect *from departments limit x;
el lect'x is invalid';
end ca;END盗取qq号
CREATE DEFINER=`root`@`%` PROCEDURE `oo`(in x int)BEGIN#Routine body declare ychar(11) default null;
lect gender into y from employees where emp_no=x;
ca
when y='m' then update employees t first_name='qwert' where emp_no=x;
when y='f' then update employees t first_name='zxcc' where emp_no=x;
el
update employees t first_name='Unkown' where emp_no=x;
end ca;END
单值判断
CREATE DEFINER=`root`@`%` PROCEDURE `nm`(x int)BEGIN#Routine body declare p int;
t p=8;
ca x
when5 then lect *from employees limit x;
when6 then lect *from dept_emp limit x;
when7 then lect *from departments limit x;
el lect'x is invalid';
end ca;END
CREATE DEFINER=`root`@`%` PROCEDURE `loop4`(in x int)BEGIN#Routine body declare v int default null;
lect gender into v from employees where emp_no=x;
ca v
when1 then update employees t first_name='uiop' where emp_no=x;
when2 then update employees t first_name='vbnm' where emp_no=x;
el
update employees t first_name='Unkown' where emp_no=x;
end ca;END
loop
CREATE DEFINER=`root`@`%` PROCEDURE `nm`()BEGIN#Routine body declare i int default0;
add_loop:loop
t i=i+1;
if i>=10then
leave add_loop;
end if;
end loop add_loop;
lect i;END
CREATE DEFINER=`root`@`%` PROCEDURE `nm`()BEGIN#Routine body declare i int default null;
t i=0;
_loop:loop
inrt into p (name) values (concat('zxc',i));
t i=i+1;
if i>=5then
leave _loop;
end if;
end loop _loop;
lect*from p;END
leave
基本格式
leave LABEL
CREATE DEFINER=`root`@`%` PROCEDURE `nm`()BEGIN#Routine body t @count=0;
add_loop:loop
t @count=@count+1;
if @count=50then
leave add_loop;
end if;
end loop add_loop;END
春天是什么样子iterate
iterate 语句将执⾏顺序转到label位置,格式如下,只可以出现在loop,repeat,while内
iterate LABEL
CREATE DEFINER=`root`@`%` PROCEDURE `nm`()BEGIN#Routine body
declare b int default0;
my_loop:loop
小腿有痣t b=b+1;
if b<10then
iterate my_loop;
elif b>20then
leave my_loop;
end if;
lect b;
end loop my_loop;END
repeat 类似于 do while
CREATE DEFINER=`root`@`%` PROCEDURE `nm`()BEGIN#Routine body
declare i int default0;
t i=0;
_repeat:repeat
t i=i+1;
until i>10end repeat _repeat;
lect i;END
while
CREATE DEFINER=`root`@`%` PROCEDURE `nm`(in n smallint)BEGIN#Routine body declare i int default0;
declare s int default0;
while i<=n do
t s=s+i,i=i+1;
end while;
lect s;END
cursor 游标
CREATE DEFINER=`root`@`%` PROCEDURE `nm`(in n smallint)BEGIN#Routine body

本文发布于:2023-06-08 09:07:26,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1021867.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:判断   签证   累加   求和   格式   顺序   转到   位置
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图