锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品亚洲综合一区在线观看,亚洲人和日本人jizz,亚洲国产精品SSS在线观看AVhttp://www.tkk7.com/Reg/category/45432.htmlzh-cnSat, 19 Mar 2011 02:45:28 GMTSat, 19 Mar 2011 02:45:28 GMT60鏄劇ずsql server鐨勬煡璇㈣鍙ヨ繍琛屾椂闂達紝鍏蜂綋鍒版縐?/title><link>http://www.tkk7.com/Reg/archive/2011/03/18/346546.html</link><dc:creator>鑹炬嘗</dc:creator><author>鑹炬嘗</author><pubDate>Fri, 18 Mar 2011 08:31:00 GMT</pubDate><guid>http://www.tkk7.com/Reg/archive/2011/03/18/346546.html</guid><wfw:comment>http://www.tkk7.com/Reg/comments/346546.html</wfw:comment><comments>http://www.tkk7.com/Reg/archive/2011/03/18/346546.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/Reg/comments/commentRss/346546.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/Reg/services/trackbacks/346546.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #0000ff">declare</span><span style="color: #000000">   </span><span style="color: #008000">@ct</span><span style="color: #000000">   </span><span style="color: #000000; font-weight: bold">datetime</span><span style="color: #000000">   <br />   </span><span style="color: #0000ff">set</span><span style="color: #000000">   </span><span style="color: #008000">@ct</span><span style="color: #000000">   </span><span style="color: #808080">=</span><span style="color: #000000">   </span><span style="color: #ff00ff">getdate</span><span style="color: #000000">()   <br />   </span><span style="color: #008080">--</span><span style="color: #008080">-   </span><span style="color: #008080"><br /> </span><span style="color: #000000">  </span><span style="color: #008080">--</span><span style="color: #008080">sql   璇彞   </span><span style="color: #008080"><br /> </span><span style="color: #000000"><br />   </span><span style="color: #008080">--</span><span style="color: #008080">-   </span><span style="color: #008080"><br /> </span><span style="color: #000000">  </span><span style="color: #0000ff">select</span><span style="color: #000000">   </span><span style="color: #ff00ff">datediff</span><span style="color: #000000">(ms,   </span><span style="color: #008000">@ct</span><span style="color: #000000">   ,</span><span style="color: #ff00ff">getdate</span><span style="color: #000000">())   </span><span style="color: #0000ff">as</span><span style="color: #000000">   </span><span style="color: #ff0000">'</span><span style="color: #ff0000">鏌ヨ鏃墮棿錛堟縐掞級</span><span style="color: #ff0000">'</span><span style="color: #000000"> <br /> </span></div> <img src ="http://www.tkk7.com/Reg/aggbug/346546.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/Reg/" target="_blank">鑹炬嘗</a> 2011-03-18 16:31 <a href="http://www.tkk7.com/Reg/archive/2011/03/18/346546.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏍?Oracle鐢⊿tart with...Connect By瀛愬彞閫掑綊鏌ヨhttp://www.tkk7.com/Reg/archive/2011/03/16/346370.html鑹炬嘗鑹炬嘗Wed, 16 Mar 2011 03:30:00 GMThttp://www.tkk7.com/Reg/archive/2011/03/16/346370.htmlhttp://www.tkk7.com/Reg/comments/346370.htmlhttp://www.tkk7.com/Reg/archive/2011/03/16/346370.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/346370.htmlhttp://www.tkk7.com/Reg/services/trackbacks/346370.htmlStart withConnect By瀛愬彞閫掑綊鏌ヨ涓鑸敤浜庝竴涓〃緇存姢鏍戝艦緇撴瀯鐨勫簲鐢ㄣ?br /> 鍒涘緩紺轟緥琛細
CREATE TABLE TBL_TEST
(
  ID    
NUMBER,
  NAME  
VARCHAR2(100 BYTE),
  PID   
NUMBER                                  DEFAULT 0
);
 
鎻掑叆嫻嬭瘯鏁版嵁錛?br />
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('1','10','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('2','11','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('3','20','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('4','12','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('5','121','2');
 
浠嶳oot寰鏍戞湯姊㈤掑綊
select * from TBL_TEST
 start 
with id=1
 connect 
by prior id = pid
 
浠庢湯姊㈠線鏍慠OOT閫掑綊
select * from TBL_TEST
 start 
with id=5
 connect 
by prior pid = id
=====
瀵逛簬oracle榪涜綆鍗曟爲鏌ヨ(閫掑綊鏌ヨ)

DEPTID PAREDEPTID NAME 
NUMBER NUMBER CHAR (40 Byte) 
閮ㄩ棬id 鐖墮儴闂╥d(鎵灞為儴闂╥d) 閮ㄩ棬鍚嶇О 


閫氳繃瀛愯妭鐐瑰悜鏍硅妭鐐硅拷鏈?

Sql浠g爜 
1.select * from persons.dept start with deptid=76 connect by prior paredeptid=deptid   
Sql浠g爜  
1.select * from persons.dept start with deptid=76 connect by prior paredeptid=deptid   
 
select * from persons.dept start with deptid=76 connect by prior paredeptid=deptid  

閫氳繃鏍硅妭鐐歸亶鍘嗗瓙鑺傜偣. 

Sql浠g爜 
1.select * from persons.dept start with paredeptid=0 connect by prior deptid=paredeptid   
Sql浠g爜  
1.select * from persons.dept start with paredeptid=0 connect by prior deptid=paredeptid   
select * from persons.dept start with paredeptid=0 connect by prior deptid=paredeptid  

鍙氳繃level 鍏抽敭瀛楁煡璇㈡墍鍦ㄥ眰嬈? 

Sql浠g爜 
1.select a.*,level from persons.dept a start with paredeptid=0 connect by prior deptid=paredeptid   
Sql浠g爜  
1.select a.*,level from persons.dept a start with paredeptid=0 connect by prior deptid=paredeptid   
select a.*,level from persons.dept a start with paredeptid=0 connect by prior deptid=paredeptid  

鍐嶆澶嶄範涓涓?start 
with connect by 鐨勭敤娉曪紝 start with 鍚庨潰鎵璺熺殑灝辨槸灝辨槸閫掑綊鐨勭瀛愩?nbsp;

閫掑綊鐨勭瀛愪篃灝辨槸閫掑綊寮濮嬬殑鍦版柟 connect 
by 鍚庨潰鐨?prior" 濡傛灉緙虹渷錛氬垯鍙兘鏌ヨ鍒扮鍚堟潯浠剁殑璧峰琛岋紝騫朵笉榪涜閫掑綊鏌ヨ錛?nbsp;

connect 
by prior 鍚庨潰鎵鏀劇殑瀛楁鏄湁鍏崇郴鐨勶紝瀹冩寚鏄庝簡鏌ヨ鐨勬柟鍚戙?nbsp;

緇冧範錛?nbsp;閫氳繃瀛愯妭鐐硅幏寰楅《鑺傜偣 

Sql浠g爜 
1.select FIRST_VALUE(deptid) OVER (ORDER BY LEVEL DESC ROWS UNBOUNDED PRECEDING) AS firstdeptid from persons.dept start with deptid=76 connect by prior paredeptid=deptid  
====榪欑鏂規硶鍙槸褰撹〃閲屽氨鏈変竴棰楁爲,澶氭5鏍戞庝箞鍔烇紵

.澹版槑錛欽avaEye鏂囩珷鐗堟潈灞炰簬浣滆咃紝鍙楁硶寰嬩繚鎶ゃ傛病鏈変綔鑰呬功闈㈣鍙笉寰楄漿杞姐?nbsp;


鑹炬嘗 2011-03-16 11:30 鍙戣〃璇勮
]]>
SQLSERVER 瀛楃鍑芥暟鏁寸悊http://www.tkk7.com/Reg/archive/2011/03/16/346369.html鑹炬嘗鑹炬嘗Wed, 16 Mar 2011 03:17:00 GMThttp://www.tkk7.com/Reg/archive/2011/03/16/346369.htmlhttp://www.tkk7.com/Reg/comments/346369.htmlhttp://www.tkk7.com/Reg/archive/2011/03/16/346369.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/346369.htmlhttp://www.tkk7.com/Reg/services/trackbacks/346369.html銆銆/* 瀛楃鍑芥暟 */
銆銆
/* 榪斿洖瀛楃琛ㄨ揪寮忎腑鏈宸︿晶瀛楃鐨凙SCII浠g爜鍊?nbsp;*/
銆銆
select Ascii(‘a‘) --a:97,A:65
銆銆/* 灝嗘暣鏁癆SCII浠g爜杞崲涓哄瓧絎?nbsp;*/
銆銆
select Char(97)--97:a,65:A
銆銆/* 榪斿洖琛ㄨ揪寮忎腑鎸囧畾瀛楃鐨勫紑濮嬩綅緗?nbsp;*/
銆銆
select Charindex(‘b‘,‘abcdefg‘,5)
銆銆
/* 浠ユ暣鏁拌繑鍥炰袱涓瓧絎﹁〃杈懼紡鐨凷OUNDEX鍊間箣宸?nbsp;*/
銆銆
select Difference(‘bet‘,‘bit‘)--3
銆銆/* 榪斿洖瀛楃琛ㄨ揪寮忔渶宸︿晶鎸囧畾鏁扮洰鐨勫瓧絎?nbsp;*/
銆銆
select Left(‘abcdefg‘,3)--abc
銆銆/* 榪斿洖緇欏畾瀛楃涓茶〃杈劇殑瀛楃鏁?nbsp;*/
銆銆
select Len(‘abcdefg‘)--7
銆銆/* 榪斿洖灝嗗ぇ鍐欏瓧絎﹁漿鎹負灝忓瓧絎︾殑瀛楃琛ㄨ揪寮?nbsp;*/
銆銆
select Lower(‘ABCDEFG‘)--abcdefg
銆銆/* 榪斿洖鍒犻櫎浜嗗墠瀵肩┖鏍間箣鍚庡瓧絎﹁〃杈懼紡 */
銆銆
select Ltrim(‘銆銆 abcdefg‘)--abcdefg
銆銆/* 榪斿洖鍏鋒湁緇欏畾鐨勬暣鏁頒唬鐮佺殑UNICODE瀛楃 */
銆銆
select Nchar(65)--A
銆銆/* 榪斿洖鎸囧畾琛ㄨ揪寮忎腑妯″紡絎竴嬈″嚭鐜扮殑寮濮嬩綅緗?nbsp;*/
銆銆
select Patindex(‘%_cd%‘,‘abcdefg‘)--2
銆銆/* 榪斿洖涓烘垚涓烘湁鏁堢殑SQL SERVER鍒嗛殧鏍囪瘑絎﹁屾坊鍔犱簡鍒嗛殧絎︾殑UNICODE瀛楃涓?nbsp;*/
銆銆
select Quotename(‘create table‘)
銆銆
/* 鐢ㄧ涓変釜琛ㄨ揪寮忔浛鎹㈢涓涓〃杈懼紡涓嚭鐜扮殑絎簩涓〃杈懼紡 */
銆銆
select Replace(‘abcdefg‘,‘cd‘,‘xxx‘)--abxxxefg
銆銆/* 鎸夋寚瀹氭鏁伴噸澶嶈〃杈懼紡 */
銆銆
select Replicate(‘abc|‘,4)--abc|abc|abc|abc|
銆銆/* 榪斿洖瀛楃琛ㄨ揪寮忕殑閫嗗悜琛ㄨ揪寮?nbsp;*/
銆銆
select Reverse(‘abc‘)--cba
銆銆/* 榪斿洖瀛楃琛ㄨ揪寮忓彸渚ф寚瀹氭暟鐩殑瀛楃 */
銆銆
select Right(‘abcd‘,3)--bcd
銆銆/* 榪斿洖鎴柇浜嗘墍鏈夊熬闅忕┖鏍間箣鍚庣殑瀛楃琛ㄨ揪寮?nbsp;*/
銆銆
select Rtrim(‘abcd銆銆銆 ‘)--abcd
銆銆/* 榪斿洖鐢卞洓涓瓧絎﹁〃杈劇殑SOUNDEX浠g爜 */
銆銆
select Soundex(‘abcd‘)--A120
銆銆/* 榪斿洖鐢遍噸澶嶇┖鏍肩粍鎴愮殑瀛楃涓?nbsp;*/
銆銆
select Space(10)--[銆銆]
銆銆/* 榪斿洖浠庨粯璁よ〃杈捐漿鎹㈣屾潵鐨勫瓧絎︿覆 */
銆銆
select Str(100)--[銆銆銆銆 100]
銆銆/*銆 */
銆銆
select Str(100,3)--[100]
銆銆/*銆 */
銆銆
select Str(14.4444,5,4)--[14.44]
銆銆/* 鍒犻櫎鎸囧畾闀垮害鐨勫瓧絎?騫跺湪鎸囧畾鐨勮搗鐐瑰鎻掑叆鍙︿竴緇勫瓧絎?nbsp;*/
銆銆
select Stuff(‘abcdefg‘,2,4,‘xxx‘)--axxxfg
銆銆/* 榪斿洖瀛楃琛ㄨ揪寮?浜岃繘鍒?鏂囨湰琛ㄨ揪寮忔垨鍥懼儚琛ㄨ揪鐨勪竴閮ㄥ垎 */
銆銆
select Substring(‘abcdefg‘,2,3)--bcd
銆銆/* 榪斿洖琛ㄨ揪絎竴涓瓧絎︾殑UNICODE鏁存暟鍊?nbsp;*/
銆銆
select Unicode(‘a‘)--97
銆銆/* 榪斿洖灝嗗皬鍐欏瓧絎﹁漿鎹負澶у啓瀛楃鐨勫瓧絎﹁〃杈懼紡 */
銆銆
select Upper(‘a‘)--‘A‘

鑹炬嘗 2011-03-16 11:17 鍙戣〃璇勮
]]>
SQLSERVER 鏁板瓧鏍煎紡鍖?/title><link>http://www.tkk7.com/Reg/archive/2011/03/15/346336.html</link><dc:creator>鑹炬嘗</dc:creator><author>鑹炬嘗</author><pubDate>Tue, 15 Mar 2011 09:57:00 GMT</pubDate><guid>http://www.tkk7.com/Reg/archive/2011/03/15/346336.html</guid><wfw:comment>http://www.tkk7.com/Reg/comments/346336.html</wfw:comment><comments>http://www.tkk7.com/Reg/archive/2011/03/15/346336.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/Reg/comments/commentRss/346336.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/Reg/services/trackbacks/346336.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #ff00ff">Cast</span><span style="color: #000000">(</span><span style="color: #ff00ff">round</span><span style="color: #000000">((a.M_weight</span><span style="color: #808080">*</span><span style="color: #000000">a.length</span><span style="color: #808080">*</span><span style="color: #000000">a.R_NUMBER),</span><span style="color: #800000; font-weight: bold">2</span><span style="color: #000000">) </span><span style="color: #0000ff">as</span><span style="color: #000000"> numeric(</span><span style="color: #800000; font-weight: bold">12</span><span style="color: #000000">,</span><span style="color: #800000; font-weight: bold">2</span><span style="color: #000000">))total</span></div> <img src ="http://www.tkk7.com/Reg/aggbug/346336.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/Reg/" target="_blank">鑹炬嘗</a> 2011-03-15 17:57 <a href="http://www.tkk7.com/Reg/archive/2011/03/15/346336.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>SQL SERVER 2008 PIVOThttp://www.tkk7.com/Reg/archive/2011/03/09/346046.html鑹炬嘗鑹炬嘗Wed, 09 Mar 2011 09:57:00 GMThttp://www.tkk7.com/Reg/archive/2011/03/09/346046.htmlhttp://www.tkk7.com/Reg/comments/346046.htmlhttp://www.tkk7.com/Reg/archive/2011/03/09/346046.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/346046.htmlhttp://www.tkk7.com/Reg/services/trackbacks/346046.html select doctype,docid,pro_type,create_date from TSPRO_SALESROOM_STOCKIN_MAIN where CREATE_DATE>'2011-02-01' and CREATE_DATE<='2011-02-28'
 
  
select count(*from TSPRO_SALESROOM_STOCKIN_MAIN where CREATE_DATE>'2011-02-01' and CREATE_DATE<='2011-02-28' and pro_type=2
 
 
 
SELECT pro_type,
[1] AS JAN,
[2] AS FEB,
[3] AS MAR,
[4] AS APR
 
from (
 
select pro_type,DATEPART(MM,create_date) AS MON 
  
from TSPRO_SALESROOM_STOCKIN_MAIN where CREATE_DATE>'2011-01-20' and CREATE_DATE<='2011-03-09'
 )s 
 PIVOT
 (
     
COUNT(MON) FOR MON IN ([1],[2],[3],[4])
 )
AS p

        
        
        


鑹炬嘗 2011-03-09 17:57 鍙戣〃璇勮
]]>
嫻佹按鍙峰垱寤?SQL2005)http://www.tkk7.com/Reg/archive/2010/12/16/340917.html鑹炬嘗鑹炬嘗Thu, 16 Dec 2010 11:39:00 GMThttp://www.tkk7.com/Reg/archive/2010/12/16/340917.htmlhttp://www.tkk7.com/Reg/comments/340917.htmlhttp://www.tkk7.com/Reg/archive/2010/12/16/340917.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/340917.htmlhttp://www.tkk7.com/Reg/services/trackbacks/340917.htmlright(cast(power(10,8as varchar)+IDENT_CURRENT('tablebame'),8)


鑹炬嘗 2010-12-16 19:39 鍙戣〃璇勮
]]>
SQL Server 2005 鑷畾涔夊嚱鏁拌姹囧皬緇?/title><link>http://www.tkk7.com/Reg/archive/2010/12/16/340916.html</link><dc:creator>鑹炬嘗</dc:creator><author>鑹炬嘗</author><pubDate>Thu, 16 Dec 2010 11:38:00 GMT</pubDate><guid>http://www.tkk7.com/Reg/archive/2010/12/16/340916.html</guid><wfw:comment>http://www.tkk7.com/Reg/comments/340916.html</wfw:comment><comments>http://www.tkk7.com/Reg/archive/2010/12/16/340916.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/Reg/comments/commentRss/340916.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/Reg/services/trackbacks/340916.html</trackback:ping><description><![CDATA[<div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 0);">鐢變簬宸ヤ綔鐨勯渶瑕侊紝浜嗚В涓婼QL Server </span><span style="color: rgb(128, 0, 0); font-weight: bold;">2005</span><span style="color: rgb(0, 0, 0);"> 鍑芥暟鐨勫啓娉曪紝鐜板湪鎬葷粨涓涓嬶細<br /> <br /> 瀵逛簬SQL Server </span><span style="color: rgb(128, 0, 0); font-weight: bold;">2005</span><span style="color: rgb(0, 0, 0);"> 鏁版嵁搴撹岃█錛屽嚱鏁頒笌瀛樺偍榪囩▼鍦ㄨ娉曟柟闈㈡槸鏈夊緢澶х殑鐩稿悓鐐癸紝<br /> <br /> 鏈澶х殑涓嶅悓灝辨槸鍑芥暟鏈夎繑鍥炲鹼紝鐩存帴浣跨敤returns ,鑰屽瓨鍌ㄨ繃紼嬪垯浣跨敤output鏉ュ0鏄庤緭鍑哄彉閲?br /> <br /> 涓銆佷笅闈㈠厛璇存槑涓嬶紝濡備綍鍒涘緩鍑芥暟<br /> <br /> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);">銆佸垱寤烘病鏈夎繑鍥炲間笌娌℃湁鍙傛暟鐨勫嚱鏁?br /> <br /> </span><span style="color: rgb(0, 0, 255);">CREATE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">FUNCTION</span><span style="color: rgb(0, 0, 0);"> my_function()<br /> <br /> </span><span style="color: rgb(0, 0, 255);">AS</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">BEGIN</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">DECLARE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@variable</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">255</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">澹版槑瀛楃鍨嬪彉閲?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 255);">DECLARE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@variable</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">int</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">澹版槑鏁村艦鍨嬪彉閲?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br />     <img src="http://www.tkk7.com/Images/dot.gif" alt="" />(do something)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">SET</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@variable</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">12345</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">瀵瑰彉閲弙ariable璧嬪?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span><span style="color: rgb(0, 0, 0);">銆佸垱寤烘病鏈夎繑鍥炲兼湁鍙傛暟鐨勫嚱鏁?br /> <br /> </span><span style="color: rgb(0, 0, 255);">CREATE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">FUNCTION</span><span style="color: rgb(0, 0, 0);"> my_function(</span><span style="color: rgb(0, 128, 0);">@user_Name</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">128</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 128, 0);">@password</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">int</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">6</span><span style="color: rgb(0, 0, 0);">))<br /> <br /> </span><span style="color: rgb(0, 0, 255);">AS</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">BEGIN</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">DECLARE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@variable_1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">255</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">澹版槑瀛楃鍨嬪彉閲?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br />     <img src="http://www.tkk7.com/Images/dot.gif" alt="" />(do something)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">SET</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@variable_1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@user_Name</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">255</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 128, 0);">@password</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">灝嗗彉閲廆user_Name涓嶡password榪炴帴璧嬬粰@variable_1錛屽叾涓璫onvert()鍑芥暟鏄皢int鍨嬭漿涓簐archar鍨?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">3</span><span style="color: rgb(0, 0, 0);">銆佸垱寤烘湁榪斿洖鍊間笌鏈夊弬鏁扮殑鍑芥暟<br /> <br /> </span><span style="color: rgb(0, 0, 255);">CREATE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">FUNCTION</span><span style="color: rgb(0, 0, 0);"> my_function(</span><span style="color: rgb(0, 128, 0);">@user_Name</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">128</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 128, 0);">@password</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">int</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">6</span><span style="color: rgb(0, 0, 0);">))<br /> <br /> </span><span style="color: rgb(0, 0, 255);">returns</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">255</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">璁劇疆榪斿洖鍊鹼紝璁頒綇鏄痳eturns 鑰屼笉鏄痳eturn</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">AS</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">BEGIN</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">DECLARE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">5</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">DECLARE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@fagle</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">5</span><span style="color: rgb(0, 0, 0);">)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">SET</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);"> users.</span><span style="color: rgb(255, 0, 255);">user_Name</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> USERS </span><span style="color: rgb(0, 0, 255);">as</span><span style="color: rgb(0, 0, 0);"> users </span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);"> users.</span><span style="color: rgb(255, 0, 255);">user_Name</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@user_Name</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);"> users.password </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@password</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">IF</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">BEGIN</span><span style="color: rgb(0, 0, 0);"><br /> <br />        </span><span style="color: rgb(0, 0, 255);">SET</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@fagle</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">NO</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">ELSE</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">BEGIN</span><span style="color: rgb(0, 0, 0);"><br /> <br />        </span><span style="color: rgb(0, 0, 255);">SET</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@falge</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">YES</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">榪斿洖緇撴灉</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);"><br /> <br /> 浜屻佸垹闄や竴涓嚱鏁拌娉?br /> <br /> </span><span style="color: rgb(0, 0, 255);">DROP</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">FUNCTION</span><span style="color: rgb(0, 0, 0);"> my_function<br /> <br /> 涓夈佹墽琛屼竴涓嚱鏁拌娉?br /> <br /> </span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);"> dbo.my_function(<img src="http://www.tkk7.com/Images/dot.gif" alt="" />) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">鏍規嵁鏈夋病鍙傛暟鏉ュ鐞?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">go</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">娉細鍦⊿QL Server 2005 涓紝鏈夊唴閮ㄥ嚱鏁頒笌澶栭儴鍑芥暟錛屾暟鎹簱緋葷粺鑷甫鍑芥暟錛屽sum()錛宑ount()絳夌瓑錛岃繖浜涚О涓哄唴閮ㄥ嚱鏁幫紝鑰屾垜浠嚜瀹氫箟鐨勫嚱鏁扮О涓哄閮ㄥ嚱鏁般?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">鍦ㄦ墽琛屽嚱鏁拌娉曚腑錛屼篃鏈変簺鍖哄埆錛屽鎵ц鍐呴儴鍑芥暟錛歴elect sum(total) from <img src="http://www.tkk7.com/Images/dot.gif" alt="" />錛岄偅涔堟墽琛屽閮ㄥ嚱鏁板垯闇瑕佸湪鍑芥暟鍚嶅墠鍔燿bo. + 鑷畾涔夊嚱鏁板悕錛屽</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">select dbo.my_function()</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">go</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> 鍥涖佷笅闈㈡彁渚涗簩涓緥瀛?br /> <br /> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);">銆佹棩鏈熷垽鏂紝鍒ゆ柇浼犺繘鏉ョ殑鏃ユ湡鏄惁鍦ㄤ笂涓湀鏃ュ埌鏈湀鏃ヤ箣闂?br /> <br /> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">璇鋒敞鎰廲onvert()鍑芥暟鐨勭敤娉?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">create</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> isNewContract(</span><span style="color: rgb(0, 128, 0);">@date</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">32</span><span style="color: rgb(0, 0, 0);">))<br /> <br /> </span><span style="color: rgb(0, 0, 255);">returns</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">32</span><span style="color: rgb(0, 0, 0);">)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">AS</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@begin_time</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">32</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@end_time</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">32</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@temp</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">4</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">32</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@month</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span><span style="color: rgb(0, 0, 0);">)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@begin_time</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(255, 0, 255);">DATEPART</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(255, 0, 255);">year</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(255, 0, 255);">getdate</span><span style="color: rgb(0, 0, 0);">())) </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">-</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@end_time</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(255, 0, 255);">DATEPART</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(255, 0, 255);">year</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(255, 0, 255);">getdate</span><span style="color: rgb(0, 0, 0);">())) </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(255, 0, 255);">DATEPART</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(255, 0, 255);">month</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(255, 0, 255);">getdate</span><span style="color: rgb(0, 0, 0);">())) </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">14</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@temp</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span><span style="color: rgb(0, 0, 0);">),(</span><span style="color: rgb(255, 0, 255);">month</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(255, 0, 255);">getDate</span><span style="color: rgb(0, 0, 0);">())</span><span style="color: rgb(128, 128, 128);">-</span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"> ))<br /> <br /> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 128, 0);">@temp</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);"><</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">10</span><span style="color: rgb(0, 0, 0);"> )<br /> <br /> </span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@begin_time</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@begin_time</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">0</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@temp</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">-</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 255);">convert</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">15</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 128, 0);">@date</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">>=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@begin_time</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@date</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);"><=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@end_time</span><span style="color: rgb(0, 0, 0);">)<br /> <br /> </span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">鏄?/span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@begin_time</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@result</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span><span style="color: rgb(0, 0, 0);">銆佹煡璇㈠鏉¤褰曞悎騫舵垚涓鏉¤褰曡繑鍥烇紝騫跺啓鍏XECL琛ㄤ腑錛岃繘琛屽垎琛屾崲琛屾樉紺猴紝鍏朵腑浣跨敤娓告爣榪涜寰幆澶勭悊<br /> <br /> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">鍦ㄦ暟鎹簱涓紝EXECL榛樿鎹㈣絎CSII鐮佷負'10',鍦ㄥ悎騫跺瓧絎︿覆涔嬪墠錛岄渶瑕佸厛杞負EXECL璇嗗埆鐨勬崲琛岀錛屽叿浣撲嬌鐢╟hat()鍐呴儴鍑芥暟澶勭悊</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">create</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getExportReportCollect(</span><span style="color: rgb(0, 128, 0);">@projectId</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">int</span><span style="color: rgb(0, 0, 0);"> ,</span><span style="color: rgb(0, 128, 0);">@month</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">64</span><span style="color: rgb(0, 0, 0);">))<br /> <br /> </span><span style="color: rgb(0, 0, 255);">returns</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">4096</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">璁劇疆榪斿洖鍊?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">AS</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@num</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@end</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">10</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">4096</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">鐢ㄤ簬榪斿洖鏌ヨ緇撴灉</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> city_cursor </span><span style="color: rgb(0, 0, 255);">cursor</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">澹版槑娓告爣鍙橀噺</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);"> reported.id<br /> <br />     </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> dbo.Investment_Budget_Reported </span><span style="color: rgb(0, 0, 255);">as</span><span style="color: rgb(0, 0, 0);"> reported<br /> <br />     </span><span style="color: rgb(255, 0, 255);">left</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">join</span><span style="color: rgb(0, 0, 0);"> dbo.Investment_Budget_Contract </span><span style="color: rgb(0, 0, 255);">as</span><span style="color: rgb(0, 0, 0);"> con<br /> <br />     </span><span style="color: rgb(0, 0, 255);">on</span><span style="color: rgb(0, 0, 0);"> reported.contractId </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> con.id<br /> <br />     </span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);"> reported.</span><span style="color: rgb(255, 0, 0);">[</span><span style="color: rgb(255, 0, 0);">month</span><span style="color: rgb(255, 0, 0);">]</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@month</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">and</span><span style="color: rgb(0, 0, 0);"> reported.projectId </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@projectId</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@num</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@end</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">10</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">瀵煎叆EXECL琛ㄤ腑錛屾崲琛岀鐨凙CSII鐮?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Field</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">int</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">澹版槑涓存椂瀛樻斁CityID鐨勫彉閲?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">open</span><span style="color: rgb(0, 0, 0);"> city_cursor </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">鎵撳紑娓告爣</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">fetch</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">next</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> city_cursor </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Field</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">灝嗗疄闄匢D璧嬬粰鍙橀噺</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 128, 0); font-weight: bold;">@@fetch_status</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">0</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">寰幆寮濮?/span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">((</span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">[</span><span style="color: rgb(255, 0, 0);">content</span><span style="color: rgb(255, 0, 0);">]</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> dbo.Investment_Budget_Reported </span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);"> id </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Field</span><span style="color: rgb(0, 0, 0);"> )</span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">not</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br /> <br />     </span><span style="color: rgb(0, 0, 255);">BEGIN</span><span style="color: rgb(0, 0, 0);"><br /> <br />      <br /> <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(0, 0, 0);">)<br /> <br />            </span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@num</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">銆?/span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">[</span><span style="color: rgb(255, 0, 0);">content</span><span style="color: rgb(255, 0, 0);">]</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> dbo.Investment_Budget_Reported </span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);"> id </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Field</span><span style="color: rgb(0, 0, 0);"><br /> <br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br /> <br />            </span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@num</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">銆?/span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">[</span><span style="color: rgb(255, 0, 0);">content</span><span style="color: rgb(255, 0, 0);">]</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> dbo.Investment_Budget_Reported </span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);"> id </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Field</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0); font-weight: bold;">char</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 128, 0);">@end</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">璁╂崲琛岀杞負EXECL璁よ瘑鐨勬崲琛岀</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@num</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@num</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"><br /> <br />     </span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);"><br /> <br />        </span><span style="color: rgb(0, 0, 255);">fetch</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">next</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> city_cursor </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Field</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">涓嬩竴涓猺eportId</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">close</span><span style="color: rgb(0, 0, 0);"> city_cursor </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">鍏抽棴娓告爣</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">deallocate</span><span style="color: rgb(0, 0, 0);"> city_cursor </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">閲婃斁娓告爣寮曠敤</span><span style="color: rgb(0, 128, 128);"><br /> </span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">@Result</span><span style="color: rgb(0, 0, 0);"><br /> <br /> </span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"><br /> <br /> <br /> 鏈枃鏉ヨ嚜CSDN鍗氬錛岃漿杞借鏍囨槑鍑哄錛歨ttp:</span><span style="color: rgb(128, 128, 128);">//</span><span style="color: rgb(0, 0, 0);">blog.csdn.net</span><span style="color: rgb(128, 128, 128);">/</span><span style="color: rgb(0, 0, 0);">zhdd1234</span><span style="color: rgb(128, 128, 128);">/</span><span style="color: rgb(0, 0, 0);">archive</span><span style="color: rgb(128, 128, 128);">/</span><span style="color: rgb(128, 0, 0); font-weight: bold;">2009</span><span style="color: rgb(128, 128, 128);">/</span><span style="color: rgb(128, 0, 0); font-weight: bold;">10</span><span style="color: rgb(128, 128, 128);">/</span><span style="color: rgb(128, 0, 0); font-weight: bold;">27</span><span style="color: rgb(128, 128, 128);">/</span><span style="color: rgb(128, 0, 0); font-weight: bold;">4734789</span><span style="color: rgb(0, 0, 0);">.aspx</span></div> <img src ="http://www.tkk7.com/Reg/aggbug/340916.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/Reg/" target="_blank">鑹炬嘗</a> 2010-12-16 19:38 <a href="http://www.tkk7.com/Reg/archive/2010/12/16/340916.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title><img src='http://blog.csdn.net/images/turnship.gif'/>sqlserver sql甯哥敤鍑芥暟,璇硶http://www.tkk7.com/Reg/archive/2010/11/23/338758.html鑹炬嘗鑹炬嘗Tue, 23 Nov 2010 02:21:00 GMThttp://www.tkk7.com/Reg/archive/2010/11/23/338758.htmlhttp://www.tkk7.com/Reg/comments/338758.htmlhttp://www.tkk7.com/Reg/archive/2010/11/23/338758.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/338758.htmlhttp://www.tkk7.com/Reg/services/trackbacks/338758.html闃呰鍏ㄦ枃

鑹炬嘗 2010-11-23 10:21 鍙戣〃璇勮
]]>
SQLServer 瀹炵幇rownum 鐨勫姛鑳?/title><link>http://www.tkk7.com/Reg/archive/2010/07/28/327358.html</link><dc:creator>鑹炬嘗</dc:creator><author>鑹炬嘗</author><pubDate>Wed, 28 Jul 2010 10:50:00 GMT</pubDate><guid>http://www.tkk7.com/Reg/archive/2010/07/28/327358.html</guid><wfw:comment>http://www.tkk7.com/Reg/comments/327358.html</wfw:comment><comments>http://www.tkk7.com/Reg/archive/2010/07/28/327358.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/Reg/comments/commentRss/327358.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/Reg/services/trackbacks/327358.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">鏂規硶1: <br /> <br /> </span><span style="color: #0000ff">with</span><span style="color: #000000"> </span><span style="color: #0000ff">temp</span><span style="color: #000000"> </span><span style="color: #0000ff">as</span><span style="color: #000000"> <br /> <br /> ( </span><span style="color: #0000ff">select</span><span style="color: #000000"> row_number() </span><span style="color: #0000ff">over</span><span style="color: #000000">(</span><span style="color: #0000ff">order</span><span style="color: #000000"> </span><span style="color: #0000ff">by</span><span style="color: #000000"> cityID) </span><span style="color: #0000ff">as</span><span style="color: #000000"> rownum,cityName </span><span style="color: #0000ff">from</span><span style="color: #000000"> city ) <br /> <br /> </span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #808080">*</span><span style="color: #000000"> </span><span style="color: #0000ff">from</span><span style="color: #000000"> </span><span style="color: #0000ff">temp</span><span style="color: #000000"> </span><span style="color: #0000ff">where</span><span style="color: #000000"> rownum </span><span style="color: #808080">between</span><span style="color: #000000"> </span><span style="font-weight: bold; color: #800000">10</span><span style="color: #000000"> </span><span style="color: #808080">and</span><span style="color: #000000"> </span><span style="font-weight: bold; color: #800000">20</span><span style="color: #000000"> <br /> <br /> </span><span style="color: #0000ff">go</span><span style="color: #000000"> <br /> <br /> 瑙i噴: <br /> <br /> </span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000"> 姝ゆ柟娉曟妸鎷彿閲岀殑鏌ヨ緇撴灉鏀懼埌鍙橀噺:</span><span style="color: #0000ff">temp</span><span style="color: #000000"> 閲岄潰( 鎴戜篃涓嶇‘瀹氭槸涓嶆槸鍙橀噺), 騫剁敤row_number() 鍑芥暟榪涜涓涓鍙瘋窡韙? 鍐嶇敤over 鍑芥暟榪涜涓涓垪鐨勬帓搴忚鍒? 鏄繖蹇呴』鐨?, 騫舵寚瀹氬垪鍚嶄負</span><span style="color: #ff0000">'</span><span style="color: #ff0000">rownum</span><span style="color: #ff0000">'</span><span style="color: #000000"> <br /> <br /> </span><span style="font-weight: bold; color: #800000">2</span><span style="color: #000000"> 绱ф帴鐫鍦ㄤ笅闈㈢殑璇彞鍙互瀵?nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">rownum</span><span style="color: #ff0000">'</span><span style="color: #000000"> 榪涜涓涓寚瀹氳鍙風殑鏌ヨ <br /> <br /> </span><span style="font-weight: bold; color: #800000">3</span><span style="color: #000000"> 姝ゆ壒璇彞鎵ц瀹屾瘯鍚? 鍙橀噺:</span><span style="color: #0000ff">temp</span><span style="color: #000000"> 閲婃斁 <br /> <br /> 鏂規硶2: <br /> <br /> </span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #ff00ff">identity</span><span style="color: #000000">(</span><span style="font-weight: bold; color: #000000">int</span><span style="color: #000000">,</span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000">,</span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000">) </span><span style="color: #0000ff">as</span><span style="color: #000000"> rownum, cityName </span><span style="color: #0000ff">into</span><span style="color: #000000"> #</span><span style="color: #0000ff">temp</span><span style="color: #000000"> </span><span style="color: #0000ff">from</span><span style="color: #000000"> city <br /> <br /> </span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #808080">*</span><span style="color: #000000"> </span><span style="color: #0000ff">from</span><span style="color: #000000"> #</span><span style="color: #0000ff">temp</span><span style="color: #000000"> </span><span style="color: #0000ff">where</span><span style="color: #000000"> rownum </span><span style="color: #808080">between</span><span style="color: #000000"> </span><span style="font-weight: bold; color: #800000">10</span><span style="color: #000000"> </span><span style="color: #808080">and</span><span style="color: #000000"> </span><span style="font-weight: bold; color: #800000">20</span><span style="color: #000000"> <br /> <br /> </span><span style="color: #0000ff">go</span><span style="color: #000000"> <br /> <br /> 瑙i噴: <br /> <br /> 姝ゆ柟娉曡窡涓婇潰鐨勫樊涓嶅鐨勬剰鎬? 鍙笉榪囨妸 row_number() 鍑芥暟鎹㈡垚浜?nbsp;</span><span style="color: #ff00ff">identity</span><span style="color: #000000">() 鍑芥暟 <br /> <br /> 騫舵妸緇撴灉闆嗘斁鍦ㄤ竴涓復鏃惰〃閲岄潰, 褰撴壒璇彞鎵ц瀹屾瘯, 姝や復鏃惰〃榪樺彲浠ヤ嬌鐢?nbsp;<br /> <br /> </span></div> <img src ="http://www.tkk7.com/Reg/aggbug/327358.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/Reg/" target="_blank">鑹炬嘗</a> 2010-07-28 18:50 <a href="http://www.tkk7.com/Reg/archive/2010/07/28/327358.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>sql璇彞鏍煎紡鍖栨暟瀛?鍓嶉潰琛?)鐨勫弬鑰冪ず渚?/title><link>http://www.tkk7.com/Reg/archive/2010/07/27/327243.html</link><dc:creator>鑹炬嘗</dc:creator><author>鑹炬嘗</author><pubDate>Tue, 27 Jul 2010 10:13:00 GMT</pubDate><guid>http://www.tkk7.com/Reg/archive/2010/07/27/327243.html</guid><wfw:comment>http://www.tkk7.com/Reg/comments/327243.html</wfw:comment><comments>http://www.tkk7.com/Reg/archive/2010/07/27/327243.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/Reg/comments/commentRss/327243.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/Reg/services/trackbacks/327243.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">灝嗕竴涓暟瀛椾緥濡?3錛屾垨1浣跨敤t</span><span style="color: #808080">-</span><span style="color: #000000">sql璇彞杞崲鎴?33鎴?01 浠ヤ笅鏄緇嗗垎鏋愶細 <br /> </span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000">銆?/span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #ff00ff">power</span><span style="color: #000000">(</span><span style="font-weight: bold; color: #800000">10</span><span style="color: #000000">,</span><span style="font-weight: bold; color: #800000">3</span><span style="color: #000000">)寰楀埌1000 <br /> </span><span style="font-weight: bold; color: #800000">2</span><span style="color: #000000">銆?/span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #ff00ff">cast</span><span style="color: #000000">(</span><span style="font-weight: bold; color: #800000">1000</span><span style="color: #808080">+</span><span style="font-weight: bold; color: #800000">33</span><span style="color: #000000"> </span><span style="color: #0000ff">as</span><span style="color: #000000"> </span><span style="font-weight: bold; color: #000000">varchar</span><span style="color: #000000">錛?nbsp;灝?000杞崲綾誨瀷 <br /> </span><span style="font-weight: bold; color: #800000">3</span><span style="color: #000000">銆?/span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #ff00ff">right</span><span style="color: #000000">(</span><span style="font-weight: bold; color: #800000">100033</span><span style="color: #000000">,</span><span style="font-weight: bold; color: #800000">3</span><span style="color: #000000">) 浠庡彸杈瑰彇3涓瓧絎﹀緱鍒?33 灝?鏍煎紡鍖栧悓涓?nbsp;</span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #ff00ff">right</span><span style="color: #000000">(</span><span style="color: #ff00ff">cast</span><span style="color: #000000">(</span><span style="color: #ff00ff">power</span><span style="color: #000000">(</span><span style="font-weight: bold; color: #800000">10</span><span style="color: #000000">,</span><span style="font-weight: bold; color: #800000">3</span><span style="color: #000000">) </span><span style="color: #0000ff">as</span><span style="color: #000000"> </span><span style="font-weight: bold; color: #000000">varchar</span><span style="color: #000000">)</span><span style="color: #808080">+</span><span style="font-weight: bold; color: #800000">33</span><span style="color: #000000">,</span><span style="font-weight: bold; color: #800000">3</span><span style="color: #000000">)<br /> <br /> </span></div> <img src ="http://www.tkk7.com/Reg/aggbug/327243.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/Reg/" target="_blank">鑹炬嘗</a> 2010-07-27 18:13 <a href="http://www.tkk7.com/Reg/archive/2010/07/27/327243.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>緇忓吀鐨凷QLhttp://www.tkk7.com/Reg/archive/2010/06/24/324290.html鑹炬嘗鑹炬嘗Wed, 23 Jun 2010 16:43:00 GMThttp://www.tkk7.com/Reg/archive/2010/06/24/324290.htmlhttp://www.tkk7.com/Reg/comments/324290.htmlhttp://www.tkk7.com/Reg/archive/2010/06/24/324290.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/324290.htmlhttp://www.tkk7.com/Reg/services/trackbacks/324290.html 浠g爜濡備笅

select a.[id],a.mark from 

select [page].[id],100 as mark from [page] where [page].[url] like '%baidu%' 
union 
select [page].[id],50 as mark from [page] where [page].[title] like '%baidu%' 
union 
select [page].[id],10 as mark from [page] where [page].[body] like '%baidu%' 
as a  order by mark desc  


鐢╱nion 瀹炵幇鑱斿悎鏌ヨ錛屽湪姣忎釜鏌ヨ璇彞涓畾涔変竴涓復鏃跺彉閲弇ark 騫剁粰mark璧嬪鹼紝鍦ㄦ渶鍚庣殑杈撳嚭鏃墮噰鐢╩ark鏉ユ帓搴忥紝榪欐牱瀹炵幇錛岄潪甯哥畝鍗曪紝鎴戞劅瑙夎繖棰樻洿澶氳冪爺鎴戜滑鐨勭紪紼嬫濇兂銆?


鑹炬嘗 2010-06-24 00:43 鍙戣〃璇勮
]]>
Oracle 娓告爣鎬葷粨+鏁寸悊http://www.tkk7.com/Reg/archive/2010/02/24/313823.html鑹炬嘗鑹炬嘗Wed, 24 Feb 2010 09:20:00 GMThttp://www.tkk7.com/Reg/archive/2010/02/24/313823.htmlhttp://www.tkk7.com/Reg/comments/313823.htmlhttp://www.tkk7.com/Reg/archive/2010/02/24/313823.html#Feedback2http://www.tkk7.com/Reg/comments/commentRss/313823.htmlhttp://www.tkk7.com/Reg/services/trackbacks/313823.html闃呰鍏ㄦ枃

鑹炬嘗 2010-02-24 17:20 鍙戣〃璇勮
]]>
Oracle SQL 鏌ヨ涓嶅尯鍒嗗ぇ灝忓啓瑙e喅鏂規(java) <font color=red>[璐碷</font>http://www.tkk7.com/Reg/archive/2009/12/14/305913.html鑹炬嘗鑹炬嘗Mon, 14 Dec 2009 08:09:00 GMThttp://www.tkk7.com/Reg/archive/2009/12/14/305913.htmlhttp://www.tkk7.com/Reg/comments/305913.htmlhttp://www.tkk7.com/Reg/archive/2009/12/14/305913.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/305913.htmlhttp://www.tkk7.com/Reg/services/trackbacks/305913.htmlselect * from tablename where upper(ziduan) like '%" + ziduan.toUpperCase() + "%'"
sql += " and upper(t2.customer_name) like '%" + customerName.toUpperCase() + "%'";


鑹炬嘗 2009-12-14 16:09 鍙戣〃璇勮
]]>
Oracle 闅忔満璁板綍<font color=red>鏂版墜鏅嬬駭</font>http://www.tkk7.com/Reg/archive/2009/11/20/303044.html鑹炬嘗鑹炬嘗Fri, 20 Nov 2009 06:50:00 GMThttp://www.tkk7.com/Reg/archive/2009/11/20/303044.htmlhttp://www.tkk7.com/Reg/comments/303044.htmlhttp://www.tkk7.com/Reg/archive/2009/11/20/303044.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/303044.htmlhttp://www.tkk7.com/Reg/services/trackbacks/303044.html--鏌ヨ涓鏉¢殢鏈烘暟涓婃潵

select * from tablename where t_id=(select trunc(dbms_random.value(min(鏉′歡),max(鏉′歡))) from tablename;

select * from dept where did=(select trunc(dbms_random.value(min(rownum),max(rownum))) from dept);

--鏌ヨN鏉¢殢鏈鴻褰曚笂鏉?/strong>

select * frmo (select * from tablename order by sys_guid()) where rownum<N

select * from (select * from dept order by sys_guid()) where rownum < 5;

--鏌ヨ鍑鴻〃涓璛鏉′腑浠嶯鍒癕鏉$壒瀹氳褰曚笂鏉ワ紙鍒嗛〉鏌ヨ錛?/strong>


select * from (select rownum r,t.* from tablename t where rownum<X) ss where ss.r>N and ss.r <=M

select * from (select rownum r, t.* from dept t where rownum<6) ss where ss.r > 2 and ss.r <= 10

鑹炬嘗 2009-11-20 14:50 鍙戣〃璇勮
]]>
鏇挎崲like錛屼嬌sql璇彞鏇存湁鏁堢巼<font color=red>銆愯漿銆?lt;/font>http://www.tkk7.com/Reg/archive/2009/11/18/302828.html鑹炬嘗鑹炬嘗Wed, 18 Nov 2009 10:04:00 GMThttp://www.tkk7.com/Reg/archive/2009/11/18/302828.htmlhttp://www.tkk7.com/Reg/comments/302828.htmlhttp://www.tkk7.com/Reg/archive/2009/11/18/302828.html#Feedback1http://www.tkk7.com/Reg/comments/commentRss/302828.htmlhttp://www.tkk7.com/Reg/services/trackbacks/302828.html 

鏇挎崲like錛屼嬌sql璇彞鏇存湁鏁堢巼

鎻愬埌Like璇彞澶у閮藉緢鐔熸倝錛屾瘮濡傛煡鎵劇敤鎴峰悕鍖呭惈鏈?c"鐨勬墍鏈夌敤鎴? 鎴戜滑鍙互鐢?

use mydatabase
select * from table1 where username like'%c%"

浠ヤ笅鏄畬鎴愪笂闈㈠姛鑳界殑鍙︿竴縐嶅啓娉?

use mydatabase
select * from table1 where charindex('c',username)>0

榪欑鏂規硶鐞嗚涓婃瘮涓婁竴縐嶆柟娉曞浜嗕竴涓垽鏂鍙?鍗?gt;0, 浣嗚繖涓垽鏂繃紼嬫槸鏈蹇殑, 鎴戠浉淇?0%浠ヤ笂鐨勮繍綆楅兘鏄姳鍦ㄦ煡鎵懼瓧絎︿覆鍙婂叾瀹冪殑榪愮畻涓? 鎵浠ヨ繍鐢╟harindex鍑芥暟涔熸病浠涔堝ぇ涓嶄簡銆傜敤榪欑鏂規硶涔熸湁濂藉, 閭e氨鏄%,|絳夊湪涓嶈兘鐩存帴鐢╨ike 鏌ユ壘鍒扮殑瀛楃涓彲浠ョ洿鎺ュ湪榪檆harindex涓繍鐢? 濡備笅:

use mydatabase
select * from table1 where charindex('%',username)>0

澶у榪樺彲浠ュ啓鎴?

 

use mydatabase
select * from table1 where charindex(char(37),username)>0

ASCII鐨勫瓧絎﹀嵆涓?



鑹炬嘗 2009-11-18 18:04 鍙戣〃璇勮
]]>
ORACLE鏌ヨ鏍戝瀷鍏崇郴<font color=#F1AF03>(start with connect by prior)</font><font color=red>銆愯漿銆?lt;/font>http://www.tkk7.com/Reg/archive/2009/11/18/302826.html鑹炬嘗鑹炬嘗Wed, 18 Nov 2009 10:00:00 GMThttp://www.tkk7.com/Reg/archive/2009/11/18/302826.htmlhttp://www.tkk7.com/Reg/comments/302826.htmlhttp://www.tkk7.com/Reg/archive/2009/11/18/302826.html#Feedback0http://www.tkk7.com/Reg/comments/commentRss/302826.htmlhttp://www.tkk7.com/Reg/services/trackbacks/302826.html 

oracle涓殑select璇彞鍙互鐢⊿TART WITHCONNECT BY PRIOR瀛愬彞瀹炵幇閫掑綊鏌ヨ錛宑onnect by 鏄粨鏋勫寲鏌ヨ涓敤鍒扮殑錛屽叾鍩烘湰璇硶鏄細 

select 
* from tablename start with cond1 

connect by cond2 

where cond3; 

綆鍗曡鏉ユ槸灝嗕竴涓爲鐘剁粨鏋勫瓨鍌ㄥ湪涓寮犺〃閲岋紝姣斿涓涓〃涓瓨鍦ㄤ袱涓瓧孌? 

id,parentid閭d箞閫氳繃琛ㄧず姣忎竴鏉¤褰曠殑parent鏄皝錛屽氨鍙互褰㈡垚涓涓爲鐘剁粨鏋勩?nbsp;

鐢ㄤ笂榪拌娉曠殑鏌ヨ鍙互鍙栧緱榪欐5鏍戠殑鎵鏈夎褰曘?nbsp;

鍏朵腑COND1鏄牴緇撶偣鐨勯檺瀹氳鍙ワ紝褰撶劧鍙互鏀懼闄愬畾鏉′歡錛屼互鍙栧緱澶氫釜鏍圭粨鐐癸紝瀹為檯灝辨槸澶氭5鏍戙?nbsp;

COND2鏄繛鎺ユ潯浠訛紝鍏朵腑鐢≒RIOR琛ㄧず涓婁竴鏉¤褰曪紝姣斿 CONNECT BY PRIOR ID
=PRAENTID灝辨槸璇翠笂涓鏉¤褰曠殑ID鏄湰鏉¤褰曠殑PRAENTID錛屽嵆鏈褰曠殑鐖朵翰鏄笂涓鏉¤褰曘?nbsp;

COND3鏄繃婊ゆ潯浠訛紝鐢ㄤ簬瀵硅繑鍥炵殑鎵鏈夎褰曡繘琛岃繃婊ゃ?nbsp;

瀵逛簬oracle榪涜綆鍗曟爲鏌ヨ(閫掑綊鏌ヨ) 

DEPTID           NUMBER                   閮ㄩ棬id 

PAREDEPTID   NUMBER                   鐖墮儴闂╥d(鎵灞為儴闂╥d) 

NAME              CHAR (
40 Byte)        閮ㄩ棬鍚嶇О 

 

閫氳繃瀛愯妭鐐瑰悜鏍硅妭鐐硅拷鏈? 

select 
* from persons.dept start with deptid=76 connect by prior paredeptid=deptid

閫氳繃鏍硅妭鐐歸亶鍘嗗瓙鑺傜偣. 

select 
* from persons.dept start with paredeptid=0 connect by prior deptid=paredeptid

鍙氳繃level 鍏抽敭瀛楁煡璇㈡墍鍦ㄥ眰嬈? 

select a.
*,level from persons.dept a start with paredeptid=0 connect by prior deptid=paredeptid

PS錛歴tart with 鍚庨潰鎵璺熺殑灝辨槸灝辨槸閫掑綊鐨勭瀛愶紝涔熷氨鏄掑綊寮濮嬬殑鍦版柟錛?br />
connect by  prior鍚庨潰鐨勫瓧孌甸『搴忔槸鏈夎絀剁殑錛?nbsp;

鑻rior緙虹渷錛氬垯鍙兘鏌ヨ鍒扮鍚堟潯浠剁殑璧峰琛岋紝騫朵笉榪涜閫掑綊鏌ヨ錛?nbsp;

 渚嬶細 

select 
* from table

start with org_id 
= 'HBHqfWGWPy' 

connect by prior org_id 
= parent_id; 

  

綆鍗曡鏉ユ槸灝嗕竴涓爲鐘剁粨鏋勫瓨鍌ㄥ湪涓寮犺〃閲岋紝姣斿涓涓〃涓瓨鍦ㄤ袱涓瓧孌? 

org_id,parent_id閭d箞閫氳繃琛ㄧず姣忎竴鏉¤褰曠殑parent鏄皝錛屽氨鍙互褰㈡垚涓涓爲鐘剁粨鏋勩?nbsp;

鐢ㄤ笂榪拌娉曠殑鏌ヨ鍙互鍙栧緱榪欐5鏍戠殑鎵鏈夎褰曘?nbsp;

鍏朵腑錛?nbsp;

鏉′歡1 鏄牴緇撶偣鐨勯檺瀹氳鍙ワ紝褰撶劧鍙互鏀懼闄愬畾鏉′歡錛屼互鍙栧緱澶氫釜鏍圭粨鐐癸紝瀹為檯灝辨槸澶氭5鏍戙?nbsp;

鏉′歡2 鏄繛鎺ユ潯浠訛紝鍏朵腑鐢≒RIOR琛ㄧず涓婁竴鏉¤褰曪紝 

姣斿 CONNECT BY PRIOR org_id 
= parent_id灝辨槸璇翠笂涓鏉¤褰曠殑org_id 鏄湰鏉¤褰曠殑parent_id錛屽嵆鏈褰曠殑鐖朵翰鏄笂涓鏉¤褰曘?nbsp;

鏉′歡3 鏄繃婊ゆ潯浠訛紝鐢ㄤ簬瀵硅繑鍥炵殑鎵鏈夎褰曡繘琛岃繃婊ゃ?nbsp;

  

綆鍗曚粙緇嶅涓嬶細 

鍦ㄦ壂鎻忔爲緇撴瀯琛ㄦ椂錛岄渶瑕佷緷姝よ闂爲緇撴瀯鐨勬瘡涓妭鐐癸紝涓涓妭鐐瑰彧鑳借闂竴嬈★紝鍏惰闂殑姝ラ濡備笅錛?nbsp;

絎竴姝ワ細浠庢牴鑺傜偣寮濮嬶紱 

絎簩姝ワ細璁塊棶璇ヨ妭鐐癸紱 

絎笁姝ワ細鍒ゆ柇璇ヨ妭鐐規湁鏃犳湭琚闂殑瀛愯妭鐐癸紝鑻ユ湁錛屽垯杞悜瀹冩渶宸︿晶鐨勬湭琚闂殑瀛愯妭鐐癸紝騫舵墽琛岀浜屾錛屽惁鍒欐墽琛岀鍥涙錛?nbsp;

絎洓姝ワ細鑻ヨ鑺傜偣涓烘牴鑺傜偣錛屽垯璁塊棶瀹屾瘯錛屽惁鍒欐墽琛岀浜旀錛?nbsp;

絎簲姝ワ細榪斿洖鍒拌鑺傜偣鐨勭埗鑺傜偣錛屽茍鎵ц絎笁姝ラ銆?nbsp;

鎬諱箣錛氭壂鎻忔暣涓爲緇撴瀯鐨勮繃紼嬩篃鍗蟲槸涓簭閬嶅巻鏍戠殑榪囩▼銆?nbsp;

  

1錛?nbsp;鏍戠粨鏋勭殑鎻忚堪 

鏍戠粨鏋勭殑鏁版嵁瀛樻斁鍦ㄨ〃涓紝鏁版嵁涔嬮棿鐨勫眰嬈″叧緋誨嵆鐖跺瓙鍏崇郴錛岄氳繃琛ㄤ腑鐨勫垪涓庡垪闂寸殑鍏崇郴鏉ユ弿榪幫紝濡?nbsp;EMP 琛ㄤ腑鐨?nbsp;EMPNO 鍜?nbsp;MGR 銆?nbsp;EMPNO 琛ㄧず璇ラ泧鍛樼殑緙栧彿錛?nbsp;MGR 琛ㄧず棰嗗璇ラ泧鍛樼殑浜虹殑緙栧彿錛屽嵆瀛愯妭鐐圭殑 MGR 鍊肩瓑浜庣埗鑺傜偣鐨?nbsp;EMPNO 鍊箋傚湪琛ㄧ殑姣忎竴琛屼腑閮芥湁涓涓〃紺虹埗鑺傜偣鐨?nbsp;MGR 錛堥櫎鏍硅妭鐐瑰錛夛紝閫氳繃姣忎釜鑺傜偣鐨勭埗鑺傜偣錛屽氨鍙互紜畾鏁翠釜鏍戠粨鏋勩?nbsp;

鍦?nbsp;SELECT 鍛戒護涓嬌鐢?nbsp;CONNECT BY 鍜?nbsp;START WITH 瀛愬彞鍙互鏌ヨ琛ㄤ腑鐨勬爲鍨嬬粨鏋勫叧緋匯傚叾鍛戒護鏍煎紡濡備笅錛?nbsp;

SELECT 銆傘傘?nbsp;

CONNECT BY 
{PRIOR 鍒楀悕 1= 鍒楀悕 2| 鍒楀悕 1=PRIOR 瑁傚悕 2}

[START WITH] 錛?nbsp;

鍏朵腑錛?nbsp;CONNECT BY 瀛愬彞璇存槑姣忚鏁版嵁灝嗘槸鎸夊眰嬈¢『搴忔绱紝騫惰瀹氬皢琛ㄤ腑鐨勬暟鎹繛鍏ユ爲鍨嬬粨鏋勭殑鍏崇郴涓?nbsp;PRIORY 榪愮畻絎﹀繀欏繪斁緗湪榪炴帴鍏崇郴鐨勪袱鍒椾腑鏌愪竴涓殑鍓嶉潰銆傚浜庤妭鐐歸棿鐨勭埗瀛愬叧緋伙紝 PRIOR 榪愮畻絎﹀湪涓渚ц〃紺虹埗鑺傜偣錛屽湪鍙︿竴渚ц〃紺哄瓙鑺傜偣錛屼粠鑰岀‘瀹氭煡鎵炬爲緇撴瀯鏄殑欏哄簭鏄嚜欏跺悜涓嬭繕鏄嚜搴曞悜涓娿傚湪榪炴帴鍏崇郴涓紝闄や簡鍙互浣跨敤鍒楀悕澶栵紝榪樺厑璁鎬嬌鐢ㄥ垪琛ㄨ揪寮忋?nbsp;START WITH 瀛愬彞涓哄彲閫夐」錛岀敤鏉ユ爣璇嗗摢涓妭鐐逛綔涓烘煡鎵炬爲鍨嬬粨鏋勭殑鏍硅妭鐐廣傝嫢璇ュ瓙鍙ヨ鐪佺暐錛屽垯琛ㄧず鎵鏈夋弧瓚蟲煡璇㈡潯浠剁殑琛屼綔涓烘牴鑺傜偣銆?nbsp;

START WITH錛?nbsp;涓嶄絾鍙互鎸囧畾涓涓牴鑺傜偣錛岃繕鍙互鎸囧畾澶氫釜鏍硅妭鐐廣?nbsp;

 

2錛?nbsp;鍏充簬 PRIOR

榪愮畻絎?nbsp;PRIOR 琚斁緗簬絳夊彿鍓嶅悗鐨勪綅緗紝鍐沖畾鐫鏌ヨ鏃剁殑媯绱㈤『搴忋?nbsp;

PRIOR 琚疆浜?nbsp;CONNECT BY 瀛愬彞涓瓑鍙風殑鍓嶉潰鏃訛紝鍒欏己鍒朵粠鏍硅妭鐐瑰埌鍙惰妭鐐圭殑欏哄簭媯绱紝鍗崇敱鐖惰妭鐐瑰悜瀛愯妭鐐規柟鍚戦氳繃鏍戠粨鏋勶紝鎴戜滑縐頒箣涓鴻嚜欏跺悜涓?nbsp;鐨勬柟寮忋傚錛?nbsp;

CONNECT BY PRIOR EMPNO
=MGR 

PIROR 榪愮畻絎﹁緗簬 CONNECT BY 瀛愬彞涓瓑鍙風殑鍚庨潰鏃訛紝鍒欏己鍒朵粠鍙惰妭鐐瑰埌鏍硅妭鐐圭殑欏哄簭媯绱紝鍗崇敱瀛愯妭鐐瑰悜鐖惰妭鐐規柟鍚戦氳繃鏍戠粨鏋勶紝鎴戜滑縐頒箣涓鴻嚜搴曞悜涓?nbsp;鐨勬柟寮忋備緥濡傦細 

CONNECT BY EMPNO
=PRIOR MGR 

鍦ㄨ繖縐嶆柟寮忎腑涔熷簲鎸囧畾涓涓紑濮嬬殑鑺傜偣銆?nbsp;

 

3錛?nbsp;瀹氫箟鏌ユ壘璧峰鑺傜偣 

鍦ㄨ嚜欏跺悜涓嬫煡璇㈡爲緇撴瀯鏃訛紝涓嶄絾鍙互浠庢牴鑺傜偣寮濮嬶紝榪樺彲浠ュ畾涔変換浣曡妭鐐逛負璧峰鑺傜偣錛屼互姝ゅ紑濮嬪悜涓嬫煡鎵俱傝繖鏍鋒煡鎵劇殑緇撴灉灝辨槸浠ヨ鑺傜偣涓哄紑濮嬬殑緇撴瀯鏍戠殑涓鏋濄?nbsp;

 

4錛庝嬌鐢?nbsp;LEVEL

鍦ㄥ叿鏈夋爲緇撴瀯鐨勮〃涓紝姣忎竴琛屾暟鎹兘鏄爲緇撴瀯涓殑涓涓妭鐐癸紝鐢變簬鑺傜偣鎵澶勭殑灞傛浣嶇疆涓嶅悓錛屾墍浠ユ瘡琛岃褰曢兘鍙互鏈変竴涓眰鍙楓傚眰鍙鋒牴鎹妭鐐逛笌鏍硅妭鐐圭殑璺濈紜畾銆備笉璁轟粠鍝釜鑺傜偣寮濮嬶紝璇ヨ搗濮嬫牴鑺傜偣鐨勫眰鍙峰緇堜負 
1 錛屾牴鑺傜偣鐨勫瓙鑺傜偣涓?nbsp;2 錛?nbsp;渚濇綾繪帹銆?nbsp;

 

5錛庤妭鐐瑰拰鍒嗘敮鐨勮鍓?nbsp;

鍦ㄥ鏍戠粨鏋勮繘琛屾煡璇㈡椂錛屽彲浠ュ幓鎺夎〃涓殑鏌愪簺琛岋紝涔熷彲浠ュ壀鎺夋爲涓殑涓涓垎鏀紝浣跨敤 WHERE 瀛愬彞鏉ラ檺瀹氭爲鍨嬬粨鏋勪腑鐨勫崟涓妭鐐癸紝浠ュ幓鎺夋爲涓殑鍗曚釜鑺傜偣錛屼絾瀹冨嵈涓嶅獎鍝嶅叾鍚庝唬鑺傜偣錛堣嚜欏跺悜涓嬫绱㈡椂錛夋垨鍓嶈緢鑺傜偣錛堣嚜搴曞悜欏舵绱㈡椂錛夈?nbsp;

6錛庢帓搴忔樉紺?nbsp;

璞″湪鍏跺畠鏌ヨ涓竴鏍鳳紝鍦ㄦ爲緇撴瀯鏌ヨ涓篃鍙互浣跨敤 ORDER BY 瀛愬彞錛屾敼鍙樻煡璇㈢粨鏋滅殑鏄劇ず欏哄簭錛岃屼笉蹇呮寜鐓ч亶鍘嗘爲緇撴瀯鐨勯『搴忋?nbsp;


鑹炬嘗 2009-11-18 18:00 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 免费无毒a网站在线观看| 在线免费观看h片| 国产日产亚洲系列| 最近2019免费中文字幕视频三| 亚洲中文字幕一二三四区苍井空| 国产一级一片免费播放i| 日本免费A级毛一片| 亚洲综合精品第一页| 国产精品V亚洲精品V日韩精品 | xxxx日本免费| 青草青草视频2免费观看| 中文字幕亚洲综合久久| 国产gav成人免费播放视频| 国产午夜免费高清久久影院| 亚洲乱妇老熟女爽到高潮的片| 亚洲人成人无码网www电影首页| 青春禁区视频在线观看直播免费| h片在线观看免费| 亚洲一卡2卡3卡4卡5卡6卡| 久久亚洲精品视频| 免费一级国产生活片| 精品国产无限资源免费观看| 久久一区二区免费播放| 亚洲sm另类一区二区三区| 久久久国产精品亚洲一区| 亚洲人成国产精品无码| 成人在线免费观看| 免费国产黄网站在线观看可以下载| 美女视频黄频a免费| 中文字幕在线观看亚洲日韩| 亚洲日本中文字幕| 在线观看亚洲精品福利片| 免费国产高清视频| 最近的免费中文字幕视频| 99久久99久久精品免费观看| 国产高潮流白浆喷水免费A片 | 亚洲中文字幕AV每天更新| 亚洲精品视频免费在线观看| 国产亚洲A∨片在线观看 | 亚洲另类自拍丝袜第1页| 亚洲成AV人片在线观看WWW|