Notice (8): file_put_contents(): Write of 270 bytes failed with errno=28 No space left on device [CORE/src/Log/Engine/FileLog.php, line 140]

Notice: file_put_contents() [function.file-put-contents]: Write of 1108 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): SplFileObject::fwrite() [<a href='https://secure.php.net/splfileobject.fwrite'>splfileobject.fwrite</a>]: Write of 5131 bytes failed with errno=28 No space left on device [CORE/src/Cache/Engine/FileEngine.php, line 141]

Notice: file_put_contents() [function.file-put-contents]: Write of 3151 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 85980 of 86005 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2489 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 90093 of 90101 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2489 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
SQlFunction创建函数实例介绍 - 站长搜索
首页 > 资讯列表 > 编程/数据库 >> 数据库操作教程

SQlFunction创建函数实例介绍

数据库操作教程 2022-09-23 18:13:58 转载来源: 网络整理/侵权必删

 在SQL中系统已为我们提供了很非常丰富的函数:例:聚会函数avg,sum,count,max,min日期函数:Day,Month,Year等等 为我们日常开发节省很多时间 但是有一些特殊需求的话SQL也提供自己创建函数的功能下面举一小例子:需求:某一订单表编号,订单号,产品名称要知道某一订单号的产品名称名称之间用逗号(,)隔开如下图:我们创建一个标题函数:StrName创建过程类似创建存储过程如下:点击右键创建表值函数与标量函数从名称就可以分出来 一个返回表(集合)标题(单一)在这个小例子中因为我们只返回名字所以创建一个标量函数代码如下:CreateFUNCTION[dbo].[OrderDetailGetStrNameByOrderId](@OrderIdint)RETURNSvarchar(500)ASBEGIN--Declarethereturnvariableheredeclare@StrPassengernamevarchar(500)set@StrPassengername=''select@StrPassengername=@St

 在SQL中系统已为我们提供了很非常丰富的函数:例:聚会函数avg, sum,count,max,min 日期函数:Day,Month,Year等等  为我们日常开发节省很多时间  但是有一些特殊需求的话SQL 也提供自己创建函数的功能下面举一小例子:需求: 某一订单表 编号,订单号,产品名称 要知道 某一订单号的产品名称 名称之间用逗号(,)隔开 如下图:

我们创建一个标题函数: StrName 创建过程类似创建存储过程 如下:

点击右键创建 表值函数与标量函数 从名称就可以分出来  一个返回表(集合) 标题(单一) 在这个小例子中因为我们只返回名字 所以创建一个标量函数 代码如下:

Create FUNCTION [dbo].[OrderDetailGetStrNameByOrderId] (  @OrderId int)RETURNS varchar(500)ASBEGIN  -- Declare the return variable here  declare @StrPassengername varchar(500)  set @StrPassengername=''  select @StrPassengername=@StrPassengername+ Passengername +', ' from OrderDetail where OrderId=@OrderId  select @StrPassengername=substring(@StrPassengername,0,len(@StrPassengername))  -- Return the result of the function  RETURN @StrPassengernameEND

创建好之后在就可以像avg,sum等函数一样的使用 减少代码量 如下

select distinct A.OrderId,(SELECT [dbo].[OrderDetailGetStrNameByOrderId](A.OrderId)) StrNamefrom OrderDetail A

完毕。

标签: SQlFunction 创建 函数 实例 介绍


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2025 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持