帶輸出引數的儲存過程的使用及在C 中呼叫問題

2021-03-31 16:10:10 字數 1011 閱讀 9785

建立示例儲存過程的完整的語句:

use pubs

if exists (select name from sysobjects

where name = 'up_test ' and type = 'p')

drop procedure up_test

gocreate procedure  up_test  

@out_val integer=0 output

--@out_val integer output    ------1

asbegin

--set @out_val=0 

-----2

if(1=1)                 

-----3

set @out_val=@out_val+1

return 9;

end儲存過程在查詢分析其中使用示例:

1、簡單呼叫

exec up_test  3

--注:呼叫時也要給輸出引數傳值,有給定預設值時可以不再給引數指定值

2、呼叫並使用儲存過程中的輸出引數和返回值

declare @ret_val int

declare @output_val int

exec @ret_val=up_test @out_val=@output_val output     

-----4

select @ret_val,@output_val

值得說明的是:如果只是給定了預設值,呼叫時未給該輸出引數傳值,並且儲存過程體中並沒有諸如

set @out_val=0的顯式為

輸出引數

賦值的語句(使用

set @out_val=@out_val+1

是不行的

),那麼在執行完儲存過程後,輸出引數的帶回值是null

。這一點我在使用c#的呼叫中遇到了,還讓我除錯程式好久。後來在sql serve 查詢分析器了看到null

才恍悟。

帶輸出引數的儲存過程的使用及在C 中呼叫問題

建立示例儲存過程的完整的語句 use pubs if exists select name from sysobjects where name up test and type p drop procedure up test gocreate procedure up test out val ...

帶輸出引數的儲存過程的使用及在C 中呼叫問題

建立示例儲存過程的完整的語句 use pubs if exists select name from sysobjects where name up test and type p drop procedure up test gocreate procedure up test out val ...

帶輸出引數的儲存過程的使用及在C 中呼叫問題

建立示例儲存過程的完整的語句 use pubs if exists select name from sysobjects where name up test and type p drop procedure up test gocreate procedure up test out val ...

執行帶輸出引數的儲存過程

declare msg varchar 100 exec submitinfo 34342 90782528352907 0,1,kf01 msg output select msg msg 為返回的資訊 儲存過程一部分 alter proc dbo submitinfo name varchar ...

c 呼叫帶輸出引數的儲存過程

c 呼叫帶輸出引數的儲存過程。先給出一個例項,用 說話。首先在sql server中編寫一個儲存過程 csharp view plain copy create procedure progetpwd username varchar 20 password varchar 20 output as...