·¢²©ÎÄ
CLEANER

yuechaotian.blog.chinaunix.net

<script type="text/javascript" src="http://js.tongji.linezing.com/408980/tongji.js"></script><noscript><a href="http://www.linezing.com"><img src="http://img.tongji.linezing.com/408980/tongji.gif"/></   
¸öÈË×ÊÁÏ
  • ²©¿Í·ÃÎÊ£º876131
  • ²©ÎÄÊýÁ¿£º343
  • ²©¿Í»ý·Ö£º10041
  • ²©¿ÍµÈ¼¶£ºÉϽ«
  • ×¢²áʱ¼ä£º2007-01-22 11:26:01
¶©ÔÄÎҵIJ©¿Í
  • ¶©ÔÄ
  • ¶©Ôĵ½Ïʹû
  • ¶©Ôĵ½×¥Ïº
  • ¶©Ôĵ½Google
×ÖÌå´óС£º´ó ÖРС²©ÎÄ
·ÖÀࣺ ORACLE PROGRAMING

Oracle ÌṩÁËÈýÖÖ¼¯ºÏÀàÐÍ£º
 
ÁªºÏÊý×飺Îޱ߽磻¿ÉÒÔÊÇÏ¡Ê裨sparse£©µÄ£¬Ò²¿ÉÒÔÊǽôÃÜ£¨dense£©µÄ£¨¸úʹÓ÷½Ê½Ïà¹Ø£©£»²»ÄÜÓÃ×÷Áе͍ÒåÀàÐÍ¡£
ǶÌ×±í£ºÎޱ߽磻¿ªÊ¼½ôÃÜ£¬Í¨¹ýɾ³ýʹµÃÏ¡Ê裻¿ÉÒÔÓÃ×÷Áе͍ÒåÀàÐÍ¡£
Êý×飺Óб߽磻½ôÃÜ£»¿ÉÒÔÓÃ×÷Áе͍ÒåÀàÐÍ¡£
 
ÕâÈýÖÖÀàÐͶ¼ÊÇһάµÄ£¬Èç¹ûÐèÒª¶àάµÄÊý×éÀàÐÍ£¬¿ÉÒÔǶÌ×¶¨Òå¡£
 
1. ÁªºÏÊý×飨associative array£©

 

SQL> set serveroutput on

SQL> declare

  2    type type_names is table of varchar2(20) index by pls_integer;

  3    t_names type_names;

  4    pls_rows pls_integer;

  5  begin

  6    t_names(100000) := 'yuechaotian';

  7    t_names(302944003) := 'guoguo';

  8    t_names(-4903) := 'oratea';

  9    t_names(0) := 'hot_dog';

 10    pls_rows := t_names.first;

 11    while (pls_rows is not null) loop

 12      dbms_output.put_line( t_names(pls_rows) );

 13      pls_rows := t_names.next(pls_rows);

 14    end loop;

 15  end;

 16  /

oratea

hot_dog

yuechaotian

guoguo

 

PL/SQL ¹ý³ÌÒѳɹ¦Íê³É¡£

 

SQL>

 

ÕâÀïÖ»ÄÜʹÓà WHILE Ñ­»·£¬ÒòΪ¶¨ÒåµÄ±äÁ¿ t_names ÊÇÏ¡ÊèµÄ¡£Èç¹ûʹÓà FOR Ñ­»·£¬»áÅ׳ö NO_DATA_FOUND Òì³£¡£µ«ÎÒÃÇÒ²¿ÉÒÔÒÔ½ôÃܵķ½Ê½À´Ê¹ÓÃËü£º

 

SQL> declare

  2    type type_names is table of varchar2(20) index by pls_integer;

  3    t_names type_names;

  4  begin

  5    t_names(1) := 'yuechaotian';

  6    t_names(2) := 'guoguo';

  7    t_names(3) := 'oratea';

  8    t_names(4) := 'hot_dog';

  9    for n_pointer in t_names.first..t_names.last loop

 10      dbms_output.put_line( t_names(n_pointer) );

 11    end loop;

 12  end;

 13  /

yuechaotian

guoguo

oratea

hot_dog

 

PL/SQL ¹ý³ÌÒѳɹ¦Íê³É¡£

 

ÓÐʱºò£¬Ê¹ÓÃÏ¡ÊèÊý×éºÜ·½±ã¡£±ÈÈ磬Äã¿ÉÒÔʹÓñíÖÐijÁÐ×÷ΪϡÊèÊý×éµÄϱ꣬À´´æ´¢Êý¾Ý¡£

 

2. ÄÚǶ±í£¨nested table£©

 

´Ó Oracle10g Release 1 ¿ªÊ¼£¬ÄÚǶ±íÖ§³Ö MULTISET EXCEPT£¬¹¦ÄÜÓë SQL ÖÐµÄ MINUS ÀàËÆ£º

 

SQL> select * from v$version;

 

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

PL/SQL Release 10.2.0.1.0 - Production

CORE    10.2.0.1.0      Production

TNS for 32-bit Windows: Version 10.2.0.1.0 - Production

NLSRTL Version 10.2.0.1.0 - Production

 

SQL> set serveroutput on

SQL> declare

  2    type type_names is table of varchar2(20);

  3    t_names_parent type_names := type_names();

  4    t_names_children type_names := type_names();

  5    t_names_family type_names := type_names();

  6  begin

  7    t_names_family.extend(5);

  8    t_names_family(1) := 'my father';

  9    t_names_family(2) := 'my mother';

 10    t_names_family(3) := 'my sister';

 11    t_names_family(4) := 'my brother';

 12    t_names_family(5) := 'yuechaotian';

 13    t_names_children.extend;

 14    t_names_children(1) := 'my sister';

 15    t_names_children.extend;

 16    t_names_children(2) := 'my brother';

 17    t_names_children.extend;

 18    t_names_children(3) := 'yuechaotian';

 19    t_names_parent := t_names_family multiset except t_names_children;

 20    for n_pointer in t_names_parent.first..t_names_parent.last loop

 21      dbms_output.put_line( t_names_parent(n_pointer) );

 22    end loop;

 23  end;

 24  /

my father

my mother

 

PL/SQL ¹ý³ÌÒѳɹ¦Íê³É¡£

 

SQL>

 

ÒòΪÉÏÃæ¶¨ÒåµÄÄÚǶ±íÊǽôÃܵģ¬ËùÒÔ¿ÉÒÔʹÓà FOR Ñ­»·¡£Ê¹ÓÃÄÚǶ±í´æ´¢Êý¾Ýǰ£¬±ØÐë³õʼ»¯¡£Ò²±ØÐëÊÖ¹¤·ÖÅä´æ´¢¿Õ¼ä¡£

³õʼµÄÄÚǶ±íÊǽôÃܵ쬵«¿ÉÒÔͨ¹ýɾ³ý²Ù×÷ʹµÃËü±äµÃÏ¡Ê裺

 

SQL> set serveroutput on

SQL> declare

  2    type type_names is table of varchar2(20);

  3    t_names_mine type_names := type_names();

  4  begin

  5    t_names_mine.extend(3);

  6    t_names_mine(1) := 'yuechaotian';

  7    t_names_mine(2) := 'yuechaotiao';

  8    t_names_mine(3) := 'tianyc';

  9    t_names_mine.delete(2);

 10    for n_pointer in t_names_mine.first..t_names_mine.last loop

 11      if t_names_mine.exists( n_pointer ) then

 12        dbms_output.put_line( n_pointer || ' : ' || t_names_mine(n_pointer) );

 13      else

 14        dbms_output.put_line( n_pointer || ' : no data found' );

 15      end if;

 16    end loop;

 17  end;

 18  /

1 : yuechaotian

2 : no data found

3 : tianyc

 

PL/SQL ¹ý³ÌÒѳɹ¦Íê³É¡£

 

SQL>

 

3. VARRAY

 

ÎÒÃÇ¿´Ò»¸öʹÓà VARRAY ×÷ΪÁе͍ÒåÀàÐ͵ÄÀý×Ó£º

 

SQL> create type type_parent is varray(2) of varchar2(20);

  2  /

 

ÀàÐÍÒÑ´´½¨¡£

 

SQL> create type type_children is varray(3) of varchar2(20);

  2  /

 

ÀàÐÍÒÑ´´½¨¡£

 

SQL> create table my_family(

  2    province varchar2(20),

  3    parent type_parent,

  4    children type_children

  5  );

 

±íÒÑ´´½¨¡£

 

SQL> declare

  2    t_parent type_parent := type_parent();

  3    t_children type_children := type_children();

  4  begin

  5    t_parent.extend(2);

  6    t_parent(1) := 'my father';

  7    t_parent(2) := 'my mother';

  8    t_children.extend(3);

  9    t_children(1) := 'my sister';

 10    t_children(2) := 'my brother';

 11    t_children(3) := 'yuechaotian';

 12    insert into my_family

 13      values( 'Hebei', t_parent, t_children );

 14    commit;

 15  end;

 16  /

 

PL/SQL ¹ý³ÌÒѳɹ¦Íê³É¡£

 

SQL> select * from my_family;

 

PROVINCE

--------------------

PARENT

---------------------------------------------------------------

CHILDREN

---------------------------------------------------------------

Hebei

TYPE_PARENT('my father', 'my mother')

TYPE_CHILDREN('my sister', 'my brother', 'yuechaotian')

 

 

SQL>

 

¼ÈÈ» VARRAY ¿ÉÒÔ×öΪÁе͍ÒåÀàÐÍ£¬µ±È»¿ÉÒÔʹÓñäÁ¿Ãª¶¨ÁË¡£±ÈÈçÉÏÃæµÄ1-4ÐдúÂë¿ÉÒÔ¸ÄΪ£º

 

declare

  t_parent my_family.parent%type := type_parent();

  t_children my_family.children%type := type_children();

begin

 

VARRAY Óб߽硣¶¨Òåʱ±ØÐëÖ¸¶¨×î´ó³¤¶È¡£Í¬Ç¶Ì×±íÒ»Ñù£¬Ê¹Óà VARRAY ǰ±ØÐëÊ×Ïȳõʼ»¯¡£

Ç×£¬Äú»¹Ã»ÓеǼ,Çë[µÇ¼]»ò[×¢²á]ºóÔÙ½øÐÐÆÀÂÛ