Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQLÓï¾ä´ó·¨

 SQLÓïÑÔÓÉÃüÁî¡¢×Ӿ䡢ÔËËãºÍ¼¯ºÏº¯ÊýµÈ¹¹³É¡£ÔÚSQLÖУ¬Êý¾Ý¶¨ÒåÓïÑÔDDL£¨ÓÃÀ´½¨Á¢¼°¶¨ÒåÊý¾Ý±í¡¢×Ö¶ÎÒÔ¼°Ë÷ÒýµÈÊý¾Ý¿â½á¹¹£©°üº¬µÄÃüÁîÓÐCREATE¡¢DROP¡¢ALTER£»Êý¾Ý²Ù×ÝÓïÑÔDML£¨ÓÃÀ´ÌṩÊý¾ÝµÄ²éѯ¡¢ÅÅÐòÒÔ¼°É¸Ñ¡Êý¾ÝµÈ¹¦ÄÜ£©°üº¬µÄÃüÁîÓÐSELECT¡¢INSERT¡¢UPDATE¡¢DELETE¡£
Ò»¡¢SQLÓï¾ä
£¨1£©Select ²éѯÓï¾ä
Óï·¨£ºSELECT [ALL|DISTINCT] <Ä¿±êÁбí´ïʽ> [AS ÁÐÃû]
[,<Ä¿±êÁбí´ïʽ> [AS ÁÐÃû] ...] from <±íÃû> [£¬<±íÃû>…]
[WHERE <Ìõ¼þ±í´ïʽ> [AND|OR <Ìõ¼þ±í´ïʽ>...]
[GROUP BY ÁÐÃû [HAVING <Ìõ¼þ±í´ïʽ>>
[ORDER BY ÁÐÃû [ASC | DESC>
½âÊÍ£º[ALL|DISTINCT]   ALL£ºÈ«²¿£» DISTINCT£º²»°üÀ¨Öظ´ÐÐ
<Ä¿±êÁбí´ïʽ> ¶Ô×ֶοÉʹÓÃAVG¡¢COUNT¡¢SUM¡¢MIN¡¢MAX¡¢ÔËËã·ûµÈ
<Ìõ¼þ±í´ïʽ>
²éѯÌõ¼þ ν´Ê
±È½Ï =¡¢>,<,>=,<=,!=,<>,
È·¶¨·¶Î§ BETWEEN AND¡¢NOT BETWEEN AND
È·¶¨¼¯ºÏ IN¡¢NOT IN
×Ö·ûÆ¥Åä LIKE£¨“%”Æ¥ÅäÈκγ¤¶È£¬“_”Æ¥ÅäÒ»¸ö×Ö·û£©¡¢NOT LIKE
¿ÕÖµ IS NULL¡¢IS NOT NULL
×Ó²éѯ ANY¡¢ALL¡¢EXISTS
¼¯ºÏ²éѯ UNION£¨²¢£©¡¢INTERSECT£¨½»£©¡¢MINUS£¨²î£©
¶àÖØÌõ¼þ AND¡¢OR¡¢NOT
<GROUP BY ÁÐÃû> ¶Ô²éѯ½á¹û·Ö×é
[HAVING <Ìõ¼þ±í´ïʽ>] ·Ö×éɸѡÌõ¼þ
[ORDER BY ÁÐÃû [ASC | DESC> ¶Ô²éѯ½á¹ûÅÅÐò£»ASC£ºÉýÐò DESC£º½µÐò
Àý1£º select student.sno as ѧºÅ, student.name as ÐÕÃû, course as ¿Î³ÌÃû, score as ³É¼¨ from score,student where student.sid=score.sid and score.sid=:sid
Àý2£ºselect student.sno as ѧºÅ, student.name as ÐÕÃû,AVG(score) as ƽ¾ù·Ö from score,student where student.sid=score.sid and student.class=:class and (term=5 or term=6) group by student.sno, student.name having count(*)>0 order by ƽ¾ù·Ö DESC
Àý3£ºselect * from score where sid like '9634'
Àý4£ºselect * from student where class in (select class from student where name='³ÂСС')
£¨2£©INSERT²åÈëÓï¾ä
Óï·¨£ºINSERT INTO <±íÃû> [£¨<×Ö¶ÎÃû1> [,<×Ö¶ÎÃû2>, ...])] VALUES (<³£Á¿1> [,<³£Á¿2>, ...])
Óï·¨£ºINSERT INTO <±íÃû> [£¨<×Ö¶ÎÃû1> [,<×Ö¶ÎÃû2>, ...])] ×Ó²éѯ
Àý×Ó£ºINSERT INTO ½è


Ïà¹ØÎĵµ£º

PL/SQL¿ª·¢

bulk collectÊÇ¿ÉÒÔ¿´×öÊÇÒ»ÖÖÅú»ñÈ¡µÄ·½Ê½£¬ÔÚÎÒÃǵÄplsqlµÄ´úÂë¶ÎÀï¾­³£×÷ΪintoµÄÀ©Õ¹À´Ê¹Ó᣶ÔÓÚselect id into v from .... ÊÇÒ»¸ö³£ÓõÄÓ÷¨¡£²»¹ýÕâÀïÖ»ÄÜÊÇ·µ»Øµ¥Ìõ¼Ç¼µÄʱºò£¬²ÅÄÜʹÓã¬Èç¹ûÊÇÓжàÌõ¼Ç¼ÎÒÃǾͲ»ÄÜÓÃÕâÑùµÄ·½Ê½£¬¶øÊÇʹÓÃfetchºÍÑ­»·µÄ·½Ê½£¬²»½öʹÓÃÂé·³£¬¶øÇÒÐÔÄÜÒ²µ×Ï£¬ÕâʱÎÒÃǵÄbulk coll ......

sqlÖ®×óÁ¬½Ó¡¢ÓÒÁ¬½Ó¡¢È«Á¬½Ó

ÎÒÃǽéÉÜÁ˱íÁ¬½Ó£¬¸üÈ·ÇеÄ˵ÊÇinner joins內Á¬½Ó¡£內Á¬½Ó½öÑ¡³öÁ½ÕűíÖл¥ÏàÆ¥ÅäµÄ¼Ç¼£®Òò´Ë£¬Õâ»áµ¼ÖÂÓÐʱÎÒÃÇÐèÒªµÄ¼Ç¼ûÓаüº¬½øÀ´¡£
Ϊ¸üºÃµÄÀí½âÕâ¸ö¸ÅÄÎÒÃǽéÉÜÁ½¸ö±í×÷ÑÝʾ¡£ËÕ¸ñÀ¼Òé»áÖеÄÕþµ³±í(party)ºÍÒéÔ±±í(msp)¡£
 
party(Code,Name,Leader)
Code: Õþµ³´úÂë
Name: Õþµ³Ãû³Æ
Le ......

SQlµÄexecute Óësp_executesql¡¡

SQLÓï¾äÀàËÆstring.Format()×é×°±äÁ¿µÄʹÓá£
Ò»°ãÀ´Ëµ£¬ÎÒÃÇ»áÔÚ³ÌÐòÔËÐÐÆڼ佫ËùÒªÔËÐеÄÃüÁîÓï¾ä×éºÏ³ÉÒ»¸ö×Ö·û´®£¬È»ºóʹÓÃEXECUTEÃüÁî»òϵͳ´æ´¢¹ý³Ì
@0sp_executesqlÀ´ÔËÐС£½ñÌ죬ÎÒÃǽ«À´Ïêϸ̽ÌÖÕâÁ½ÖÖ·½·¨¸÷×ÔµÄÓÅÁӵ㡣
(Ò») ʹÓÃEXECUTEÃüÁîÔËÐÐÃüÁî×Ö·û´®
ҪʹÓÃEXECUTEÃüÁîÀ´ÔËÐÐÒ»¸öÃüÁî×Ö·û´®µÄÓï·¨ÈçÏ ......

SQLÓï¾äЧÂÊÎÊÌâµÄ¼¸µã×ܽá

 1. SQLÓÅ»¯µÄÔ­ÔòÊÇ£º
  ½«Ò»´Î²Ù×÷ÐèÒª¶ÁÈ¡µÄBLOCKÊý¼õµ½×îµÍ,¼´ÔÚ×î¶ÌµÄʱ¼ä´ïµ½×î´óµÄÊý¾ÝÍÌÍÂÁ¿¡£  
  µ÷Õû²»Á¼SQLͨ³£¿ÉÒÔ´ÓÒÔϼ¸µãÇÐÈ룺  
  ¼ì²é²»Á¼µÄSQL£¬¿¼ÂÇÆäд·¨ÊÇ·ñ»¹ÓпÉÓÅ»¯ÄÚÈÝ  
  ¼ì²é×Ó²éѯ   ¿¼ÂÇSQL×Ó²éѯÊÇ·ñ¿ÉÒÔÓüòµ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ