儲存過程中IN 引數的使用

2021-09-30 03:36:39 字數 445 閱讀 3018

在sql語句中,我們有時會因批量刪除而用到in語句,如delete from table where field in (1,2,3),一般在儲存過程中我們會寫成delete from table where field in (@field),但現在出現乙個問題,@field到底是什麼型別,如何去寫,我們得用sp_executesql,此句應該是對sql語句執行替換,也就是將引數原封不動的替換到sql語句中,然後再執行

例項如下:

create procedure an_accountlist_delete @al_id nvarchar(80)

asdeclare @tt nvarchar(800)

set @tt='delete from an_accountlist where al_id in ('+@al_id+')'

exec sp_executesql @tt

go

儲存過程中,if語句使用

if語句 判斷使用者輸入的數字 set serveroutput on 1.提示資訊 2.接收鍵盤輸入 num 是乙個位址值 sql優化 num繫結變數 盡量使用繫結變數 select from emp where deptno 10 執行計畫 select from emp where deptn...

儲存過程中的游標使用

利用儲存過程來消除資料庫中冗餘的資料 create procedure sp mytest as declare pro varchar 50 declare mm int declare wu cursor for select distinct product from mytest open ...

儲存過程中SELECT INTO的使用

在mysql儲存過程中使用select into語句為變數賦值 用來將查詢返回的一行的各個列值儲存到區域性變數中。要求 查詢的結果集中只能有1行。select col name into var name table expr 使用select into語句在資料庫中進行查詢,並將得到的結果賦值給變...