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

創建sql自定義函數

發布時間: 2023-05-08 15:08:51

❶ 什麼是sql自定義函數

Create Function myFunc(@param1 int,@param2 varchar(50)) returns int
as
begin
......
RETURN 0
end
類似這樣自己建的函數,就是SQL自定義函數,可以自定義參數和返回值的,能夠在查詢語句中使用的。
像max(),min(),getdate(),newid()這些就是系統函數了。

❷ sqlserver中自定義函數

創建自定義缺緩函數:
use 數祥扮猛據謹橋庫名
go
create function 函數名
(@pno int)
returns int
as
begin
declare @a int
if not exists(select * from person where pno=@pno)
set @a=-1
else
set @a=1
return @a
end

調用函數:
use 資料庫
go
select dbo.函數名(13250)

❸ SQL建自定義函數

一個簡單的自定義求和函拍瞎數
create Function sumnum(@A INT,@B int)
Returns int
As
Begin
Declare
@S int
Set @S='襲轎空'
Select @S=@A+@B
Return (@S)
End

--測試帆粗
--SELECT DBO.sumnum(1,2)

❹ 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
('記事本')

❺ 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

❻ 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

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

❼ sql 創建自定義函數

create function grade_fun
(
@學生 decimail(18,1)
)
returns decimail(18,1)
as
begin
declare @a decimail(18,1)
select @a=sum(grade) from 成績慶猜團表譽橘兆仿 where 學生=@學生
return @a
end

❽ 寫一個Sql自定義函數

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

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

熱點內容
捷達方向機安全登錄密碼是多少 發布:2025-07-19 00:57:37 瀏覽:688
夜魔迅雷下載ftp 發布:2025-07-19 00:39:29 瀏覽:94
增值稅票安全接入伺服器地址 發布:2025-07-19 00:20:45 瀏覽:481
solidworkspcb伺服器地址 發布:2025-07-18 22:50:35 瀏覽:816
怎麼在堆疊交換機里配置vlan 發布:2025-07-18 22:42:35 瀏覽:625
java調用別人的介面 發布:2025-07-18 22:37:35 瀏覽:435
伺服器四個節點如何聯網 發布:2025-07-18 22:36:02 瀏覽:273
華強北什麼地方休安卓手機 發布:2025-07-18 22:24:56 瀏覽:736
資料庫的根本目標 發布:2025-07-18 21:37:50 瀏覽:939
壓縮機的流速 發布:2025-07-18 21:37:40 瀏覽:408