當前位置:首頁 » 編程語言 » sql參數數組
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql參數數組

發布時間: 2022-05-10 08:28:04

Ⅰ 如何用數組向sql中輸入數據

構造一個大的SQL語句唄,Insert into wer(A1,A2...A1000) Values(@a1,@a2,...@a1000)。裡面有1000個參數,給參數數組循環賦值,然後執行就可以了。
這個字元串,你可以用循環來生成
string Sql,param;
Sql="";param="";
for(int i=1;i<=1000;i++)
{
Sql+="A"+i.ToString()+",";
param+="@a"+i.ToString()+",";
}
Sql="Insert into wer("+Sql.Substring(0,Sql.Length-1)+") Values ("+param.Substring(0,param.Length-1));
給這個Sql的參數數組賦值,然後執行這個SQL;
不過我記得2000下面,單個SQL命令最大長度為4K位元組(記得不是太清楚了,你可以自己試試看),如果有1000個欄位,光寫欄位名就超過4K位元組了。
如果SQL語句太常,就需要拆分成兩條,一條插入,並返回一個id,然後根據第二條update,或者你的參數中自己就帶了一個id也可以。

Ⅱ sql存儲過程處理數組參數

declare@strvarchar(500)
declare@insertvarchar(8000)
select@insert='insertintoyouTablevalues'
select@str='str1,1,1,1,1|str2,2,2,2,2|str3,3,3,3,5|str4,4,4,45,4'
select@str=@insert+'('''+@str+''')'
select@str=REPLACE(@str,',',''',''')
select@str=REPLACE(@str,'|',''')'+CHAR(13)+@insert+'(''')
print@str
--exec(@str)動態執行下生成的語句就好了

--print結果如下:
insertintoyouTablevalues('str1','1','1','1','1')
insertintoyouTablevalues('str2','2','2','2','2')
insertintoyouTablevalues('str3','3','3','3','5')
insertintoyouTablevalues('str4','4','4','45','4')

Ⅲ 如何給SQL SERVER存儲過程傳遞數組參數

確切的說不行-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

Ⅳ php sql條件參數為數組

1、將二維數組轉換為一維數組

$arr_2 (這是二維數組,就是你上邊那個類型的,我這里就不貼了)
$arr_1 (這個保存轉化後的一維數組)

下面是二維轉化一維數組過程:
for($i=0;$i<count($arr_1);$i++){
$arr[] = $arr_2[$i]['cat_id'];
}

下面是循環輸出一維數組:

foreach($arr_1 as $key=>$val){
echo $key . '<br>' .$val;
}

輸出結果是所有的cat_id 鍵值。至於sql 中的循環,我想你看了這個以後應該會了。
原理就是將二維轉換為一維數組,然後根據條件實現循環查詢。這個轉化的過程,你可以使用for循環,也可以使用php自帶的合並數組函數,也可以使用高級點的spl高級數組合並。當然看你程序需要,如果是應用比較簡單的,循環是最佳選擇。

另外,邀請你加入我們php實驗室,相互學習。在此,祝聖誕快樂。

Ⅳ c# sql 參數數組 執行

wer(A1,A2...A1000) Values(@a1,@a2,...@a1000)。裡面有1000個參數,給參數數組循環賦值,然後執行就可以了。
這個字元串,你可以用循環來生成
string Sql,param;
Sql="";param="";
for(int i=1;i<=1000;i++)
{
Sql+="A"+i.ToString()+",";
param+="@a"+i.ToString()+",";
}
Sql="Insert into wer("+Sql.Substring(0,Sql.Length-1)+") Values ("+param.Substring(0,param.Length-1));
給這個Sql的參數數組賦值,然後執行這個SQL;
不過我記得2000下面,單個SQL命令最大長度為4K位元組(記得不是太清楚了,你可以自己試試看),如果有1000個欄位,光寫欄位名就超過4K位元組了。
如果SQL語句太常,就需要拆分成兩條,一條插入,並返回一個id,然後根據第二條update,或者你的參數中自己就帶了一個id也可以。
另外,虛機團上產品團購,超級便宜

Ⅵ SQL語句可以聲明使用數組么

SQL語句可以聲明使用數組,聲明方法為:

1、先定義一個數組,數組內容是一些數字,可以對應為數據表裡的id列。

Ⅶ 關於BaseDao中如何獲取sql參數數組

DECLARE @Test VARCHAR(50)
DECLARE @ArgsTable TABLE
(
Arg VARCHAR(50)
)

SET @Test = 'ASD,FGH,JKL,YUI'

DECLARE @TempIndex INT

WHILE @Test LIKE '%,%'
BEGIN
SET @TempIndex = CHARINDEX(',',@Test) --取出,位置

INSERT INTO @ArgsTable(Arg)
SELECT SUBSTRING(@Test,0,@TempIndex) --截取第一個參數

SET @Test = RIGHT(@Test,LEN(@Test) - @TempIndex) --使 @Test 取截後的字元串

IF @Test NOT LIKE '%,%' --如果是最後一個,加入列表並退出
BEGIN
INSERT INTO @ArgsTable(Arg)
SELECT @Test

BREAK;
END
END
SELECT * FROM @ArgsTable

Ⅷ 關於SqlParameter[] Params = new SqlParameter[1];請問在這聲明一個Sql輸入參數數組的作用的什麼

ProcStr 貌似是你自己寫的DataBase類的方法。
根據你的函數使用 我覺得這個函數的作用是返回滿足條件的記錄數。
int Count = -1; 是用來判斷SQL語句是否執行成功
因為執行DELETE FROM Usersmr WHERE UserID = @UserID 這句SQL的時候
滿足條件的記錄數可能為0 可能大於0
所以如果Count<0 就表示執行失敗。

具體函數的含義要具體看函數的源碼了

Ⅸ sql 存儲過程 傳入兩組數組參數

declare@nnvarchar(500)
declare@mnvarchar(500)
set@n='1,2,3,4,5'
set@m='a,b,c,d,e'

createtable#tb(nVARCHAR(500),mVARCHAR(500))
while(1=1)
begin
if(Charindex(',',@n)=0andCharindex(',',@m)=0)
begin
insertinto#tbvalues(@n,@m)
break
end
insertinto#tbvalues(Substring(@n,1,Charindex(',',@n)-1),Substring(@m,1,Charindex(',',@m)-1))
set@n=Right(@n,Len(@n)-Charindex(',',@n))
set@m=Right(@m,Len(@m)-Charindex(',',@m))
end

select*from#tb

droptable#tb

ps:要做好校驗!

Ⅹ sql存儲過程數組參數超難問題

--方法一,用字元串替換和拼接,構造成insert
into

select
的樣子,然後執行
--方法二,用字元串拆分
declare
@a
varchar(800)='str1,0,0,0|str2,0,0,0|str3,0,0,0'
set
@a='insert
into
t
select
'''+@a
set
@a=replace(replace(@a,'|','''
union
all
select
'''),',',''',''')+''''
exec(@a)
/*
insert
into
t
select
'str1','0','0','0'
union
all
select
'str2','0','0','0'
union
all
select
'str3','0','0','0'
*/