mysql 5.0´æ´¢¹ý³Ìѧϰ×ܽá
mysql´æ´¢¹ý³ÌµÄ´´½¨£¬É¾³ý£¬µ÷Óü°ÆäËû³£ÓÃÃüÁî
mysql 5.0´æ´¢¹ý³Ìѧϰ×ܽá
Ò».´´½¨´æ´¢¹ý³Ì
begin
¡¡¡
end
2.²ÎÊý´«µÝ
¶þ.µ÷Óô洢¹ý³Ì
×¢Ò⣺´æ´¢¹ý³ÌÃû³ÆºóÃæ±ØÐë¼ÓÀ¨ºÅ£¬ÄÄŸô洢¹ý³ÌûÓвÎÊý´«µÝ
Èý.ɾ³ý´æ´¢¹ý³Ì
drop procedure sp_name//
2.×¢ÒâÊÂÏî
(1)²»ÄÜÔÚÒ»¸ö´æ´¢¹ý³ÌÖÐɾ³ýÁíÒ»¸ö´æ´¢¹ý³Ì£¬Ö»Äܵ÷ÓÃÁíÒ»¸ö´æ´¢¹ý³Ì
ËÄ.Çø¿é£¬Ìõ¼þ£¬Ñ»·
begin
¡¡
end;
Ò²¿ÉÒÔ¸øÇø¿éÆð±ðÃû£¬È磺
lable:begin
¡¡¡..
end lable;
¿ÉÒÔÓÃleave lable;Ìø³öÇø¿é£¬Ö´ÐÐÇø¿éÒÔºóµÄ´úÂë
2.Ìõ¼þÓï¾ä
statement
else
statement
end if;
3.Ñ»·Óï¾ä
(1).whileÑ»·
statements
END WHILE [label] ;
statements
END LOOP [label];
statements
UNTIL expression
END REPEAT [label] ;
Îå.ÆäËû³£ÓÃÃüÁî
ÏÔʾÊý¾Ý¿âÖÐËùÓд洢µÄ´æ´¢¹ý³Ì»ù±¾ÐÅÏ¢£¬°üÀ¨ËùÊôÊý¾Ý¿â£¬´æ´¢¹ý³ÌÃû³Æ£¬´´½¨Ê±¼äµÈ
2.show create procedure sp_name
ÏÔʾijһ¸ö´æ´¢¹ý³ÌµÄÏêϸÐÅÏ¢
mysql´æ´¢¹ý³ÌÖÐÒªÓõ½µÄÔËËã·û
mysql´æ´¢¹ý³Ìѧϰ×ܽᣲÙ×÷·û
ËãÊõÔËËã·û
+ ¼Ó SET var1=2+2; 4
- ¼õ SET var2=3-2; 1
* ³Ë SET var3=3*2; 6
/ ³ý SET var4=10/3; 3.3333
DIV Õû³ý SET var5=10 DIV 3; 3
% È¡Ä£ SET var6=10%3 ; 1
±È½ÏÔËËã·û
< СÓÚ 2<1 False
<= СÓÚµÈÓÚ 2<=2 True
>= ´óÓÚµÈÓÚ 3>=2 True
BETWEEN ÔÚÁ½ÖµÖ®¼ä 5 BETWEEN 1 AND 10 True
NOT BETWEEN ²»ÔÚÁ½ÖµÖ®¼ä 5 NOT BETWEEN 1 AND 10 False
IN ÔÚ¼¯ºÏÖÐ 5 IN (1,2,3,4) False
NOT IN ²»ÔÚ¼¯ºÏÖÐ 5 NOT IN (1,2,3,4) True
= µÈÓÚ 2=3 False
<>, != ²»µÈÓÚ 2<>3 False
<=> Ñϸñ±È½ÏÁ½¸öNULLÖµÊÇ·ñÏàµÈ NULL<=>NULL True
LIKE ¼òµ¥Ä£Ê½Æ¥Åä "Guy Harrison" LIKE "Guy%" True
REGEXP ÕýÔòʽƥÅä "Guy Harrison" REGEXP "[Gg]reg" False
IS NULL Ϊ¿Õ 0 IS NULL False
IS NOT NULL ²»Îª¿Õ 0 IS NOT NULL True
Âß¼ÔËËã·û
Óë(AND)
<style type="text/css">
<!--
@page { size: 8.5in 11in; margin: 0.79in }
TD P { margin-bottom: 0in }
TH P { margin-bottom: 0in; font-style: italic }
P { margin-bottom: 0.08in }
-->
</style>
AND |
TRUE |
FALSE |
NULL |
---|---|---|---|
TRUE |
TRUE |
FALSE |
NULL |
FALSE |
FALSE |
FALSE |
NULL |
NULL |
NULL |
NULL |
NULL |
»ò(OR)
OR |
TRUE |
FALSE |
NULL |
---|---|---|---|
TRUE |
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
NULL |
NULL |
TRUE |
NULL |
NULL |
Òì»ò(XOR)
XOR |
TRUE |
FALSE |
NULL |
---|---|---|---|
TRUE |
FALSE |
TRUE |
NULL |
FALSE |
TRUE |
FALSE |
NULL |
NULL |
NULL |
NULL |
NULL |
λÔËËã·û
| λ»ò
& λÓë
<< ×óÒÆλ
>> ÓÒÒÆλ
~ λ·Ç(µ¥Ä¿ÔËË㣬°´Î»È¡·´)
mysq´æ´¢¹ý³ÌÖг£Óõĺ¯Êý£¬×Ö·û´®ÀàÐͲÙ×÷£¬ÊýѧÀ࣬ÈÕÆÚʱ¼äÀà¡£
mysql´æ´¢¹ý³Ì»ù±¾º¯Êý
Ò».×Ö·û´®Àà
CONCAT (string2 [,... ]) //Á¬½Ó×Ö´®
INSTR (string ,substring ) //·µ»ØsubstringÊ×´ÎÔÚstringÖгöÏÖµÄλÖÃ,²»´æÔÚ·µ»Ø0
LCASE (string2 ) //ת»»³ÉСд
LEFT (string2 ,length ) //´Óstring2ÖеÄ×ó±ßÆðÈ¡length¸ö×Ö·û
LENGTH (string ) //string³¤¶È
LOAD_FILE (file_name ) //´ÓÎļþ¶ÁÈ¡ÄÚÈÝ
LOCATE (substring , string [,start_position ] ) ͬINSTR,µ«¿ÉÖ¸¶¨¿ªÊ¼Î»ÖÃ
LPAD (string2 ,length ,pad ) //Öظ´ÓÃpad¼ÓÔÚstring¿ªÍ·,Ö±µ½×Ö´®³¤¶ÈΪlength
LTRIM (string2 ) //È¥³ýÇ°¶Ë¿Õ¸ñ
REPEAT (string2 ,count ) //Öظ´count´Î
REPLACE (str ,search_str ,replace_str ) //ÔÚstrÖÐÓÃreplace_strÌæ»»search_str
RPAD (string2 ,length ,pad) //ÔÚstrºóÓÃpad²¹³ä,Ö±µ½³¤¶ÈΪlength
RTRIM (string2 ) //È¥³ýºó¶Ë¿Õ¸ñ
STRCMP (string1 ,string2 ) //Öð×Ö·û±È½ÏÁ½×Ö´®´óС,
SUBSTRING (str , position [,length ]) //´ÓstrµÄposition¿ªÊ¼,È¡length¸ö×Ö·û,
×¢£ºmysqlÖд¦Àí×Ö·û´®Ê±£¬Ä¬ÈϵÚÒ»¸ö×Ö·ûϱêΪ1£¬¼´²ÎÊýposition±ØÐë´óÓÚµÈÓÚ1
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+
| substring(¡¯abcd¡¯,0,2) |
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+
| |
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+
1 row in set (0.00 sec)
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+
| substring(¡¯abcd¡¯,1,2) |
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+
| ab |
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+
1 row in set (0.02 sec)
TRIM([[BOTH|LEADING|TRAILING] [padding] FROM]string2) //È¥³ýÖ¸¶¨Î»ÖõÄÖ¸¶¨×Ö·û
UCASE (string2 ) //ת»»³É´óд
RIGHT(string2,length) //È¡string2×îºólength¸ö×Ö·û
SPACE(count) //Éú³Écount¸ö¿Õ¸ñ
¶þ.ÊýѧÀà
BIN (decimal_number ) //Ê®½øÖÆת¶þ½øÖÆ
CEILING (number2 ) //ÏòÉÏÈ¡Õû
CONV(number2,from_base,to_base) //½øÖÆת»»
FLOOR (number2 ) //ÏòÏÂÈ¡Õû
FORMAT (number,decimal_places ) //±£ÁôСÊýλÊý
HEX (DecimalNumber ) //תʮÁù½øÖÆ
×¢£ºHEX()Öпɴ«Èë×Ö·û´®£¬Ôò·µ»ØÆäASC-11Â룬ÈçHEX(¡¯DEF¡¯)·µ»Ø4142143
Ò²¿ÉÒÔ´«ÈëÊ®½øÖÆÕûÊý£¬·µ»ØÆäÊ®Áù½øÖƱàÂ룬ÈçHEX(25)·µ»Ø19
LEAST (number , number2 [,..]) //Çó×îСֵ
MOD (numerator ,denominator ) //ÇóÓà
POWER (number ,power ) //ÇóÖ¸Êý
RAND([seed]) //Ëæ»úÊý
ROUND (number [,decimals ]) //ËÄÉáÎåÈë,decimalsΪСÊýλÊý]
(1)ĬÈϱäΪÕûÐÎÖµ
mysql> select round(1.23);
+¡ª¡ª¡ª¡ª-+
| round(1.23) |
+¡ª¡ª¡ª¡ª-+
| 1 |
+¡ª¡ª¡ª¡ª-+
1 row in set (0.00 sec)
mysql> select round(1.56);
+¡ª¡ª¡ª¡ª-+
| round(1.56) |
+¡ª¡ª¡ª¡ª-+
| 2 |
+¡ª¡ª¡ª¡ª-+
1 row in set (0.00 sec)
(2)¿ÉÒÔÉ趨СÊýλÊý£¬·µ»Ø¸¡µãÐÍÊý¾Ý
mysql> select round(1.567,2);
+¡ª¡ª¡ª¡ª¡ª-+
| round(1.567,2) |
+¡ª¡ª¡ª¡ª¡ª-+
| 1.57 |
+¡ª¡ª¡ª¡ª¡ª-+
1 row in set (0.00 sec)
SIGN (number2 ) //·µ»Ø·ûºÅ,Õý¸º»ò0
SQRT(number2) //¿ªÆ½·½
Èý.ÈÕÆÚʱ¼äÀà
CONVERT_TZ (datetime2 ,fromTZ ,toTZ ) //ת»»Ê±Çø
CURRENT_DATE ( ) //µ±Ç°ÈÕÆÚ
CURRENT_TIME ( ) //µ±Ç°Ê±¼ä
CURRENT_TIMESTAMP ( ) //µ±Ç°Ê±¼ä´Á
DATE (datetime ) //·µ»ØdatetimeµÄÈÕÆÚ²¿·Ö
DATE_ADD (date2 , INTERVAL d_value d_type ) //ÔÚdate2ÖмÓÉÏÈÕÆÚ»òʱ¼ä
DATE_FORMAT (datetime ,FormatCodes ) //ʹÓÃformatcodes¸ñʽÏÔʾdatetime
DATE_SUB (date2 , INTERVAL d_value d_type ) //ÔÚdate2ÉϼõÈ¥Ò»¸öʱ¼ä
DATEDIFF (date1 ,date2 ) //Á½¸öÈÕÆÚ²î
DAY (date ) //·µ»ØÈÕÆÚµÄÌì
DAYNAME (date ) //Ó¢ÎÄÐÇÆÚ
DAYOFWEEK (date ) //ÐÇÆÚ(1-7) ,1ΪÐÇÆÚÌì
DAYOFYEAR (date ) //Ò»ÄêÖеĵڼ¸Ìì
EXTRACT (interval_name FROM date ) //´ÓdateÖÐÌáÈ¡ÈÕÆÚµÄÖ¸¶¨²¿·Ö
MAKEDATE (year ,day ) //¸ø³öÄê¼°ÄêÖеĵڼ¸Ìì,Éú³ÉÈÕÆÚ´®
MAKETIME (hour ,minute ,second ) //Éú³Éʱ¼ä´®
MONTHNAME (date ) //Ó¢ÎÄÔ·ÝÃû
NOW ( ) //µ±Ç°Ê±¼ä
SEC_TO_TIME (seconds ) //ÃëÊýת³Éʱ¼ä
STR_TO_DATE (string ,format ) //×Ö´®×ª³Éʱ¼ä,ÒÔformat¸ñʽÏÔʾ
TIMEDIFF (datetime1 ,datetime2 ) //Á½¸öʱ¼ä²î
TIME_TO_SEC (time ) //ʱ¼äתÃëÊý]
WEEK (date_time [,start_of_week ]) //µÚ¼¸ÖÜ
YEAR (datetime ) //Äê·Ý
DAYOFMONTH(datetime) //Ôµĵڼ¸Ìì
HOUR(datetime) //Сʱ
LAST_DAY(date) //dateµÄÔµÄ×îºóÈÕÆÚ
MICROSECOND(datetime) //΢Ãë
MONTH(datetime) //ÔÂ
MINUTE(datetime) //·Ö
DAY ,DAY_HOUR ,DAY_MINUTE ,DAY_SECOND ,HOUR ,HOUR_MINUTE ,HOUR_SECOND ,MINUTE ,MINUTE_SECOND,MONTH ,SECOND ,YEAR
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ