mysql存储过程nowait_MySQL存储过程中一直困扰的 の 变量中的@

在声明变量中

CREATE function Get_StrArrayLength

(

@str varchar(1024), --要分割的字符串

@split varchar(10) --分隔符号

)

returns int

as

begin

declare @location int

declare @start int

declare @length int

set @str=ltrim(rtrim(@str))

set @location=charindex(@split,@str)

set @length=1

while @location<>0

begin

set @start=@location+1

set @location=charindex(@split,@str,@start)

set @length=@length+1

end

return @length

end

/***********为什么下面这种可以不用 decalre*************************/

CREATE DEFINER=`root`@`%` PROCEDURE `test`()

BEGIN

#目标字符串

set @a = ’1,2,3,4,5,6,12‘;

# 分隔符

set @c = ',';

# 存储风格后的字符串

set @b = '';

REPEAT

# 调用上面的存储过程

CALL SPLIT_SUB_STR0(@a, ',', @c);

#将取得的字符串拼接,测试用

set @b = concat(@b, @c);

#当目标字符串为空时,停止循环

UNTIL @a = ''

END REPEAT;

# 查看结果

select @a, @c, @b;

END;

/******************************为什么还有的没有@****************************/

BEGIN

-- Get the separated string.

declare cnt int default 0;

declare i int default 0;

set cnt = func_get_split_string_total(f_string,f_delimiter);

drop table if exists tmp_print;

create temporary table tmp_print (num int not null);

while i 

do

set i = i + 1;

insert into tmp_print(num) values (func_get_split_string(f_string,f_delimiter,i));

end while;

select * from tmp_print;

END

求教这三种区别

/**************************************答案***********************************/

变量的作用范围同编程里面类似,在这里一般是在对应的begin和end之间。在end之后这个变量就没有作用了,不能使用了。这个同编程一样。

另外有种变量叫做会话变量(session variable),也叫做用户定义的变量(user defined variable)。这种变量要在变量名称前面加上“@”符号,叫做会话变量,代表整个会话过程他都是有作用的,这个有点类似于全局变量一样。这种变量用途比较广,因为只要在一个会话内(就是某个应用的一个连接过程中),这个变量可以在被调用的存储过程或者代码之间共享数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值