13存储过程、用户自定义函数与触发器.pptVIP

  • 3
  • 0
  • 约1.12万字
  • 约 43页
  • 2017-06-12 发布于浙江
  • 举报

13存储过程、用户自定义函数与触发器.ppt

13存储过程、用户自定义函数与触发器

13.4 用户自定义函数 创建用户自定义函数 图13-6 创建用户自定义函数对话框 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 13.4 用户自定义函数 例13-7:创建标量函数DatetoQuarter,将输入的日期数据转换为该日期对应的季度值。如输入‘2006-8-5’,返回‘3Q2006’,表示2006年3季度。 CREATE FUNCTION DatetoQuarter(@dqdate datetime) RETURNS char(6) AS BEGIN RETURN(datename(q,@dqdate)+Q+datename(yyyy,@dqdate)) END Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 例13-8:创建标量函数NumToStr,输入阿拉伯数字0~9,输出对应的中文大写。 CREATE FUNCTION NumToStr(@num as int) RETURNS char(2) AS BEGIN declare @ChineseCap as char(2) set @ChineseCap=(case @num when 0 then 零 when 1 then 壹 when 2 then 贰 when 3 then 叁 when 4 then 肆 when 5 then 伍 when 6 then 陆 when 7 then 柒 when 8 then 捌 when 9 then 玖 end) return @ChineseCap END Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 13.4 用户自定义函数 例13-9:通过自定义函数根据输入课程号,返回对应的课程名。 CREATE FUNCTION F课程名 (@courseID char(10)) RETURNS char(20) AS BEGIN declare @courseName char(20) select @courseName=课程名 from 课程表 where 课程号=@courseID return @courseName END Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 13.4 用户自定义函数 例13-10:创建一个内嵌表值函数stuinfo,输入学生学号,返回学生姓名及各科成绩。 CREATE FUNCTION stuinfo (@xh varchar(10)) RETURNS table AS return(select 姓名,课程号,成绩 from 学生表 inner join 选课表 on 学生表.学号=选课表.学号 where 选课表.学号=@xh) Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 例13-11:创建多语句表值函数Stu_Info,根据输入的学号、课程号,返回对应的姓名、课程名和成绩。 CREATE FUNCTION Stu_Info(@学号 varchar(10),@课程号 varchar(10)) RETURNS @stu_info table(stuName varchar(8), courseName varchar(20), score smallint) AS BEGIN declare @stuName as varchar(8),@courseName as varchar(20) declare @score as smallint select

文档评论(0)

1亿VIP精品文档

相关文档