實際上,無論是否指定返回值,程式都會返回乙個值。預設時,在儲存過程完成時,sql service會自動返回乙個值0.
要從儲存過程向呼叫它的**返回值,可以簡單的使用return語句
return[《返回整數值》]
注意返回值一定是整數
關於return語句,也許我們最了解的就是它在儲存過程中無條件的退出。無論在儲存過程中的什麼位置,只要呼叫return語句,其後的所有**都不會被執行。
下面是一段測試**
use adventureworks//adventureworks是mssql的乙個資料庫例項,關於adventureworks的安裝,我在另一篇文章中有介紹
gocreate proc sptestreturns
asdeclare @mymessage varchar(50)
declare @myothermessage varchar(5)
select @mymessage='hi,it''s that line before the return'
print @mymessage
return
select @myothermessage='sorry,but we don''t get this far'
print @myothermessage
return
現在你已經擁有乙個儲存過程了,但還需要一小段指令碼來測試一下
要捕獲return語句的返回值,需要在exec語句執行時,將其賦值到乙個變數中
下面測試一下
declare @return int
exec @return=sptestreturns
select @return
返回結果如下:
hi,it's that line before the return
(1 行受影響)
同時還得到了儲存過程的返回值,在這裡是0.即使沒有專門指定乙個特定的返回值,該返回值也會是0.這是因為預設值總是0.
下面修改一下上面的**,可以根據需要返回任何整數值
use adventureworks
gocreate proc sptestreturns
asdeclare @mymessage varchar(50)
declare @myothermessage varchar(5)
select @mymessage='hi,it''s that line before the return'
print @mymessage
return 100
select @myothermessage='sorry,but we don''t get this far'
print @myothermessage
return
declare @return int
exec @return=sptestreturns
select @return
返回結果:
hi,it's that line before the return
(1 行受影響)
同時還得到了儲存過程的返回值,在這裡是100.
js中return的用法
1.返回函式結果 語法 return 表示式 表示從被調函式返回到主調函式繼續執行,返回時可附帶乙個返回值,由return後面的引數指定。return通常是必要的,因為return呼叫時候的計算結果,通常是通過返回值帶出的。function add function fun fun 3return ...
js中return的用法
在大多數情況下,為事件處理函式返回false,可以防止預設的事件行為.例如,預設情況下點選乙個元素,頁面會跳轉到該元素href屬性指定的頁.return false 就相當於終止符,return true 就相當於執行符。在js中return false的作用一般是用來取消預設動作的。比如你單擊乙個...
js中return的用法
一 返回控制與函式結果 語法 return 表示式 在函式語句結束時執行,並返回表示式的值作為函式的結果 二 返回控制 返回空值,語法 return 一般來講,為事件處理函式返回return false 作用在於阻止預設事件行為和取消預設動作,比如,在預設情況下點選乙個元素,那麼頁面就會跳轉到元素h...