ORACLE PL/SQL
Ò»¡¢Ê²Ã´ÊÇPL/SQL?
PL/SQL(Procedural Language/SQL)ÊǶÔSQLµÄÀ©³ä,ËüÎüÊÕÁ˽üÄêÀ´±à³ÌÓïÑÔµÄÐí¶à×î¸ßÉè¼ÆÌصã:ÈçÊý¾Ý·â×°ÐÔ¡¢ÐÅÏ¢Òþ±ÎÐÔ¡¢ÖØÔغÍÀýÍâ´¦ÀíµÈ¡£ËüÔÊÐíSQLµÄÊý¾Ý²Ù×ÝÓïÑԺͲéѯÓï¾ä°üº¬ÔÚ¿é½á¹¹(block_structured)ºÍ´úÂë¹ý³ÌÓïÑÔÖÐ,ʹPL/SQL³ÉΪһ¸ö¹¦ÄÜÇ¿´óµÄÊÂÎñ´¦ÀíÓïÑÔ¡£
PL/SQLµÄÓŵãÈçÏÂ:
1.¿é½á¹¹(Block Structure)
PL/SQLÊÇ¿é½á¹¹ÓïÑÔ,Òâζ×ųÌÐò¿ÉÒÔ·Ö³ÉÈô¸ÉÂß¼¿é,¸÷×Ô°üº¬ÄǸöµ¥ÔªÀïÒªÇóµÄÂß¼ÓïÑÔ×ÊÔ´¡£¿ÉÒÔ¶Ô¿éÐû²¼±¾µØ±äÁ¿£¬ÔÚ¿éÖÐʹÓÃÕâЩ±äÁ¿,¿ÉÔÚËüÃÇÓ¦ÓõĿéÖÐÌرðµØ´¦Àí´íÎóÌõ¼þ(½Ð×öExceptions)
2. Á÷³Ì¿ØÖÆ
Ìõ¼þÓï¾ä¡¢Ñ»·ºÍ·ÖÖ§¿ÉÓÃÀ´¿ØÖƳÌÐòµÄ¹ý³ÌÁ÷£¬ÒÔ¾ö¶¨ÊÇ·ñ»òºÎʱִÐÐSQL»òÆäËüÐж¯¡£ÕâЩÌصãÔÊÐíORACLE¹¤¾ß(ÖîÈçSQL*Forms)È¥·Ö×éÁªÏµÔÚÒ»ÆðµÄÃüÁî×éºÍͨ¹ýPL/SQL¿ØÖÆËüÃǵÄÖ´ÐС£ÕâÑù¿ÉÒÔ±ÜÃâÖÃÐí¶àÃüÁîΪµ¥¶ÀµÄ´¥·¢Æ÷²½Öè»òÕßǶÌ×Íⲿ±à³ÌÓïÑÔÖеÄSQLÓï¾äµÄÒªÇó¡£
3. ¿ÉÒÆÖ²ÐÔ
ÒòΪPL/SQLÊÇORACLEµÄÖ÷ÓïÑÔ,¹Ê³ÌÐò¿ÉÒÆÖ²ÖÁÖ§³ÖORACLEºÍPL/SQLµÄÈκβÙ×÷ϵͳƽ̨ÉÏ¡£
4.¼¯³ÉÐÔ
PL/SQLÔÚRDBMS(´æÖü¹ý³Ì¡¢´¥·¢Æ÷¡¢°ü)ºÍORACLE¹¤¾ßÖаçÑÝÁËÈÕÒæÔö³¤µÄÖÐÐĽÇÉ«¡£PL/SQLµÄ±äÁ¿ºÍÐÍÓëSQLµÄ±äÁ¿ºÍÐͼæÈÝ(Óë×Ô¼ºÓÃÔÚÊý¾Ý¿âÁÐÖеÄÐÍÒ²¼æÈÝ)¡£Òò´Ë£¬PL/SQLÊÇÁ¬½ÓÊý¾Ý¿â¼¼ÊõºÍ¹ý³Ì±à³ÌÄÜÁ¦Ö®¼ä¼ä϶µÄ·½±ãµÄÇÅÁº¡£
5. ¸Ä½øÁËÐÔÄÜ
PL/SQLµÄʹÓÿÉÒÔ°ïÖú¸Ä½øÓ¦ÓóÌÐòµÄÐÔÄÜ¡£ÔÚûÓÐPL/SQLʱ,ORACLEÿ´ÎÖ»´¦ÀíÒ»¸öSQLÓï¾ä,¶øÔÚ¾ßÓÐPL/SQLʱ,Ò»¸öÍêÕûµÄÓï¾ä¿éÒ»´Î·¢Ë͵½ORACLE,¿ÉÃ÷ÏԵؼõÉÙÓëORACLEÖ®¼äµÄͨÐź͵÷Óá£Ìá¸ßÁËЧÒ档ЧÒæµÄ²îÒìÈ¡¾öÓÚPL/SQLʹÓõÄʲô»·¾³¡£ÕâЩЧÒæÉÔºóÌÖÂÛ¡¡
¶þ¡¢PL/SQLµÄ½á¹¹
PL/SQLµÄÿ¸öµ¥ÔªÓÉÒ»¸ö»ò¶à¸ö¿é(blocks)×é³É¡£ÕâЩ¿é¿ÉÒÔÊÇÍêÈ«¶ÀÁ¢µÄ,»òÕßÒ»¸ö¿éǶÌ×ÔÚÁíÒ»¸ö¿éÖ®ÖС£ÕâÑù,Ò»¸ö¿é¿É±íʾÆäËü¿éµÄһС²¿·Ö,·´¹ýÀ´,ËüÇ¡ºÃÒ²ÊÇÕû¸ö³ÌÐòÂëµ¥ÔªµÄÒ»²¿·Ö¡£
ͨ³£,Ò»¸ö¿é¿ÉÒÔÊÇÎÞÃû¿é»òÕßÒ»¸ö×Ó³ÌÐò¡£
1. ÎÞÃû¿é(anonymous)
ÎÞÃû¿éÊÇÒ»ÖÖûÓÐÃû×ֵĿ顣ÕâЩ¿éÔÚÔËÐÐËüÃǵÄÓ¦ÓóÌÐòÖÐ˵Ã÷£¬²¢ÇÒΪÁËÖ´ÐÐÔÚÔËÐÐʱÓÉPL/SQLÒýÇæͨ¹ý¡£ÎÞÃû¿é¿ÉÒÔǶÈëÔ¤±àÒë³ÌÐò(»òOCI³ÌÐò)¡¢ÒÔ¼°SQL*PLUS»òSQL*DBAÖС£SQL*FormsÖеĴ¥·¢Æ÷Ò²ÓÉÕâЩ¿é×é³É,ÎÞÃû¿éÓõý϶ࡣ
ÎÞÃû¿éµÄ¶¨ÒåÐÎʽΪ:
DECLARE
--˵Ã÷
BEGIN
--Óï¾äÐòÁÐ
[EXCEPT
Ïà¹ØÎĵµ£º
ѧϰOracle DBAÒ²°ë¸ö¶àѧÆÚÁË£¬½ñÌìÃÍÈ»²Å·¢ÏÖ£¬ÔÀ´ÎÒµÄÊ黹ÊǺÜеģ¬ÉϿβÙ×÷ʱºòÒ²Ö»ÊÇÖªµÀ´ó¸ÅÔõô×ö£¬µ«ÊÇÒªÕæµÄÈ«²¿×Ô¼º×ö£¬¶ø²»È¥·Ê黹ÊÇÓÐÒ»¶¨µÄÄѶȵģ¬ËùÒÔÄØ£¬½ñÌ쿪ʼ½«DBA´ÓÍ·¸´Ï°Ò»±é£¬Í¬Ê±ÔÙ²Ù×÷Ò»±é¡£
µÚÒ»Õ£¬Ñ§µÄÊÇOracleµÄÌåϵ½á¹¹£ ......
Õâ´ÎÈ¥ÉÇÍ·ÊǸøÉÇÍ·µçÐŽ²¿Î,Ö÷½²ORACLEÊý¾Ý¿âÐÔÄÜÓÅ»¯,ΪÆÚ4Ìì.´ÓÂÞºþÆû³µÕ¾³ö·¢,×ßÉîÉǸßËÙ,´óÔ¼4,5¸öÖӾ͵½ÉÇÍ·ÁË.
³ö·¢Ê±ÊÇ°øÍí,³µ×ÓÔÚÉîÉǸßËÙÐнø,ϦÑôÎ÷Ï£¬ÂäÈÕµÄÓà»ÔÕÕÓ³ÔÚ¹«Â·Á½±ßµÄÇðÁê,ɽÌÁÉÏ£¬¿´ÉÏÈ¥ºÜÃÀ¡£ÉîÉǸßËٴ󲿷ÖÊÇÑØן£°¶ÏßòêÑÑ£¬ËùÒÔ£¬ÓÐʱÔÚ³µÉϾÍÄܹ»¿´µ½º££¬ÂäÈÕµÄÓà»ÔÕÕÔÚ´óº£ÉÏ£¬²¨¹âÁÛÁÛ£¬¼ ......
ÏÂÃæ¾ÍÀ´½éÉÜÒ»ÏÂÕâЩÔÚºǫ́ÐÁÇÚ¹¤×÷µÄ½ø³ÌÃÇ¡£ÏµÍ³¼ì²âÆ÷£¨System Monitor,SMON£©¡¢½ø³Ì¼àÊÓÆ÷£¨Process
Monitor,PMON£©¡¢Êý¾Ý¿âдÈëÆ÷£¨Database Writer,DBWn£©¡¢ÈÕ־дÈëÆ÷£¨Log
Writer,LGWR£©¡¢¼ì²éµã½ø³Ì£¨Checkpoint Process,CKPT£© ¡£
1¡¢SMON£º°²×°ºÍ´ò¿ªÊý¾Ý¿â¡£Í¨¹ý²éÕÒºÍ
ÑéÖ¤Êý¾Ý¿â¿ØÖÆ ......
Ò»¡¢±³¾°½éÉÜ
¡¡¡¡
¡¡¡¡½á¹¹»¯²éѯÓïÑÔ(Structured Query Language£¬¼ò³ÆSQL)ÊÇÓÃÀ´·ÃÎʹØϵÐÍÊý¾Ý¿âÒ»ÖÖͨÓÃÓïÑÔ£¬ÊôÓÚµÚËÄ´úÓïÑÔ£¨4GL£©£¬ÆäÖ´ÐÐÌصãÊǷǹý³Ì»¯£¬¼´²»ÓÃÖ¸Ã÷Ö´ÐеľßÌå·½·¨ºÍ;¾¶£¬¶øÊǼòµ¥µØµ÷ÓÃÏàÓ¦Óï¾äÀ´Ö±½ÓÈ¡µÃ½á¹û¼´¿É¡£ÏÔÈ»£¬ÕâÖÖ²»¹Ø×¢ÈκÎʵÏÖϸ½ÚµÄÓïÑÔ¶ÔÓÚ¿ª·¢ÕßÀ´ËµÓÐ׿«´óµÄ±ãÀû¡£È»¶ø£¬Ó ......