[ת] ½âÎöoracleµÄROWNUM ×÷Õß: chen_liang
¶ÔÓÚrownumÀ´ËµËüÊÇoracleϵͳ˳Ðò·ÖÅäΪ´Ó²éѯ·µ»ØµÄÐеıàºÅ£¬·µ»ØµÄµÚÒ»ÐзÖÅäµÄÊÇ1£¬µÚ¶þÐÐÊÇ2£¬ÒÀ´ËÀàÍÆ£¬Õâ¸öα×ֶοÉÒÔÓÃÓÚÏÞÖƲéѯ·µ»ØµÄ×ÜÐÐÊý£¬¶øÇÒrownum²»ÄÜÒÔÈκαíµÄÃû³Æ×÷Ϊǰ׺¡£
¾ÙÀý˵Ã÷£º
ÀýÈç±í£ºstudent(ѧÉú)±í£¬±í½á¹¹Îª£º
ID¡¡¡¡¡¡ char(6)¡¡¡¡¡¡¡¡¡¡ --ѧºÅ
name¡¡¡¡¡¡¡¡VARCHAR2(10)¡¡¡¡¡¡--ÐÕÃû
create table student (ID char(6), name VARCHAR2(100));
insert into sale values('200001',‘ÕÅÒ»’);
insert into sale values('200002',‘Íõ¶þ’);
insert into sale values('200003',‘ÀîÈý’);
insert into sale values('200004',‘ÕÔËÄ’);
commit;
(1) rownum ¶ÔÓÚµÈÓÚijֵµÄ²éѯÌõ¼þ
Èç¹ûÏ£ÍûÕÒµ½Ñ§Éú±íÖеÚÒ»ÌõѧÉúµÄÐÅÏ¢£¬¿ÉÒÔʹÓÃrownum=1×÷ΪÌõ¼þ¡£µ«ÊÇÏëÕÒµ½Ñ§Éú±íÖеڶþÌõѧÉúµÄÐÅÏ¢£¬Ê¹ÓÃrownum=2½á¹û²é²»µ½Êý¾Ý¡£ÒòΪrownum¶¼ÊÇ´Ó1¿ªÊ¼£¬µ«ÊÇ1ÒÔÉϵÄ×ÔÈ»ÊýÔÚrownum×öµÈÓÚÅжÏÊÇʱÈÏΪ¶¼ÊÇfalseÌõ¼þ£¬ËùÒÔÎÞ·¨²éµ½rownum = n£¨n>1µÄ×ÔÈ»Êý£©¡£
SQL> select rownum,id,name from student where rownum=1;£¨¿ÉÒÔÓÃÔÚÏÞÖÆ·µ»Ø¼Ç¼ÌõÊýµÄµØ·½£¬±£Ö¤²»³ö´í£¬È磺ÒþʽÓα꣩
SQL> select rownum,id,name from student where rownum=1;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
1 200001 ÕÅÒ»
SQL> select rownum,id,name from student where rownum =2;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
£¨2£©rownum¶ÔÓÚ´óÓÚijֵµÄ²éѯÌõ¼þ
Èç¹ûÏëÕÒµ½´ÓµÚ¶þÐмǼÒÔºóµÄ¼Ç¼£¬µ±Ê¹ÓÃrownum>2ÊDz鲻³ö¼Ç¼µÄ£¬ÔÒòÊÇÓÉÓÚrownumÊÇÒ»¸ö×ÜÊÇ´Ó1¿ªÊ¼µÄαÁУ¬Oracle ÈÏΪrownum> n(n>1µÄ×ÔÈ»Êý)ÕâÖÖÌõ¼þÒÀ¾É²»³ÉÁ¢£¬ËùÒԲ鲻µ½¼Ç¼
SQL> select rownum,id,name from student where rownum >2;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
ÄÇÈçºÎ²ÅÄÜÕÒµ½µÚ¶þÐÐÒÔºóµÄ¼Ç¼ѽ¡£¿ÉÒÔʹÓÃÒÔϵÄ×Ó²éѯ·½·¨À´½â¾ö¡£×¢Òâ×Ó²éѯÖеÄrownum±ØÐëÒªÓбðÃû£¬·ñÔò»¹ÊDz»»á²é³ö¼Ç¼À´£¬
Ïà¹ØÎĵµ£º
oracle±í¿Õ¼ä²Ù×÷Ïê½â
1
2
3×÷Õߣº À´Ô´£º ¸üÐÂÈÕÆÚ£º2006-01-04
5
6
7½¨Á¢±í¿Õ¼ä
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
ËäȻѧϰJavaºÜ¾ÃÁË£¬×Ô¼ºÒ²Á¬½Ó¹ýһЩÊý¾Ý¿â£¬±ÈÈçmysqlÖ®ÀàµÄ£¬Èç½ñÄØ£¬Ò²Ñ§Ï°ÁËÒ»¶Îʱ¼äµÄOracle£¬È»¶øÄØ£¬½ñÌìÊÇÎÒµÚÒ»´ÎÁ¬½ÓOracle£¬ºÙºÙ£¬Ó¦¸Ã»¹²»ËãÌ«³Ù°É¡£
½ñÌìÄØ£¬Óе㱿׾£¬´ó¼ÒĪЦ£¡
ÎÒÕâÊÇÒ»¸ö²éѯÀý×Ó
Ê×ÏÈ£¬Ô ......
°Ñ×Ô¼ºËѼ¯µÄ×ÊÁÏÌù³öÀ´£¬Ñ§Ï°¹¤×÷·½±ãÕ¼¡£
SQLÖеĵ¥¼Ç¼º¯Êý
1.ASCII
·µ»ØÓëÖ¸¶¨µÄ×Ö·û¶ÔÓ¦µÄÊ®½øÖÆÊý;
SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48 32
2.CHR
¸ø³öÕûÊý,·µ»Ø¶ÔÓ¦µÄ×Ö·û;
SQ ......
ÈÝÒ×µÃ˵£¬¾¹ýdbms_random°üµ÷ÓÃËæ»úÊýµÄ²½Öè´óÌåÓÐ4ÖÖ£º
Ò»¡¢dbms_random.normal
Õâ¸öº¯Êý²»´ø²ÎÊý£¬»á»Øµ½normal distributionµÄÒ»¸önumberÃÅÀ֮࣬ËùÒÔ´óµÖËæ»úÊý»áÔÚ-Ò»µ½Ò»Æä¼ä¡£
¼òÂÔ²âÊÔÁËÒ»ÏÂ×Ó£¬·¢×÷100000´Î×î´óÄܵ½ÎåÉÏÏ£º
SQL> declare
¶þ i number:=Áã;
Èý j number:=Áã;
ËÄ begin
Îå for ......
СÒý
Oracle RdbmsÊ©ÓÃÁ˸÷ÖÖ²»Í¬ÀàÐ͵ÄËø¶¨»úÖÆ£¬latchµÈÓÚ´ËÖеÄÒ»ÖÖ£¬ÕýÎĽ«¼¯ÖÐÒý¼ûlatch(ãÅ)µÄ¸ÅÄ¶®µÃlatchµÄ¶ÒÏÖ²½Ö貢˵Ã÷»½ÆðlatchĦ²ÁµÄÔµ¹Ê¡£
ʲôÊÇlatch
LatchÊÇÓÃÀ´±£»¤SGAÇøÖй²ÏíÊý¾Ý½á¹¹µÄÒ»ÖÖ´®Ðл¯Ëø¶¨»úÖÆ¡£LatchµÄ¶ÒÏÖÊÇÓë²Ù×÷ϵͳÏà¸ÉµÄ£¬ÓÈÉõºÍÒ»¸ö¹ý³ÌÊDz»ÊÇؽÐèµÈºòÒ»¸ölatch¡¢¼±ÐèµÈº ......