SQL Server- 預存程序

來源:互聯網
上載者:User

標籤:

--================================ -- ylb:預存程序建立與操作 --================================ use pubs  go --一、無參預存程序 --1,建立預存程序 create procedure PTitles as select * from titles  go --2,執行預存程序 execute PTitles  go --3,移除預存程序 --drop procedure PTitles go   --============================== -- ylb:預存程序-入參 -- 16:44 2011/12/14 --============================== use pubs  go --1,建立帶入參預存程序 select * from titles where type= ‘business‘  go create proc P_Titles_ByType @type char (12) --入參 as select * from titles where [email protected]    go --2,執行帶參數的預存程序 --a)方式一 exec P_Titles_ByType @type= ‘business‘ go --b)方式二 exec P_Titles_ByType ‘business‘  go --P1:寫一個預存程序,要求圖書類型是business且單價大於10的所有資訊 --P1_1,建立預存程序 select * from titles where type= ‘business‘ and price>10  go create proc P_Titles_ByTypeAndPrice @type char (12), --入參 @price money --入參 as select * from titles where [email protected] and price>@price  go --P1_2,執行預存程序 exec P_Titles_ByTypeAndPrice @type= ‘business‘ ,@price=10  go exec P_Titles_ByTypeAndPrice @price=10,@type= ‘business‘  go exec P_Titles_ByTypeAndPrice ‘business‘ ,10  go --是錯的,當你直接給值時,一定注意參數的順序和類型。 --exec P_Titles_ByTypeAndPrice 10,‘business‘  --================================ -- ylb:預存程序-帶入參和出參 -- 16:44 2011/12/14 --================================ use pubs  go select * from titles --P1:查圖書編號是“BU1032”的圖書的單價是多少? select price from titles where title_id= ‘BU1032‘  go --P1_1,建立 create proc P_Titles_ByTitleID_SelectPrice @title_id varchar (6) --入參 as select price from titles where [email protected]_id  go --P1_2,執行 exec P_Titles_ByTitleID_SelectPrice ‘BU1032‘  go --P2_1,建立 create proc P_Titles_ByTitleID_SelectPrice2 @title_id varchar (6), --入參 @price money output   --出參【出參加標識(output)】 as select @price=price from titles where [email protected]_id --出參的@在=左邊  go --1,先聲明變數 declare @price2 money --2,之後在調用 exec P_Titles_ByTitleID_SelectPrice2 @title_id= ‘BU1032‘ , @[email protected] output --3,再之後在查聲明變數 select @price2 --出參要聲明,配參後面要加output標識,之後再查聲明變數。

SQL Server- 預存程序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.