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

sqlÓÅ»¯34Ìõ

ÎÒÃÇÒª×öµ½²»µ«»áдSQL,»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQL,ÒÔÏÂΪ±ÊÕßѧϰ¡¢ÕªÂ¼¡¢²¢»ã×ܲ¿·Ö×ÊÁÏÓë´ó¼Ò·ÖÏí£¡
£¨1£©      Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLE µÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, ÄǾÍÐèҪѡÔñ½»²æ±í(intersection table)×÷Ϊ»ù´¡±í, ½»²æ±íÊÇÖ¸ÄǸö±»ÆäËû±íËùÒýÓõıí.
£¨2£©      WHERE×Ó¾äÖеÄÁ¬½Ó˳Ðò£®£º
ORACLE²ÉÓÃ×Ô϶øÉϵÄ˳Ðò½âÎöWHERE×Ó¾ä,¸ù¾ÝÕâ¸öÔ­Àí,±íÖ®¼äµÄÁ¬½Ó±ØÐëдÔÚÆäËûWHEREÌõ¼þ֮ǰ, ÄÇЩ¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐëдÔÚWHERE×Ó¾äµÄĩβ.
£¨3£©      SELECT×Ó¾äÖбÜÃâʹÓà ‘ * ‘£º
ORACLEÔÚ½âÎöµÄ¹ý³ÌÖÐ, »á½«'*' ÒÀ´Îת»»³ÉËùÓеÄÁÐÃû, Õâ¸ö¹¤×÷ÊÇͨ¹ý²éѯÊý¾Ý×ÖµäÍê³ÉµÄ, ÕâÒâζ׎«ºÄ·Ñ¸ü¶àµÄʱ¼ä
£¨4£©      ¼õÉÙ·ÃÎÊÊý¾Ý¿âµÄ´ÎÊý£º
ORACLEÔÚÄÚ²¿Ö´ÐÐÁËÐí¶à¹¤×÷: ½âÎöSQLÓï¾ä, ¹ÀËãË÷ÒýµÄÀûÓÃÂÊ, °ó¶¨±äÁ¿ , ¶ÁÊý¾Ý¿éµÈ£»
£¨5£©      ÔÚSQL*Plus , SQL*FormsºÍPro*CÖÐÖØÐÂÉèÖÃARRAYSIZE²ÎÊý, ¿ÉÒÔÔö¼Óÿ´ÎÊý¾Ý¿â·ÃÎʵļìË÷Êý¾ÝÁ¿ ,½¨ÒéֵΪ200
£¨6£©      ʹÓÃDECODEº¯ÊýÀ´¼õÉÙ´¦Àíʱ¼ä£º
ʹÓÃDECODEº¯Êý¿ÉÒÔ±ÜÃâÖظ´É¨ÃèÏàͬ¼Ç¼»òÖظ´Á¬½ÓÏàͬµÄ±í.
£¨7£©      ÕûºÏ¼òµ¥,ÎÞ¹ØÁªµÄÊý¾Ý¿â·ÃÎÊ£º
Èç¹ûÄãÓм¸¸ö¼òµ¥µÄÊý¾Ý¿â²éѯÓï¾ä,Äã¿ÉÒÔ°ÑËüÃÇÕûºÏµ½Ò»¸ö²éѯÖÐ(¼´Ê¹ËüÃÇÖ®¼äûÓйØϵ)
£¨8£©      ɾ³ýÖظ´¼Ç¼£º
×î¸ßЧµÄɾ³ýÖظ´¼Ç¼·½·¨ ( ÒòΪʹÓÃÁËROWID)Àý×Ó£º
DELETE  from  EMP E  WHERE  E.ROWID > (SELECT MIN(X.ROWID)
from  EMP X  WHERE  X.EMP_NO = E.EMP_NO);
£¨9£©      ÓÃTRUNCATEÌæ´úDELETE£º
µ±É¾³ý±íÖеļǼʱ,ÔÚͨ³£Çé¿öÏÂ, »Ø¹ö¶Î(rollback segments ) ÓÃÀ´´æ·Å¿ÉÒÔ±»»Ö¸´µÄÐÅÏ¢. Èç¹ûÄãûÓÐCOMMITÊÂÎñ,ORACLE»á½«Êý¾Ý»Ö¸´µ½É¾³ý֮ǰµÄ״̬(׼ȷµØ˵Êǻָ´µ½Ö´ÐÐɾ³ýÃüÁî֮ǰµÄ×´¿ö) ¶øµ±ÔËÓÃTRUNCATEʱ, »Ø¹ö¶Î²»ÔÙ´æ·ÅÈκοɱ»»Ö¸´µÄÐÅÏ¢.µ±ÃüÁîÔËÐкó,Êý¾Ý²»Äܱ»»Ö¸´.Òò´ËºÜÉÙµÄ×ÊÔ´±»µ÷ÓÃ,Ö´ÐÐʱ¼äÒ²»áºÜ¶Ì. (ÒëÕß°´: TRUNCATEÖ»Ô


Ïà¹ØÎĵµ£º

SQL With cube

ÏÐÀ´Ð´ÏÂwith cubeµÄÓ÷¨
cubeÔËËã·ûÔÚ SELECT Óï¾äµÄ GROUP BY ×Ó¾äÖÐÖ¸¶¨¡£¸ÃÓï¾äµÄÑ¡ÔñÁбíÓ¦°üº¬Î¬¶ÈÁк;ۺϺ¯Êý±í´ïʽ¡£GROUP BY Ó¦Ö¸¶¨Î¬¶ÈÁк͹ؼü×Ö WITH CUBE¡£½á¹û¼¯½«°üº¬Î¬¶ÈÁÐÖи÷ÖµµÄËùÓпÉÄÜ×éºÏ£¬ÒÔ¼°ÓëÕâЩά¶ÈÖµ×éºÏÏàÆ¥ÅäµÄ»ù´¡ÐÐÖеľۺÏÖµ¡£
ÏÈ¿´ÏÂ±í£º
ÎÒÃÇÒÔid¾ÛºÏ²éѯ³öƽ¾ù·Ö
ÕâÒ»ÌõSQLÓï¾äÓ ......

ÈýÖÐSQL ·ÖÒ³·½·¨Ð§ÂÊ·ÖÎö

ÈýÖÖSQL·ÖÒ³·¨Ð§ÂÊ·ÖÎö
±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
¡¡Óï¾äÐÎʽ£ºÀûÓÃNot InºÍSELECT TOP·ÖÒ³) ЧÂÊÖУ¬ÐèҪƴ½ÓSQLÓï¾ä
  SELECT TOP 10 * from  TestTable WHERE (Id  NOT  IN (SELECT  TOP  20    id&n ......

¡¾×ª¡¿²ÉÓÃp6spyÍêÕûÏÔʾhibernateµÄSQLÓï¾ä

×÷ÕߣºÇñÑó
QQ£º1964477
    ËäÈ»ÔÚhibernateÖÐÓÐshow_sqlÑ¡Ïµ«ÊÇÏÔʾ³öÀ´µÄÓï¾ä´ó¶àÀàËÆ
    select * from xxx where value=?
    µ«ÊÇÓÐʱºòÎÒÃÇÐèÒªµÃµ½ÍêÕûµÄSQLÓï¾ä£¬Ôõô°ìÄØ£¿Ê¹ÓÃP6SPY¾Í¿ÉÒÔÍê³ÉÕâ¸öÈÎÎñ
    p6spyÊÇÒ»¸ö¿ªÔ´Èí¼þ£¬Ëü¿ÉÒÔ¸ú ......

ÕÒЩ²»´íµÄsqlÃæÊÔÌâ(1)

Student(S#,Sname,Sage,Ssex) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
  select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
  fr ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ