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

Posted masterchd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验9-5 编写一个存储过程proc_test_stat相关的知识,希望对你有一定的参考价值。

在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 @[email protected]+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的主要内容,如果未能解决你的问题,请参考以下文章

MySQL数据库 *实验17存储过程

[PTA]实验9-5 查找书籍

oracle PL/SQL高级编程

实验八附加:存储过程

实验八 存储过程1

实验八 存储过程2