sqlserver存儲過程數組
仔細研究後在csdn上找到了解決該問題的辦法帖出來給大家共享一下
大致方法是利用傳遞長字元串的形式向存儲過程傳遞一個長字元串。由於sqlserver沒有 splite函數
所以必須自己定義一個splite函數來進行處理
自定義一個函數
create function f_splitstr(@SourceSql varchar(8000),@StrSeprate varchar(10))
returns @temp table(F1 varchar(100))asbegindeclare @i int
set @SourceSql=rtrim(ltrim(@SourceSql))
set @i=charindex(@StrSeprate,@SourceSql)while @i=1begininsert @temp values(left(@SourceSql,@i-1))
set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)endif @SourceSql<''
insert @temp values(@SourceSql)returnend-執行select * from dbo.f_splitstr('1,2,3,4',',')
注:'1,2,3,4'即你所傳遞的字元串
同樣你可以通過 select cunt(*) from dbo.f_splitstr('1,2,3,4',',')
獲得該字元串數組的長度
如果要刪除該函數使用--刪除函數drop function fsplit
『貳』 如何給SQLSERVER存儲過程傳遞數組參數
確切的說不行-SQL SERVER沒有數組類型,ANSI SQL 92標准也不支持數組。但可用其它的方法來實現。 1. You could simulate an array by passing one or more varchar(255) fields with comma-separated values and then use a WHILE loop with PATINDEX and SUBSTR to extract the values. 1、你可以使用幾個VARCHAR(255)欄位來模擬數組,欄位中用逗號分開各個數據,然後使用循環和PATINDEX和SUBSTR分開這些數據。 2. The more usual way to do this would be to populate a temporary table with the values you need and then use the contents of that table from within the stored-procere. Example of this below2、通常這種方法需要為這些數據創建一個臨時表,然後在存儲過程使用表中的內容。如下例create procere mytest @MyParmTempTable varchar(30)asbegin-- @MyParmTempTable contains my parameter list... 這個變數是包含參數的表名-- For simplicity use dynamic sql to into a normal temp table... create table #MyInternalList ( list_item varchar( 2 ) not null)set nocount oninsert #MyInternalList select * from sysobjects create table #MyList ( list_item varchar( 2 ) not null)insert #MyList values ( 'S' ) insert #MyList values ( 'U' ) insert #MyList values ( 'P' )exec mytest "#MyList"3. If all you wanted to do was use the array/list as input to an IN clause in a WHERE statement you could use :-3、如果你想在IN子句里使用輸入的數組參數可以這樣做:CREATE PROCEDURE sp_MyProcere (@MyCommaDelimitedString
『叄』 關於SQLserver 存儲過程 如何切割一個字元串 轉化為數組
Create Function [dbo].[Split](@Sql varchar(8000),@Splits varchar(10))
returns @temp Table (a varchar(100))
As
Begin
Declare @i Int
Set @Sql = RTrim(LTrim(@Sql))
Set @i = CharIndex(@Splits,@Sql)
While @i >= 1
Begin
Insert @temp Values(Left(@Sql,@i-1))
Set @Sql = SubString(@Sql,@i+1,Len(@Sql)-@i)
Set @i = CharIndex(@Splits,@Sql)
End
If @Sql <> ''
Insert @temp Values (@Sql)
Return
End
『肆』 sqlserver里存儲過程怎麼調用存儲過程
sqlserver里調用存儲過程的具體操作步驟如下:
1、打開SQL Server Managment管理工具,新建一個表。
『伍』 【SQL】存儲過程中如何定義數組
存儲過程里定義不了數組。如果是sqlserver,那麼你可以用表變數,游標來實現你的功能。
如果是sqlserver2005以上的版本,可以做clr存儲過程,那裡面是可以用數組的。
『陸』 sqlserver2008存儲過程的參數有數組類型嗎
您好,沒有數組類型的.所有的參數類型都是systypes表裡面的.
『柒』 【SQL】存儲過程中如何定義數組
存儲過程
里定義不了數組。如果是
sqlserver
,那麼你可以用表變數,游標來實現你的功能。
如果是
sqlserver2005
以上的版本,可以做clr存儲過程,那裡面是可以用數組的。
『捌』 mysql存儲過程存儲過程中能定義數組嗎
存儲過程里定義不了數組。如果是sqlserver,那麼你可以用表變數,游標來實現你的功能。
如果是sqlserver2005以上的版本,可以做clr存儲過程,那裡面是可以用數組的。