Ò»ÌõSQLÓï¾ä£¬¹ØÓÚ×Ö·û·Ö¸î¹ØÁª¶àÌõ¼Ç¼µÄÎÊÌâ
ÔÎÄ´«ËÍÃÅ£ºhttp://topic.csdn.net/u/20091010/14/FC7737C1-D60B-43F1-A8B5-A9EEF2DE4426.html
¼ÙÈçÏÖÔÚÓÐÁ½ÕÅ±í£º
1.±ístuinfo
sid sname subs
1 jack |1|2|
2 marry |1|4|
3 tom |3|
2.±ísubinfo
subid subname
1 physics
2 maths
3 biology
4 geography
ÎÒÏë°ÑstuinfoµÄsubs×ֶΰ´£ü×Ö·û·Ö¿ª£¬È»ºóÆ¥ÅäsubinfoµÄsubid£¬È¡subnameµÄÖµ£¬Æ¥Åäµ½¶à¸öµÄ»°¾ÍÓöººÅ¸ô¿ª¡£
¼ò¶øÑÔÖ®ÎÒÏëµÃµ½µÄ½á¹ûÈçÏ£º
sid sname subname
1 jack physics,maths
2 marry physics,geography
3 tom biology
Ï£Íû¸÷λ´óÏÀÄÜ°ïæÉè¼ÆÒ»ÏÂSQLÓï¾ä£¬Ð»Ð»ÁË£¡
Oracle 10gÒÔÉÏ°æ±¾
select a.sid,a.sname,wm_concat(b.subname) subname
from stuinfo a,subinfo b
where instr(a.subs,'|'||b.subid(+)||'|')>0
group by a.sid,a.sname
9iµÄ
select sid,sname,substr(max(sys_connect_by_path(subname,',')),2) subname
from (
select a.sid,a.sname,b.subname,
row_number()over(partition by a.sid order by rownum)rn
from stuinfo a,subinfo b
where instr(a.subs,'|'||b.subid(+)||'|')>0)
connect by prior rn=rn-1 and prior sid=sid
start with rn=1
group by sid,sname
Ïà¹ØÎĵµ£º
SQL SERVER ºÍEXCELµÄÊý¾Ýµ¼Èëµ¼³ö
1¡¢ÔÚSQL SERVERÀï²éѯExcelÊý¾Ý:
-- ======================================================
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]
ÏÂÃæÊǸö²éÑ ......
Èç¹ûÒ»¸ö SQL Óï¾ä·¢ÉúÁË´íÎó£¬ÄÇô sqlca.sqlcode ½«ÊÇ·ÇÁãÖµ¡£
Èç¹û sqlca.sqlcode СÓÚ 0 ÄÇô¾ÍÊÇ·¢ÉúÁËijÖÖÑÏÖصĴíÎó£¬ÏóÊý¾Ý¿â¶¨ÒåÓë²éѯ¶¨Òå²»Ò»Öµȣ®
Èç¹û´óÓÚ 0 ÔòÊÇͨ³£µÄ´íÎó£¬Ïó±í²»°üÀ¨ËùÒªÇóµÄÐеȣ®
sqlca.sqlcode == 0£¬³É¹¦
sqlca.sqlcode == -1 ʧ°Ü £¨»ñÈ¡¾ßÌåʧ°ÜÐÅÏ¢ ......
where 1=1ÓÐʲôÓã¿ÔÚSQLÓïÑÔÖУ¬Ð´Õâôһ¾ä»°¾Í¸úûдһÑù¡£
select * from table1 where 1=1Óëselect * from table1ÍêȫûÓÐÇø±ð£¬ÉõÖÁ»¹ÓÐÆäËûÐí¶àд·¨£¬1<>2£¬'a'='a','a'<>'b'£¬ÆäÄ¿µÄ¾ÍÖ»ÓÐÒ»¸ö£¬whereµÄÌõ¼þΪÓÀÕ棬µÃµ½µÄ½á¹û¾ÍÊÇδ¼ÓÔ¼ÊøÌõ¼þµÄ¡£
ÔÚSQL×¢Èëʱ»áÓõ½Õâ¸ö£¬ÀýÈçselect * from table1 ......
(1)char¡¢varchar¡¢textºÍnchar¡¢nvarchar¡¢ntext
charºÍvarcharµÄ³¤¶È¶¼ÔÚ1µ½8000Ö®¼ä£¬ËüÃǵÄÇø±ðÔÚÓÚcharÊǶ¨³¤×Ö·ûÊý¾Ý£¬¶øvarcharÊDZ䳤×Ö·ûÊý¾Ý¡£Ëùν¶¨³¤¾ÍÊdz¤¶È¹Ì¶¨ µÄ£¬µ±ÊäÈëµÄÊý¾Ý³¤¶ÈûÓдﵽָ¶¨µÄ³¤¶Èʱ½«×Ô¶¯ÒÔÓ¢ÎÄ¿Õ¸ñÔÚÆäºóÃæÌî³ä£¬Ê¹³¤¶È´ïµ½ÏàÓ¦µÄ³¤¶È£»¶ø±ä³¤×Ö·ûÊý¾ÝÔò²»»áÒÔ¿Õ¸ñÌî³ä¡£ text´ ......