oracle°üºÍREF CURSOR
Ê×ÏÈ£¬ÐèÒªÖØÐÂÕûÀíÒ»ÏÂÏà¹Ø¸ÅÄoracleÊý¾Ý¿âÖк¯ÊýµÄ×÷Óã¬ÊÇÖ»Äܱ»±ðÈ˵÷Ó㬴洢¹ý³Ì¿ÉÒÔµ¥¶ÀÖ´ÐУ¬²¢ÇÒ¿ÉÒÔµ÷Óô洢¹ý³Ì£¬¶ø°üµÄ×÷Óðü¿ÉÒÔ½«ÈκγöÏÖÔÚ¿éÉùÃ÷µÄÓï¾ä ( ¹ý³Ì , º¯Êý , Óαê , Óαê , ÀàÐÍ , ±äÁ¿ ) ·ÅÓÚ°üÖÐ , Ï൱ÓÚÒ»¸öÈÝÆ÷ . ½«ÉùÃ÷Óï¾ä·ÅÈë°üÖеĺô¦ÊÇ : Óû§¿ÉÒÔ´ÓÆäËû PL/SQL ¿éÖжÔÆä½øÐÐÒýÓà , Òò´Ë°üΪ PL/SQL ÌṩÁËÈ«¾Ö±äÁ¿£¬°ü·ÖΪ°üÍ·ºÍ°üÌ壬°üÍ·ÏȱàÒëͨ¹ýºó²ÅÄܱàÒë°üÌå¡£
°üÍ·µÄ´´½¨£º
1) °üÍ· :
Óï·¨¸ñʽ :
CREATE OR REPLACE PACKAGE package_name /* °üÍ·Ãû³Æ */
IS|AS
pl/sql_package_spec /* ¶¨Òå¹ý³Ì , º¯ÊýÒÔ¼°·µ»ØÀàÐÍ , ±äÁ¿ , ³£Á¿¼°Êý¾ÝÀàÐͶ¨Òå */
¶¨Òå°üÍ·Ó¦µ±×ñÑÒÔÏÂÔÔò :
1) °üÔªËØλÖÿÉÒÔÈÎÒâ°²ÅÅ . È»¶øÔÚÉùÃ÷²¿·Ö , ¶ÔÏó±ØÐëÔÚÒýÓÃÇ°½øÐÐÉùÃ÷ .
2) °üÍ·¿ÉÒÔ²»¶ÔÈκÎÀàÐ͵ÄÔªËؽøÐÐ˵Ã÷ . ÀýÈç , °üÍ·¿ÉÒÔÖ»´ø¹ý³ÌºÍº¯Êý˵Ã÷Óï¾ä , ¶ø²»ÉùÃ÷ÈκÎÒì³£ºÍÀàÐÍ .
3) ¶Ô¹ý³ÌºÍº¯ÊýµÄÈκÎÉùÃ÷¶¼±ØÐëÖ»¶Ô×Ó³ÌÐòºÍÆä²ÎÊý½øÐÐÃèÊö , ²»ÄÜÓÐÈκδúÂëµÄ˵Ã÷ , ´úÂëµÄʵÏÖÖ»ÄÜÔÚ°üÌåÖгöÏÖ . Ëü²»Í¬ÓÚ¿éÉùÃ÷ , ÔÚ¿éÉùÃ÷ÖÐ , ¹ý³ÌºÍº¯ÊýµÄ´úÂë¿Éͬʱ³öÏÖÔÚÉùÃ÷²¿·Ö .
2. °üÌå :
Óï·¨¸ñʽ :
CREATE OR REPLACE PACKAGE BODY package_name/* °üÃû±ØÐëÓë°üÍ·µÄ°üÃûÒ»Ö */
IS | AS
pl/sql_package_body /* Óαê , º¯Êý , ¹ý³ÌµÄ¾ßÌ嶨Òå */
°üÌåÊÇÓë°üÍ·Ï໥¶ÀÁ¢µÄ , °üÌåÖ»ÄÜÔÚ°üÍ·Íê³É±àÒëºó²ÅÄܽøÐбàÒë . °üÌåÖдøÓаüÍ·ÖÐÃèÊöµÄ×Ó³ÌÐòµÄ¾ßÌåʵÏֵĴúÂë¶Î . ³ý´ËÖ®Íâ , °üÌ廹¿ÉÒÔ°üÀ¨¾ßÓаüÌåÈËÈ«¾äÊôÐԵĸ½¼ÓÉùÃ÷²¿·Ö , µ«ÕâЩ¸½¼ÓÉùÃ÷¶ÔÓÚ°üÍ·ÊDz»¼ûµÄ .
Demo:
****************
*°ü
****************
create or replace package mypack
as
type mytype is ref cursor return emp%rowtype; --ÉùÃ÷REFÓαê
function myemp(dno number) return mytype;
end;
****************
*body
****************
create or replace package body mypack
as
function myemp(dno
Ïà¹ØÎĵµ£º
ÈçºÎÐÞ¸ÄOracleĬÈÏÓû§ÃÜÂëÓÐЧÆÚʱ¼ä 1¡¢²é¿´Óû§µÄproifleÊÇÄĸö£¬Ò»°ãÊÇdefault£º sql>SELECT username,PROFILE from dba_users; 2¡¢²é¿´Ö¸¶¨¸ÅÒªÎļþ£¨Èçdefault£©µÄÃÜÂëÓÐЧÆÚÉèÖ㺠sql>SELECT * from dba_profiles s WHERE s.profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME'; 3¡¢½«ÃÜÂëÓÐЧÆÚÓÉĬ ......
create table tree_table
(
id number,
pId number,
orderNumber number,
name varchar2(255)
)
select tt.*
from tree_table tt
start with tt.pId = 0
connect by prior tt.id = ttd.pId
order siblings by orderNumber ......
ÒÔÍù´ÓÀ´Ã»ÓÐÏëÈ¥ÈÏÕæ¶ÁÒ»´ÎOracleµÄ°æȨÉùÃ÷£¬½ñÌì´ò¿ªOracle10gR2µÄÎĵµ£¬ÓÚÊǾÍË÷ÐÔ´ÓÍ·¿ªÊ¼¶ÁÒ»ÏÂÕâƪÎÄÕ¡£
һЩÎÒÏë´ó¼Ò¶¼Ó¦¸ÃÈ¥ÖªµÀµÄ£¬ËäÈ»¹úÄڵİæȨ¸ÅÄîʵÔÚÊDZȽϵ±¡£¬µ«ÏëÀ´»áÔ½À´Ô½ºÃµÄ¡£
Oracle10g·ÖΪ4¸ö°æ±¾£¬·Ö±ðÊÇ£º
1¡£Oracle Database Standard Edition One£¬×î»ù±¾µÄÉÌÒµ°æ± ......
OracleÖÐÌṩһϵÁÐÀàÐÍ£¬Ã¿¸öÀàÐ͵ÄÌصãÈçÏ£º
char£º´æ´¢¹Ì¶¨³¤¶ÈµÄ×Ö·û£¬Èç¹û×Ö·û³¤¶È²»¹»»áÔÚÓұ߲¹¿Õ¸ñ¡£±ÈÈ磺name char£¨10£©£¬µ±¸øname¸³ÖµÎª'zhangsan'ʱ»áÔÚÓұ߲¹³ä2¸ö¿Õ¸ñ¡£charÀàÐ͵ÄÈÝÁ¿Îª1¡«2000B£¬Ã»ÓÐÖ¸¶¨ÔòĬÈϳ¤¶ÈΪ1¡£
varchar2£º´æ´¢³¤¶È¿É±äµÄ×Ö·û£¬ºÍcharÀàÐ͵IJ»Í¬£¬Ëü²»»á×Ô¶¯²¹³ä¿Õ¸ñ£¬ÇÒ¶¨ÒåÊ ......
¸½:Oracle SQL Developer — À©Õ¹½»Á÷ÖÐÐÄ
http://www.oracle.com/technology/global/cn/products/database/sql_developer/files/extensions.htm
֮ǰ×÷Ϊһ¸öOracle Employee£¬È´×ÜÊÇÔÚʹÓÃPL/SQL Developer£¨¶øÇÒÊÇÆƽâ°æ£©£¬ÕâʵÔÚÓÐЩ˵²»¹ýÈ¥£¬µ«ÊÇÈçºÎÕÒµ½Ò»¸öºÏÐijÃÊÖµÄÄܹ»Ô ......