OracleÖÐCursor½éÉܺÍʹÓÃ
Ò» ¸ÅÄî
ÓαêÊÇSQLµÄÒ»¸öÄڴ湤×÷Çø£¬ÓÉϵͳ»òÓû§ÒÔ±äÁ¿µÄÐÎʽ¶¨Òå¡£ÓαêµÄ×÷ÓþÍÊÇÓÃÓÚÁÙʱ´æ´¢´ÓÊý¾Ý¿âÖÐÌáÈ¡µÄÊý¾Ý¿é¡£ÔÚijЩÇé¿öÏ£¬ÐèÒª°ÑÊý¾Ý´Ó´æ·ÅÔÚ´ÅÅ̵ıíÖе÷µ½¼ÆËã»úÄÚ´æÖнøÐд¦Àí£¬×îºó½«´¦Àí½á¹ûÏÔʾ³öÀ´»ò×îÖÕд»ØÊý¾Ý¿â¡£ÕâÑùÊý¾Ý´¦ÀíµÄËٶȲŻáÌá¸ß£¬·ñÔòƵ·±µÄ´ÅÅÌÊý¾Ý½»»»»á½µµÍЧÂÊ¡£
¶þ ÀàÐÍ
CursorÀàÐÍ°üº¬ÈýÖÖ: ÒþʽCursor£¬ÏÔʽCursorºÍRef Cursor£¨¶¯Ì¬Cursor£©¡£
1£® ÒþʽCursor:
1).¶ÔÓÚSelect …INTO…Óï¾ä£¬Ò»´ÎÖ»ÄÜ´ÓÊý¾Ý¿âÖлñÈ¡µ½Ò»ÌõÊý¾Ý£¬¶ÔÓÚÕâÖÖÀàÐ͵ÄDML SqlÓï¾ä£¬¾ÍÊÇÒþʽCursor¡£ÀýÈ磺Select /Update / Insert/Delete²Ù×÷¡£
2)×÷Ó㺿ÉÒÔͨ¹ýÒþʽCusorµÄÊôÐÔÀ´Á˽â²Ù×÷µÄ״̬ºÍ½á¹û£¬´Ó¶ø´ïµ½Á÷³ÌµÄ¿ØÖÆ¡£CursorµÄÊôÐÔ°üº¬£º
SQL%ROWCOUNT ÕûÐÍ ´ú±íDMLÓï¾ä³É¹¦Ö´ÐеÄÊý¾ÝÐÐÊý
SQL%FOUND ²¼¶ûÐÍ ÖµÎªTRUE´ú±í²åÈ롢ɾ³ý¡¢¸üлòµ¥Ðвéѯ²Ù×÷³É¹¦
SQL%NOTFOUND ²¼¶ûÐÍ ÓëSQL%FOUNDÊôÐÔ·µ»ØÖµÏà·´
SQL%ISOPEN ²¼¶ûÐÍ DMLÖ´Ðйý³ÌÖÐΪÕ棬½áÊøºóΪ¼Ù
3) ÒþʽCursorÊÇϵͳ×Ô¶¯´ò¿ªºÍ¹Ø±ÕCursor.
ÏÂÃæÊÇÒ»¸öSample£º
Set Serveroutput on;
begin
update t_contract_master set liability_state = 1 where policy_code = '123456789';
if SQL%Found then
dbms_output.put_line('the Policy is updated successfully.');
commit;
else
dbms_output.put_line('the policy is updated failed.');
end if;
end;
/
2£® ÏÔʽCursor£º
£¨1£© ¶ÔÓÚ´ÓÊý¾Ý¿âÖÐÌáÈ¡¶àÐÐÊý¾Ý£¬¾ÍÐèҪʹÓÃÏÔʽCursor¡£ÏÔʽCursorµÄÊôÐÔ°üº¬£º
ÓαêµÄÊôÐÔ ·µ»ØÖµÀàÐÍ Òâ Òå
%ROWCOUNT ÕûÐÍ »ñµÃFETCHÓï¾ä·µ»ØµÄÊý¾ÝÐÐÊý
%FOUND ²¼¶ûÐÍ ×î½üµÄFETCHÓï¾ä·µ»ØÒ»ÐÐÊý¾ÝÔòΪÕ棬·ñÔòΪ¼Ù
%NOTFOUND ²¼¶ûÐÍ Óë%FOUNDÊôÐÔ·µ»ØÖµÏà·´
%ISOPEN ²¼¶ûÐÍ ÓαêÒѾ´ò¿ªÊ±ÖµÎªÕ棬·ñÔòΪ¼Ù
£¨2£© ¶ÔÓÚÏÔʽÓαêµÄÔËÓ÷ÖΪËĸö²½Ö裺
¶¨ÒåÓαê---Cursor [Cursor Name] IS;
´ò¿ªÓαê---Open [Cursor Name];
²Ù×÷Êý¾Ý---Fetch [Cursor name]
¹Ø±ÕÓαê---Close [Cursor Name],Õâ¸öStep¾ø¶Ô²»¿ÉÒÔÒÅ©¡£
£¨3£©ÒÔÏÂÊ
Ïà¹ØÎĵµ£º
ÔÚoracle°²×°Ä¿Â¼$HOME/network/adminÏ£¬¾³£¿´µ½sqlnet.ora tnsnames.ora
listener.oraÕâÈý¸öÎļþ£¬³ýÁËtnsnames.ora£¬ÆäËûÁ½¸öÎļþÏêϸµÄÓÃ;ºÜ¶àÈ˶¼²»Ì«Á˽⡣
sqlnet.ora ÓÃÔÚoracle client¶Ë£¬ÓÃÓÚÅäÖÃÁ¬½Ó·þÎñ¶ËoracleµÄÏà¹Ø²ÎÊý.
tnsnames.ora ÓÃÔÚoracle
client¶Ë£¬Óû§ÅäÖÃÁ¬½ÓÊý¾Ý¿âµÄ±ðÃû²ÎÊý,¾ÍÏñÏµÍ³Ö ......
ÎÒÏë×î³õѧϰÊý¾Ý¿âʱ¶¼ÊÇÒÔstudent±í¡¢course±íºÍsc±íΪÀýµÄ°É
Ê×ÏÈ´´½¨ÕâÈýÕÅ±í£º±ØҪʱ¿ÉÖØд´½¨Óû§¼°ÃÜÂë²¢µÇ½
»·¾³£ºoracle 10g
declare
vcnt number;
begin
select count(*) into vcnt from user_tables where table_name='SC';
If vcnt = 1 Then
Execute immedi ......
--21.1 Data Pump¹¤¾ß
Data Pump
´Óoracledatabase 10g¿ªÊ¼ÒýÈëÁËdata pump(Êý¾Ý±Ã)¹¤¾ß£¬ËüÌṩÁËÒ»ÖÖ»ùÓÚ·þÎñÆ÷µÄÊý¾Ýµ¼³öµ¼ÈëʹÓóÌÐò¡£
ËùÓеÄdata pump¶¼×÷Ϊһ¸ö·þÎñÆ÷½ø³Ì£¬Êý¾Ý²»ÔÙ±ØÐëÓÉÒ»¸ö¿Í»§³ÌÐò´¦Àí¡£Data Pump¹¤¾ßµÄµ¼³öºÍµ¼ÈëʵÏÖ
OracleÊý¾Ý¿âÖ®¼äÊý¾ÝµÄ´ ......
Ç°ÑÔ:ÍøÉÏÓкܶà½â¾ö°ì·¨£¬É¾listener.oraÒ²ºÃ£¬»¹ÊÇʲôҲºÃ£¬¶¼½â¾ö²»ÁËÎÒÕâ¸öÎÊÌ⣬ÒÀÈ»±¨12514´íÎó£¬ÒÔÏÂÊÇÎÒÖð¸ö³¢ÊÔºó³É¹¦µÄ¼àÌý×Ö·û´®¡£¡£
listener.oraÎļþ£º
# listener.ora Network Configuration File: d:\app\john\product\11.1.0\db_1\network\admin\listener.ora
# Generated by Oracle configuration too ......