當前位置:首頁 » 編程語言 » 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
('記事本')

熱點內容
52好壓壓縮 發布:2025-03-07 06:04:47 瀏覽:68
相鄰演算法 發布:2025-03-07 06:01:51 瀏覽:581
編譯器中 發布:2025-03-07 06:01:44 瀏覽:481
電視現在什麼配置好 發布:2025-03-07 06:01:06 瀏覽:625
安卓內存很大為什麼還是卡 發布:2025-03-07 05:43:53 瀏覽:534
什麼配置的車厲害 發布:2025-03-07 05:43:06 瀏覽:456
魅族應用加密 發布:2025-03-07 05:41:51 瀏覽:653
c盤windows文件夾多大 發布:2025-03-07 05:35:58 瀏覽:616
長江存儲凈資產 發布:2025-03-07 05:35:50 瀏覽:218
gridview載入資料庫 發布:2025-03-07 05:20:31 瀏覽:372