【正文】
和程序代碼語句的分離,可以提高程序代碼的可讀性。pingsql_statement 解釋:output:表示此參數(shù)是可傳回的 with*procoutput withfromint exec,100,total_price output和return都可在批次程式中用變量接收,而recordset則傳回到執(zhí)行批次的客戶端中。(selectau_info_all39。procedureauthorsjoinon go au_info_allpub_nameatitles=au_lname39。dull39。au_info39。39。dull39。au_info39?! ?ann39。au_info2 lastname39。ap like存儲過程可以用多種組合執(zhí)行。or executeau_info2,創(chuàng)建并存放于系統(tǒng)數(shù)據(jù)庫master中,并且名稱以sp_或者xp_開頭。 sp_who:用于顯示使用數(shù)據(jù)庫的當前用戶 sp_help:用于顯示參數(shù)清單和其數(shù)據(jù)類型。1 as select * from 學生 例:帶參數(shù)的存儲過程,查詢大于指定年齡的學生 create proc sp_getstu。必須提供一個數(shù)值作參數(shù)!39。 更新游標:數(shù)據(jù)庫對游標指向的當前行加鎖,當程序讀下一行數(shù)據(jù)時,本行數(shù)據(jù)解鎖,下一行數(shù)據(jù)加鎖。 end else begin set ssex=39。username tid int。= (select top(1) uid from dnt_users where username = 39。 set replies fetch next from ctemp into tid。update dnt_topics set replies = replies where posterid = uid and tid = tid。 deallocate ctemp。close ctemp。 = 0。 declare declare sno char(10),sname char(10),ssex char(2) open c1 fetch c1 into sno,sname,ssex while fetch_status==0 begin if ssex=39。3 22 print status七、存儲過程中游標的使用需要游標的數(shù)據(jù)操作 當select語句的結果中包含多個元組時,使用游標可以逐個存取這些元組 活動集:select語句返回的元組的集合 當前行:活動集中當前處理的那一行。張三39。 我們在創(chuàng)建存儲過程時,也可以定義自己的狀態(tài)碼和錯誤信息。 sp_stored_procedures:用于返回當前數(shù)據(jù)庫中的存儲過程的清單。 以上主要是用戶存儲過程,下面介紹一下系統(tǒng)存儲過程。or executeor execute39。au_info2andjointa au_fname,d%39。39。or au_info39。dull39。ann39。39。au_infoau_infoann39。39。au_infoau_infoonjoin=tavarchar(20) as selectlastnameau_info_all 如果該過程是批處理中的第一條語句,則可使用: au_info_all 實例4:使用帶有參數(shù)的簡單過程 createinnertitleauthorau_lname,=where該存儲過程不使用任何參數(shù)。+convert(varchar,total_price) go 在這里再啰嗦一下存儲過程的3種傳回值(方便正在看這個例子的朋友不用再去查看語法內容):,39。zhangsan39。(id,userid,sex,money)varchar(20),param3三、實例講解 實例1:只返回單一記錄集的存儲過程。procedue_name ?。?)擴展存儲過程二、存儲過程的優(yōu)點都有哪些呢? 1. 存儲過程只在創(chuàng)造時進行編譯即可,以后每次執(zhí)行存儲過程都不需再重新編譯,而我們通常使用的sql語句每執(zhí)行一次就編譯一次,所以使用存儲過程可提高數(shù)據(jù)庫執(zhí)行速度。但有一些限制。本選項不能和sysmentsencryptionserverserver{repileout