預存程序,資料庫預存程序

來源:互聯網
上載者:User

預存程序,資料庫預存程序

use yuyongTest;

go

 

--定義一個預存程序,給這個預存程序傳入int一個參數,這個預存程序將為一個nvarchar(50)類型的參數賦值(以作為結果)

create procproc_getStudentName(@numint,@namenvarchar(50)out)

as

    select @name=namefrom student where number=@num;

go

--定義一個nvarchar(50)類型的變數,接受這個預存程序的賦值(相當於返回結果)

declare @getName nvarchar(50);

--執行預存程序,傳入輸入參數和需要接收結果的變數

exec proc_getStudentName62,@getName out;

select @getName;

 

select *from student where number=62

 

結果如下


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.