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

MYSQL´æ´¢¹ý³ÌѧϰС½á

Mysql ´æ´¢Àý³ÌµÄʹÓÃ
   Ò»¡¢      ¼ò½é
 ´æ´¢¹ý³Ì£¨Stored Procedure£©ÊÇÒ»×éΪÁËÍê³ÉÌض¨¹¦ÄܵÄSQLÓï¾ä¼¯£¬¾­±àÒëºó´æ´¢ÔÚÊý¾Ý¿âÖС£Óû§Í¨¹ýÖ¸¶¨´æ´¢¹ý³ÌµÄÃû×Ö²¢¸ø³ö²ÎÊý£¨Èç¹û¸Ã´æ´¢¹ý³Ì´øÓвÎÊý£©À´Ö´ÐÐËü¡£´æ´¢¹ý³Ì  ÊÇÊý¾Ý¿âÖеÄÒ»¸öÖØÒª¶ÔÏó£¬ÈκÎÒ»¸öÉè¼ÆÁ¼ºÃµÄÊý¾Ý¿âÓ¦ÓóÌÐò¶¼Ó¦¸ÃÓõ½´æ´¢¹ý³Ì¡£
ËäÈ»³£ÓÃÊõÓïÊÇ´æ´¢¹ý³Ì£¨stored procedure£©£¬µ«MySQLʵ¼ÊÉÏʵÏÖÁËÁ½ÖÐÀàÐÍ£¬³ýÁË´æ´¢¹ý³ÌÍ⣬»¹Óд洢º¯Êý£¨stored routine£©,ËüÃÇͳ³ÆΪ´æ´¢Àý³Ì£»
 
   ¶þ¡¢»ù±¾¸ñʽ
 1¡¢´æ´¢¹ý³Ì
  CREATE PROCEDURE ¹ý³ÌÃû ([¹ý³Ì²ÎÊý[,...]])
  [ÌØÐÔ ...] ¹ý³ÌÌå
Èç´´½¨: CEATE PROCEDURE p1 (a INT)
SELECT a;
µ÷ÓÃһϣºCALL p1(8);  
½«ÏÔʾ£º
+------+
| a    |
+------+
|    8 |
+------+
1 row in set (0.00 sec)
2¡¢´æ´¢º¯Êý
  CREATE FUNCTION º¯ÊýÃû ([º¯Êý²ÎÊý[,...]])
  RETURNS ·µ»ØÀàÐÍ
  [ÌØÐÔ ...] º¯ÊýÌå
Èç´´½¨£ºCREATE FUNCTION f1 (x INT)
RETURNS INT
RETURN x;       /* ¹ý³Ìº¯ÊýÒ»´ÎÖ»ÄÜ·µ»ØÒ»¸öÖµ
µ÷ÓÃһϣºSELECT f1 (3);
½«ÏÔʾ£º
+-------+
| f1(3) |
+-------+
|     3 |
+-------+
1 row in set (0.00 sec)
3¡¢¹ý³Ì²ÎÊý
  [ IN | OUT | INOUT ] ²ÎÊýÃû ²ÎÊýÀàÐÍ
4¡¢º¯Êý²ÎÊý
  ²ÎÊýÃû ²ÎÊýÀàÐÍ
5¡¢·µ»ØÀàÐÍ
  ÓÐЧµÄMySQLÊý¾ÝÀàÐͼ´¿É
6¡¢¹ý³ÌÌå/º¯ÊýÌå¸ñʽÈçÏÂ
BEGIN
ÓÐЧµÄSQLÓï¾ä
END
7¡¢ÌØÐÔ£¨Ò»°ã²»ÒªÇó£©
LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'
8¡¢´æ´¢¹ý³ÌÖвÎÊýµÄIN,OUT,INOUTÀàÐÍ
    ´æ´¢¹ý³Ì¿ÉÒÔ½ÓÊÜÊäÈë²ÎÊý£¬²¢°Ñ²ÎÊý·µ»Ø¸øµ÷Ó÷½¡£²»¹ý£¬¶ÔÓÚÿ¸ö²ÎÊý£¬ÐèÒªÉùÃ÷Æä²ÎÊýÃû¡¢Êý¾ÝÀàÐÍ£¬»¹ÒªÖ¸¶¨´Ë²ÎÊýÊÇÓÃÓÚÏò¹ý³Ì´«µÝÐÅÏ¢£¬»¹ÊÇ´Ó¹ý³Ì´«»ØÐÅÏ¢£¬»òÊǶþÕß¼æÓС£
    ΪÉùÃ÷²ÎÊýµÄ×÷Óã¬Ê¹ÓÃÈçÏÂ3¸ö¹Ø¼ü×ÖÖ®Ò»£º
˜ IN :  IN²ÎÊýÖ»ÓÃÀ´Ïò¹ý³Ì´«µÝÐÅÏ¢£¬ÎªÄ¬ÈÏÖµ¡£
 
˜ OUT : OUT²ÎÊýÖ»ÓÃÀ´´Ó¹ý³Ì´«»ØÐÅÏ¢¡£
 
˜ INOUT £º INOUT²ÎÊý¿ÉÒÔÏò¹ý³


Ïà¹ØÎĵµ£º

mysqlºÍoracle·ÖÒ³×¢Òâµã

ÕâÀïÊ×ÏÈ˵ÏÂoracle·ÖÒ³²»Ïñmysql·ÖÒ³ÄÇô¼òµ¥Ö±½Ólimit ¾Í¿ÉÒÔÁË.
mysql£ºsql ="select * from talbe limit 0,10";
µÚÒ»¸öÊý±íʾϱ꣬¾ÍÊÇ´ÓµÚ¼¸ÌõÊý¾Ý¿ªÊ¼£¬
µÚ¶þ¸öÊý±íʾÿҳÏÔʾ¶àÉÙÌõÊý¾Ý£¬¿ÉÒÔ˵Êǵ±ÄãÈ·¶¨Ã¿Ò³ÏÔʾ¶àÉÙÐÐʱºò£¬Ëü¾ÍÊÇÒ»¸ö¹Ì¶¨µÄÊý¡£
ÕâÀïÐèҪעÒâµÄÊÇ£¬mysqlµÄ·ÃÎÊϱêÊÇ´Ó0¿ªÊ¼µÄ¡£Õ ......

mysql ÖеÄ×Ö·û´®Á¬½Ó CONCAT(str1,str2,...)

·µ»ØÀ´×ÔÓÚ²ÎÊýÁ¬½áµÄ×Ö·û´®¡£Èç¹ûÈκβÎÊýÊÇNULL£¬·µ»ØNULL¡£¿ÉÒÔÓг¬¹ý2¸öµÄ²ÎÊý¡£Ò»¸öÊý×Ö²ÎÊý±»±ä»»ÎªµÈ¼ÛµÄ×Ö·û´®ÐÎʽ¡£
mysql> select CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> select CONCAT('My', NULL, 'QL');
-> NULL
mysql> select CONCAT(14.3);
-> '14.3'
È磺update test set ......

MYSQLÊý¾Ý¿âµ¼Èë¡¢µ¼³ö

1.mysqlµ¼³öÊý¾Ý¿âÃüÁî
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysqldump -u Óû§Ãû -p Êý¾Ý¿âÃû (±íÃû) > c:\\ÎļþÃû.sql
2.mysqlµ¼ÈëÊý¾Ý¿âÃüÁî
£¨1£©½â¾öÖÐÎÄÂÒÂëÎÊÌ⣺ִÐÐÈçÏÂÃüÁîÔÙµ¼È룺set names utf8
£¨2£©µÇ¼mysql£¬Ö´ÐÐÈçÏÂÃüÁ
mysql> source c:\\ÎļþÃû.sql;
3½â¾öÖÐÎÄÂÒÂëÎÊÌ⣺ִР......

¹ØÓÚMySQLµÄ²éѯ»º´æ

Ô­Àí
QueryCache(ÏÂÃæ¼ò³ÆQC)ÊǸù¾ÝSQLÓï¾äÀ´cacheµÄ¡£Ò»¸öSQL²éѯÈç¹ûÒÔselect¿ªÍ·£¬ÄÇôMySQL·þÎñÆ÷½«³¢ÊÔ¶ÔÆäʹÓÃ
QC¡£Ã¿¸öCache¶¼ÊÇÒÔSQLÎı¾×÷ΪkeyÀ´´æµÄ¡£ÔÚÓ¦ÓÃQC֮ǰ£¬SQLÎı¾²»»á±»×÷Èκδ¦Àí¡£Ò²¾ÍÊÇ˵£¬Á½¸öSQLÓï¾ä£¬Ö»ÒªÏà²îÄÄÅÂÊÇÒ»¸ö×Ö·û£¨ÀýÈç´óСд²»Ò»Ñù£»¶àÒ»¸ö¿Õ¸ñµÈ£©£¬ÄÇôÕâÁ½¸öSQL½«Ê¹Óò»Í¬µÄÒ» ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ