當前位置:首頁 » 編程語言 » sql創建自定義函數

sql創建自定義函數

發布時間: 2022-07-16 15:01:03

1. 用SQL語言,創建一個用戶自定義函數,判斷一個數是否能被5和7同時整除

CREATE
FUNCTION
F2(@數
INT)
RETURNS
VARCHAR(20)
AS
BEGIN

DECLARE
@結果
VARCHAR(20)

IF
@數
%
5=0
AND
@數
%
7=0

SET
@結果='可以被5和7
整除
'

ELSE

SET
@結果='不能被5和7整除'

RETURN
@結果
END
GO
select
dbo.F2(20),dbo.F2(35)

2. SQL創建用戶自定義函數

樓主我只寫了其中一個..基本方法都如此,希望對您有幫助,代碼如下
ALTER
FUNCTION
[dbo].[sum]
(

@class
varchar(100),
--所選課程

@username
varchar(20)
--學生姓名
)
RETURNS
int
AS
BEGIN

DECLARE
@reun
int

SELECT
SUN(@class)
FROM
YOURTABLE
WHERE
USERNAME=@username

RETURN
@reun
END

3. SQL自定義函數的創建(給定班級號,統計該班級男女生數量)

CREATE FUNCTION dbo.fn_stucount (@classno nvarchar(20))
RETURNS TABLE
AS
RETURN
(
select a.sex,count(*)數量 from student a,class b where a.sno=b.sno and b.classno=@classno

group by a.sex

);

4. 寫一個Sql自定義函數

declare @flag int,@no varchar(20),@return int
--先為變數賦值
--set @flag=0...
select @return = search1(@flag,@no)

我沒明白,是要寫函數的代碼還是寫調用的代碼?調用方法上面已寫。

5. Microsoft SQL Server如何創建 自定義函數

Create Function RmGetPY(@chn nchar(1))
returns char(1)
as
begin
declare @n int
declare @c char(1)
set @n = 63
select @n = @n +1,@c = case chn when @chn then char(@n) else @c end from(
select top 27 * from (
select chn =
'吖' union all select
'八' union all select
'嚓' union all select
'咑' union all select
'妸' union all select
'發' union all select
'旮' union all select
'鉿' union all select
'丌' union all select
'丌' union all select
'咔' union all select
'垃' union all select
'嘸' union all select
'拏' union all select
'噢' union all select
'妑' union all select
'七' union all select
'呥' union all select
'仨' union all select
'他' union all select
'屲' union all select
'屲' union all select
'屲' union all select
'夕' union all select
'丫' union all select
'帀' union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
return(@c)
end

go

Create Function GetAllPY(@chn nvarchar(100))
returns varchar(30)
as
begin

declare @i int,@j int,@result varchar(100)
set @result=''
set @i=len(@chn)
set @j=1
while @j<=@i
begin
set @result = @result + dbo.RmGetPY(substring(@chn,@j,1))
set @j=@j+1
end
return @result
end

看看這兩個,典型的取漢字拼音碼的函數

6. 什麼是SQL自定義函數

就是自己定義出一個滿足自己程序需要的函數,可以參考
書上的函數,創建一個滿足自己需要的函數

7. SQL中創建一個用戶自定義函數

CREATE
FUNCTION
DBO.tFProctsHS
(
@name
VARCHAR(10))
RETURNS
INT
--這個根據價格的類型自己修改
AS
begin
DECLARE
@jiage
INT;
select
@jiage=
jiage
from
商品表
where
name=
@name
RETURN
(@jiage)
end
--ceshi
select
DBO.tFProctsHS
('記事本')

熱點內容
雲伺服器最先跑什麼 發布:2025-07-01 05:02:39 瀏覽:215
微信公眾平台手機上傳視頻 發布:2025-07-01 04:58:53 瀏覽:415
數控車床螺紋編程實例 發布:2025-07-01 04:46:27 瀏覽:422
什麼是安卓品牌尖貨 發布:2025-07-01 04:45:50 瀏覽:697
寫入設備緩存 發布:2025-07-01 04:37:35 瀏覽:431
小雞g4怎麼連安卓 發布:2025-07-01 04:37:25 瀏覽:355
黃金線主圖源碼 發布:2025-07-01 04:35:38 瀏覽:297
阿里輕量伺服器有固定IP嗎 發布:2025-07-01 04:30:27 瀏覽:507
電腦什麼配置要合適 發布:2025-07-01 04:24:15 瀏覽:167
哪個安卓恢復工具不要錢 發布:2025-07-01 04:21:54 瀏覽:743