淺析SQLServer中的Scanf與Printf建站知識(shí)
導(dǎo)讀:1建站知識(shí)本篇文章是對(duì)SQLServer中的Scanf與Printf進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下網(wǎng)seo優(yōu)化趨勢(shì)公司網(wǎng)站建設(shè)。
SQLServer中有兩個(gè)擴(kuò)展存儲(chǔ)過程實(shí)現(xiàn)Scanf和Printf功能,恰當(dāng)?shù)氖褂盟鼈兛梢栽谔崛『推唇幼址畷r(shí)大幅度簡(jiǎn)化SQL代碼。1、xp_sscanf,用它可以分解格式相對(duì)固定的字符串,這對(duì)于厭倦使用一堆substring和charindex的朋友來說不錯(cuò)。比如前幾天的一個(gè)帖子中提出的如何分解ip地址,相對(duì)簡(jiǎn)練且通用的代碼應(yīng)該是下面這樣
復(fù)制代碼 代碼如下:
if (object_id ('f_getip' ) is not null )drop function f_getip go create function dbo . f_getip (@ ip varchar (100 ))returns @ t table (a int , b int , c int , d int )as begin set @ ip = replace (@ ip , '.' , ' ' ) declare營(yíng)銷型網(wǎng)站建設(shè) @ s1 varchar (3 ) , @ s2 varchar (3 ), @ s3 varchar (3 ) , @ s4 varchar (3 ) exec xp_sscanf @ ip , '%s %s %s %s' , @ s1 output , @ s2 output , @ s3 output , @ s4 output insert into @ t select @ s1 , @ s2 , @ s3 , @ s4 return end go select * from dbo . f_getip ('192.168.0.1' )go /* a b c d ----------- ----------- ----------- ----------- 192 168 0 1 */
2、xp_sprintf,用它可以拼接出一個(gè)字符串而不用擔(dān)心過多的加號(hào)很引號(hào)難以控制,比如一個(gè)動(dòng)態(tài)執(zhí)行sql語句的存儲(chǔ)過程復(fù)制代碼 代碼如下:
if (object_id ('p_select' ) is not nu網(wǎng)站推廣優(yōu)化seoll )drop proc p_select go create proc p_select (@ tb varchar (100 ), @ cols varchar (100 ), @ wherecol varchar (100 ), @ value varchar (100 ))as begin declare @ s varchar (8000 ) exec xp_sprintf @ s output , 'select %s from %s where %s=''%s''' , @ cols , @ tb , @ wherecol , @ value exec (@ s)end go exec p_select 'sysobjects' , 'id,xtype,crdate' , 'name' , 'p_select' /* id xtype crdate -----網(wǎng)站建設(shè)公司------ ----- ----------------------- 898102240 P 2009-08-18 03:01:51.153 */
相關(guān)網(wǎng)seo優(yōu)化趨勢(shì)公司網(wǎng)站建設(shè)。聲明: 本文由我的SEOUC技術(shù)文章主頁(yè)發(fā)布于:2023-05-23 ,文章淺析SQLServer中的Scanf與Printf建站知識(shí)主要講述標(biāo)簽,標(biāo)題,SQL網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請(qǐng)保留鏈接: http://www.bifwcx.com/article/web_5550.html
為你推薦與淺析SQLServer中的Scanf與Printf建站知識(shí)相關(guān)的文章
-
通王TWCMS 2.0.3網(wǎng)站模板程序下載
(126)人喜歡 2024-01-15 -
Windows官方原版在哪里下載
(175)人喜歡 2024-01-15 -
WordPress網(wǎng)站模板發(fā)帖標(biāo)題顏色設(shè)置
(131)人喜歡 2024-01-07 -
修改discuz論壇帖子標(biāo)題80字符的長(zhǎng)度限制
(249)人喜歡 2024-01-07 -
wordpress程序調(diào)用不帶超鏈接的Tag標(biāo)簽
(234)人喜歡 2024-01-05 -
網(wǎng)站在不同時(shí)期需調(diào)整內(nèi)容更新的方向
(112)人喜歡 2023-08-12