sqlÓëhqlµÄÇø±ð
sqlÊǹØϵÊý¾Ý¿â²éѯÓïÑÔ,Ãæ¶ÔµÄÊý¾Ý¿â;
¶øhqlÊÇHibernateÕâÑùµÄÊý¾Ý¿â³Ö¾Ã»¯¿ò¼ÜÌṩµÄÄÚÖòéѯÓïÑÔ,ËäÈ»ËûÃǵÄÄ¿µÄ¶¼ÊÇΪÁË´ÓÊý¾Ý¿â²éѯÐèÒªµÄÊý¾Ý,µ«sql²Ù×÷µÄÊÇÊý¾Ý¿â±íºÍ×Ö¶Î,
¶ø×÷ΪÃæÏò¶ÔÏóµÄhql²Ù×÷µÄÔòÊdz־û¯À༰ÆäÊôÐÔ¡£
¾ÙÒ»¸ö¼òµ¥µÄÀý×Ó
sqlÓï¾ä
select * from tb_goods where id in (select goodsid from tb_getuse group by goodsid)
tb_goodsͨ¹ýgoodsidºÍtb_getuseÏà¹ØÁª£¬ÈçºÎÓÃhqlдÉÏÊösqlÓï¾ä
Èç¹ûAÊÇBµÄ¸¸±í¡£
b.A.id ÖмäµÄAÊÇB±íµÄÓ³ÉäÎļþÖжÔÓ¦µÄAµÄÃû×Ö¡£
from B as b where b.A.id in ( select a.id from A as a)
Ïà¹ØÎĵµ£º
1¡¢select * from tablename <Ìõ¼þÓï¾ä> limit 100,15
´Ó100Ìõ¼Ç¼ºó¿ªÊ¼(²»°üÀ¨µÚ100Ìõ¼Ç¼)È¡³ö15Ìõ¼Ç¼ (ʵ¼ÊÈ¡³öµÄÊÇµÚ 101-115Ìõ¼Ç¼Êý¾Ý)
2¡¢select * from tablename <Ìõ¼þÓï¾ä> limit 15
È¡³ö Ç°15Ìõ¼Ç¼Êý¾Ý,limit 15Ï൱ÓÚ limit 0,15 ......
Ç°ÑÔ£º
sql_trace ÊÇÎÒÔÚ¹¤×÷Öо³£ÒªÓõ½µÄµ÷ÓŹ¤¾ß£¬Ïà±È½Ïstatspack ÎÒ¸üÔ¸ÒâÓÃÕâ¸ö¹¤¾ß¡£
ÒòΪÊý¾Ý¿âÂýÔÒòµÄ85%ÒÔÉÏÊÇÓÉÓÚsqlÎÊÌâÔì³ÉµÄ£¬statspackûÓÐsqlµÄÖ´Ðмƻ®¡£ÏÔʾûÓÐËüÖ±¹Û£¬·½±ã£¬¶ÔÏëÒªÕë¶ÔÐÔ²»Ç¿£¬
1£¬½éÉÜÊý¾Ý¿âµ÷ÓÅÐèÒª¾³£»áÓõ½µÄ¹¤¾ß ......
×÷Õߣºfreedk
Ò»¡¢ÉîÈëdz³öÀí½âË÷Òý½á¹¹
¶þ¡¢¸ÄÉÆSQLÓï¾ä
Èý¡¢ÊµÏÖСÊý¾ÝÁ¿ºÍº£Á¿Êý¾ÝµÄͨÓ÷ÖÒ³ÏÔʾ´æ´¢¹ý³Ì
¾Û¼¯Ë÷ÒýµÄÖØÒªÐÔºÍÈçºÎÑ¡Ôñ¾Û¼¯Ë÷Òý
¡¡¡¡ÔÚÉÏÒ»½ÚµÄ±êÌâÖУ¬±ÊÕßдµÄÊÇ£ºÊµÏÖСÊý¾ÝÁ¿ºÍº£Á¿Êý¾ÝµÄͨÓ÷ÖÒ³ÏÔʾ´æ´¢¹ý³Ì¡£ÕâÊÇÒòΪÔÚ½«±¾´æ´¢¹ý³ÌÓ¦ÓÃÓÚ“°ì¹«×Ô¶¯»¯”ϵͳµÄʵ¼ùÖÐʱ£¬±ÊÕß·¢ÏÖÕ ......
ÔÚJAVAÖеÄSQL Óï¾äµÄ±àд·½Ã棬ûÓÐʹÓÃORACLE °ó¶¨±äÁ¿£¬ºÜ´ó³Ì¶ÈÉϽµµÍÁËÊý¾Ý¿âµÄÐÔÄÜ£¬±íÏÖÔÚÁ½¸ö·½Ã棺
1¡¢SQLÓï¾äÓ²·ÖÎö(Hard Parse)Ì«¶à£¬ÑÏÖØÏûºÄCPU×ÊÔ´£¬ÑÓ³¤ÁËSQLÓï¾ä×ܵÄÖ´ÐÐʱ¼ä
SQLÓï¾äµÄÖ´Ðйý³Ì·Ö¼¸¸ö²½Ö裺Óï·¨¼ì²é¡¢·ÖÎö¡¢Ö´ÐС¢·µ»Ø½á¹û¡£ÆäÖзÖÎöÓÖ·ÖΪӲ·ÖÎö(Hard Parse)ºÍÈí·ÖÎö(Soft Pars ......
execute immediate Óï·¨
ºóÃæ¸úÉÏsqlÓï¾ä¿ÉÒÔ¶¯Ì¬Ö´ÐÐsqlÓï¾ä.
ʹÓó¡¾°:
(1)¼ÓÈ붯̬±í.±ÈÈçÄãÓÐÒ»ÕűíµÄÃû×Ö²»Ã÷È·,ÊÇÐèÒªÅжϵõ½µÄ,Ôò¿ÉÒÔʹÓøÃÓï·¨À´Éú³ÉsqlÓï¾ä.
(2)¼ÓÈ붯̬×Ö¶Î.Äã¸ù¾ÝÅжÏ,×îÖÕ»á¼ÓÈëͬһÕűí,µ«ÊÇÕâÕűí¸ù¾Ý²»Í¬µÄÅжÏ×ֶλáÓÐËù²»Í¬,´ËʱÈç¹ûÖ±½ÓдsqlÊǼӲ»½øÈ¥µÄ,±ØÐëʹÓö¯Ì¬sqlÓï¾ä,ÈÃo ......