Linux&MySQL&PHP&Nginx&Apache&MSSQL&Shell
分类: Mysql/postgreSQL
2013-02-28 16:18:05
标量函数,返回一个值
Use database_name;
GO
if object_id(N'dbo.function_name',N'IF') is not null
drop function dbo.function_name;
GO
create function dbo.function_name(@id int) returns varchar(180) //定义返回值的类型
AS
BEGIN
declare @name varchar(180); //定义返回值
select @name=table_colnum from table_name where id=@id
return @name;
END
使用函数:select dbo.function_name(@id)
表值函数,返回一个表
Use database_name;
GO
if object_id(N'dbo.function_name',N'IF') is not null
drop function dbo.function_name;
GO
create function dbo.function_name(@id int) returns table //定义返回数据为表
AS
return
(
select * from table_name where id=@id
);
使用函数:select * from dbo.function_name(@id)
点击(此处)折叠或打开
-- 截取指定分隔符直接字符串