sql server 存儲過程 聲明變量declare @testValue int,默認值是NULL

在sqlServer存儲過程中,聲明一個變量,但是沒有賦值的情況下,其值默認爲NULL

測試代碼:

create PROCEDURE [dbo].[test]
AS
BEGIN
declare @testValue int
print '聲明@testValue 並不賦值'
if(@testValue IS NULL)
	print '@testValue is null'
else
	print '@testValue is not null'
--設置爲0
print '賦值@testValue =0'
set @testValue =0
if(@testValue IS NULL)
	print '@testValue is null'
else
	print '@testValue is not null'
END

執行及結果:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章