熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

存儲過程批量刪除記錄

2022-06-13   來源: Oracle 

  CREATE PROCEDURE XTJ_NewsInfor_DeleteArray

  @ID nvarchar()

  as

  DECLARE @PointerPrev int

  DECLARE @PointerCurr int

  DECLARE @TId int

  Set @PointerPrev=

  while (@PointerPrev < LEN(@ID))

  Begin

  Set @PointerCurr=CharIndex(@ID@PointerPrev)

  if(@PointerCurr>)

  Begin

  set @TId=cast(SUBSTRING(@ID@PointerPrev@PointerCurr@PointerPrev) as int)

  Delete from XTJ_NewsInfor where ID=@TID

  SET @PointerPrev = @PointerCurr+

  End

  else

  Break

  End

  刪除最後一個因為最後一個後面沒有逗號所以在循環中跳出需另外再刪除

  set @TId=cast(SUBSTRING(@ID@PointerPrevLEN(@ID)@PointerPrev+) as int)

  Delete from XTJ_NewsInfor where ID=@TID

  GO

  下來要批量刪除記錄的話只要給存儲過程傳參……n存儲過程就會刪除相應的記錄


From:http://tw.wingwit.com/Article/program/Oracle/201311/18463.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.