我正在开发一个将数据存储在DB2中的应用程序,我应该能够在数据库表中批量删除数据。实际上,“删除”数据的方法是将其“已删除”值更改为“ Y”。
表的形式为:
id |名称|删除|
1 |名称1 | N |
2 | name2 | N |
...
x | namex | N |
我要做的是制作一个SQL存储过程,该存储过程将一个数组作为参数,该数组具有我需要从“ N”更改为“ Y”的项的ID。
我的操作方式(单独)是:
Private Sub CommandButton1_Click()
Dim rowcount As Long
Dim ws As worksheet
Set ws = Worksheets("Raw Data")
rowcount = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).row
With ws
.Cells(rowcount, 0).Value = Me.TextBox1.Value
.Cells(rowcount, 1).Value = Me.TextBox2.Value
.Cells(rowcount, 2).Value = Me.TextBox3.Value
.Cells(rowcount, 3).Value = Me.TextBox4.Value
.Cells(rowcount, 4).Value = Me.TextBox5.Value
.Cells(rowcount, 5).Value = Me.TextBox6.Value
.Cells(rowcount, 6).Value = Me.TextBox7.Value
.Cells(rowcount, 7).Value = Me.TextBox8.Value
.Cells(rowcount, 8).Value = Me.TextBox9.Value
.Cells(rowcount, 9).Value = Me.TextBox10.Value
.Cells(rowcount, 10).Value = Me.PNBox.Value
.Cells(rowcount, 11).Value = Me.ENBox.Value
.Cells(rowcount, 12).Value = Me.CheckBox4.Value
.Cells(rowcount, 13).Value = Me.CheckBox5.Value
.Cells(rowcount, 14).Value = Me.CheckBox6.Value
.Cells(rowcount, 15).Value = Me.CheckBox7.Value
.Cells(rowcount, 19).Value = Me.CheckBox11.Value
.Cells(rowcount, 20).Value = Me.CheckBox12.Value
.Cells(rowcount, 21).Value = Me.CheckBox13.Value
.Cells(rowcount, 22).Value = Me.CheckBox14.Value
因此,对于存储过程,我应该只使用以下形式发送数组:
UPDATE MyTable DELETED = 'Y' where id = '1';
,带有这些ID的行应更改为Y。
我正在考虑的存储过程的结构是:
[1, 20, 5, ... , x]
有人可以帮我吗?谢谢!
答案 0 :(得分:0)
尝试将ID列表作为“类似于xml”的字符串传递:
UPDATE MyTable t
SET DELETED = 'Y'
where exists (
select 1
from xmltable (
'$D/d/i' passing xmlparse(document '<d><i>1</i><i>20</i><i>5</i></d>') as "D"
columns
i int path '.'
) p
where p.i=t.id
)