pl/sql³£Óú¯Êý
1¡£Sysdate µ±Ç°ÈÕÆÚºÍʱ¼ä
SQL> Select sysdate from dual;
SYSDATE
----------
21-6ÔÂ -05
2¡£Last_day ±¾ÔÂ×îºóÒ»Ìì
SQL> Select last_day(sysdate) from dual;
LAST_DAY(S
----------
30-6ÔÂ -05
3¡£Add_months(d,n) µ±Ç°ÈÕÆÚdºóÍÆn¸öÔÂ
ÓÃÓÚ´ÓÒ»¸öÈÕÆÚÖµÔö¼Ó»ò¼õÉÙһЩÔ·Ý
date_value:=add_months(date_value,number_of_months)
SQL> Select add_months(sysdate,2) from dual;
ADD_MONTHS
----------
21-8ÔÂ -05
4¡£Months_between(f,s) ÈÕÆÚfºÍs¼äÏà²îÔÂÊý
SQL> select months_between(sysdate,to_date('2005-11-12','yyyy-mm-dd'))from dual;
MONTHS_BETWEEN(SYSDATE,TO_DATE('2005-11-12','YYYY-MM-DD'))
----------------------------------------------------------
-4.6966741
5¡£NEXT_DAY(d, day_of_week)
·µ»ØÓÉ"day_of_week"ÃüÃûµÄ£¬ÔÚ±äÁ¿"d"Ö¸¶¨µÄÈÕÆÚÖ®ºóµÄµÚÒ»¸ö¹¤×÷ÈÕµÄÈÕÆÚ¡£²ÎÊý"day_of_week"±ØÐëΪ¸ÃÐÇÆÚÖеÄijһÌì¡£
SQL> SELECT next_day(to_date('20050620','YYYYMMDD'),1) from dual;
NEXT_DAY(T
----------
26-6ÔÂ -05
6¡£current_date()·µ»Øµ±Ç°»á»°Ê±ÇøÖеĵ±Ç°ÈÕÆÚ
date_value:=current_date
SQL> column sessiontimezone for a15
SQL> select sessiontimezone,current_date from dual;
SESSIONTIMEZONE CURRENT_DA
--------------- ----------
+08:00 13-11ÔÂ-03
SQL> alter session set time_zone='-11:00' 2 /
»á»°ÒѸü¸Ä¡£
SQL> select sessiontimezone,current_timestamp from dual;
SESSIONTIMEZONE CURRENT_TIMESTAMP
--------------- ------------------------------------
-11:00 12-11ÔÂ-03 04.59.13.668000 ÏÂÎç -11:00
7¡£current_timestamp()ÒÔtimestamp with time zoneÊý¾ÝÀàÐÍ·µ»Øµ±Ç°»á»°Ê±ÇøÖеĵ±Ç°ÈÕÆÚ
SQL> select current_timestamp from dual;
CURRENT_TIMESTAMP
---------------------------------------------------------------------------
21-6ÔÂ -05 10.13.08.220589 ÉÏÎç +08:00
8¡£dbtimezone()·µ»ØʱÇø
SQL> select dbtimezone from dual;
DBTIME
------
-08:00
9¡£extract()ÕÒ³öÈÕÆÚ»ò¼ä¸ôÖµµÄ×Ö¶ÎÖµ
date_value:=extract(date_field from [datetime_value|interval_value])
SQL> select extract(month from sysdate) "This Month" from dual;
This Month
--------
Ïà¹ØÎĵµ£º
½ñÌìÔÚÂÛ̳ÄÚ¿´µ½Ò»Æª ÃæÊÔÌ⣬ÊǹØÓÚwhere ºÍon µÄÇø±ðµÄ£¬×Ô¼ºÒ²²»¶®£¬ÔÚÍøÉÏËѳöһƪÎÄÕ£¬¼ÓÉî×Ô¼ºµÄ¼ÇÒä
ת
Êý¾Ý¿âÔÚͨ¹ýÁ¬½ÓÁ½ÕÅ»ò¶àÕűíÀ´·µ»Ø¼Ç¼ʱ£¬¶¼»áÉú³ÉÒ»ÕÅÖмäµÄÁÙʱ±í£¬È»ºóÔÙ½«ÕâÕÅÁÙʱ±í·µ»Ø¸øÓû§¡£
ÔÚʹÓÃleft jionʱ£¬onºÍwhereÌõ¼þµÄÇø±ðÈçÏ£º
1¡¢ onÌõ¼þ ......
SQL SERVER 2008Öж¨Ê±±¸·ÝÊý¾Ý¿âÈÎÎñµÄ´´½¨Óëɾ³ý
[http://news.newhua.com/news1/program_database/2008/1215/0812151515485B22JHGBK9HJ87DK09D6958HB8K83EJ0053JKGC1A543.html]
ÓÉÓÚ֮ǰÊÇʹÓÃSQL SERVER 2000»òÕß2005£¬Õâ´Î¸ø¿Í»§°²×°Ê±Ê¹ÓÃ2008 SERVER£¬±¾ÒÔΪ´´½¨Êý¾Ý¿â¶¨Ê±±¸·ÝÈÎÎñ»áÓë2000/2005ÓкܴóÇø±ð£¬µ«¾ ......
¡¡¡¡
¡¡¡¡¡ô¾¡Á¿²»ÒªÔÚwhereÖаüº¬×Ó²éѯ;
¡¡¡¡¹ØÓÚʱ¼äµÄ²éѯ£¬¾¡Á¿²»ÒªÐ´³É£ºwhere to_char(dif_date,'yyyy-mm-dd')=to_char('2007-07-01','yyyy-mm-dd');
¡¡¡¡¡ôÔÚ¹ýÂËÌõ¼þÖУ¬¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐë·ÅÔÚwhere×Ó¾äµÄĩβ;
¡¡¡¡from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í£¬driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖа ......
1.²éѯµÄÄ£ºýÆ¥Åä
¾¡Á¿±ÜÃâÔÚÒ»¸ö¸´ÔÓ²éѯÀïÃæʹÓà LIKE '%parm1%'—— ºìÉ«±êʶλÖõİٷֺŻᵼÖÂÏà¹ØÁеÄË÷ÒýÎÞ·¨Ê¹Óã¬×îºÃ²»ÒªÓÃ.
½â¾ö°ì·¨:
ÆäʵֻÐèÒª¶Ô¸Ã½Å±¾ÂÔ×ö¸Ä½ø£¬²éѯËٶȱã»áÌá¸ß½ü°Ù±¶¡£¸Ä½ø·½·¨ÈçÏ£º
a¡¢ÐÞ¸Äǰ̨³ÌÐò——°Ñ²éѯÌõ¼þµÄ¹©Ó¦ÉÌÃû³ÆÒ»À¸ÓÉÔÀ´µÄÎı¾ÊäÈë¸ÄΪÏÂÀÁб ......