码迷,mamicode.com
首页 > 其他好文 > 详细

实验9-5 编写一个存储过程proc_test_stat

时间:2018-07-17 19:28:21      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:temp   tab   中国人   创建   arc   style   count   english   test   

在TestDB数据库中,编写一个存储过程proc_test_stat:

1)参数1 @target 类型nvarchar 长度 256

2)要求返回以下结果集:

字符及其在 @target 中出现的次数,字段名分别是c, count

 

注意:字符串可能包含:符号,数字,字母,汉字等

提示:在临时数据库中创建一个表,保存字符统计结果

 

测试语句:

proc_test_stat ‘我是1个中国人, and you are an english,‘ 

 

create procedure proc_test_stat(@target nvarchar(256))
as
begin
set nocount on;
	create table chartable(
		tempc varchar(2)	
	)
	declare @i int;
		set @i =0;
    declare @length int;
		set @length=len(@target);
	while(@i<@length)
		begin
			set @i=@i+1
			insert into chartable(tempc) values(substring(@target,@i,1))
		end	
	select tempc ‘c‘,count(*) ‘count‘ from chartable
	group by tempc
set nocount off;
end

  

实验9-5 编写一个存储过程proc_test_stat

标签:temp   tab   中国人   创建   arc   style   count   english   test   

原文地址:https://www.cnblogs.com/masterchd/p/9325071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!