ORACLE ÖÐROWNUMÓ÷¨×ܽá
2009-11-15 13:06:35
½ñÌìÔÚITPUB·¢ÏÖһƪÎÄÕ£¬ÀÏÔçÒÔÇ°µÄÁË£¬Ð´µÄÂùÓÐÒâ˼£¬ÌØÒâת¹ýÀ´Êղء£
¶ÔÓÚ Oracle µÄ rownum ÎÊÌ⣬ºÜ¶à×ÊÁ϶¼Ëµ²»Ö§³Ö>,>=,=,between...and£¬Ö»ÄÜÓÃÒÔÉÏ·ûºÅ(<¡¢<=¡¢!=)£¬²¢·Ç˵ÓÃ>, >=,=,between..and ʱ»áÌáʾSQLÓï·¨´íÎ󣬶øÊǾ³£ÊDz鲻³öÒ»Ìõ¼Ç¼À´£¬»¹»á³öÏÖËƺõÊÇĪÃûÆäÃîµÄ½á¹ûÀ´£¬ÆäʵÄúÖ»ÒªÀí½âºÃÁËÕâ¸ö rownum αÁеÄÒâÒå¾Í²»Ó¦¸Ã¸Ðµ½¾ªÆ棬ͬÑùÊÇαÁУ¬rownum Óë rowid ¿ÉÓÐЩ²»Ò»Ñù£¬ÏÂÃæÒÔÀý×Ó˵Ã÷
¡¡¡¡¼ÙÉèij¸ö±í t1(c1) ÓÐ 20 Ìõ¼Ç¼
¡¡¡¡Èç¹ûÓà select rownum,c1 from t1 where rownum < 10, Ö»ÒªÊÇÓÃСÓںţ¬²é³öÀ´µÄ½á¹ûºÜÈÝÒ×µØÓëÒ»°ãÀí½âÔÚ¸ÅÄîÉÏÄÜ´ï³ÉÒ»Ö£¬Ó¦¸Ã²»»áÓÐÈκÎÒÉÎʵġ£
¡¡¡¡¿ÉÈç¹ûÓà select rownum,c1 from t1 where rownum > 10 (Èç¹ûдÏÂÕâÑùµÄ²éѯÓï¾ä£¬ÕâʱºòÔÚÄúµÄÍ·ÄÔÖÐÓ¦¸ÃÊÇÏëµÃµ½±íÖкóÃæ10Ìõ¼Ç¼)£¬Äã¾Í»á·¢ÏÖ£¬ÏÔʾ³öÀ´µÄ½á¹ûÒªÈÃÄúʧÍûÁË£¬Ò²ÐíÄú»¹»á»³ÒÉÊDz»ËɾÁËһЩ¼Ç¼£¬È»ºó²é¿´¼Ç¼Êý£¬ÈÔÈ»ÊÇ 20 Ìõ°¡£¿ÄÇÎÊÌâÊdzöÔÚÄÄÄØ£¿
¡¡¡¡ÏȺúÃÀí½â rownum µÄÒâÒå°É¡£ÒòΪROWNUMÊǶԽá¹û¼¯¼ÓµÄÒ»¸öαÁУ¬¼´ÏȲ鵽½á¹û¼¯Ö®ºóÔÙ¼ÓÉÏÈ¥µÄÒ»¸öÁÐ (Ç¿µ÷£ºÏÈÒªÓнá¹û¼¯)¡£¼òµ¥µÄ˵ rownum ÊǶԷûºÏÌõ¼þ½á¹ûµÄÐòÁкš£Ëü×ÜÊÇ´Ó1¿ªÊ¼ÅÅÆðµÄ¡£ËùÒÔÄãÑ¡³öµÄ½á¹û²»¿ÉÄÜûÓÐ1£¬¶øÓÐÆäËû´óÓÚ1µÄÖµ¡£ËùÒÔÄúû°ì·¨ÆÚÍûµÃµ½ÏÂÃæµÄ½á¹û¼¯£º
¡¡¡¡11 aaaaaaaa
¡¡¡¡12 bbbbbbb
¡¡¡¡13 ccccccc
¡¡¡¡.................
¡¡¡¡rownum >10 ûÓмǼ£¬ÒòΪµÚÒ»Ìõ²»Âú×ãÈ¥µôµÄ»°£¬µÚ¶þÌõµÄROWNUMÓÖ³ÉÁË1£¬ËùÒÔÓÀԶûÓÐÂú×ãÌõ¼þµÄ¼Ç¼¡£»òÕß¿ÉÒÔÕâÑùÀí½â£º
¡¡¡¡ROWNUMÊÇÒ»¸öÐòÁУ¬ÊÇoracleÊý¾Ý¿â´ÓÊý¾ÝÎļþ»ò»º³åÇøÖжÁÈ¡Êý¾ÝµÄ˳Ðò¡£ËüÈ¡µÃµÚÒ»Ìõ¼Ç¼ÔòrownumֵΪ1£¬µÚ¶þÌõΪ2£¬ÒÀ´ÎÀàÍÆ¡£Èç¹ûÄãÓÃ>,>=,=,between...andÕâЩÌõ¼þ£¬ÒòΪ´Ó»º³åÇø»òÊý¾ÝÎļþÖеõ½µÄµÚÒ»Ìõ¼Ç¼µÄrownumΪ1£¬Ôò±»É¾³ý£¬½Ó×ÅÈ¡ÏÂÌõ£¬¿ÉÊÇËüµÄrownum»¹ÊÇ1£¬ÓÖ±»É¾³ý£¬ÒÀ´ÎÀàÍÆ£¬±ãûÓÐÁËÊý¾Ý¡£
¡¡¡¡ÓÐÁËÒÔÉÏ´Ó²»Í¬·½Ã潨Á¢ÆðÀ´µÄ¶Ô rownum µÄ¸ÅÄÄÇÎÒÃÇ¿ÉÒÔÀ´ÈÏʶʹÓà rownum µÄ¼¸ÖÖÏÖÏñ
¡¡¡¡1. select rownum,c1 from t1 where rownum != 10 ΪºÎÊÇ·µ»ØÇ°9ÌõÊý¾ÝÄØ£¿ËüÓë select rownum,c1 from tablename where rownum < 10 ·µ»ØµÄ½á¹û¼¯ÊÇÒ»ÑùµÄÄØ£¿
¡¡¡¡ÒòΪÊÇÔÚ²éѯµ½½á¹û¼¯ºó£¬ÏÔʾÍêµÚ 9 Ìõ¼Ç¼ºó£¬Ö®ºóµÄ¼Ç¼Ҳ¶¼ÊÇ != 10,»òÕß >=10,ËùÒÔÖ»ÏÔʾǰÃæ9Ìõ¼ÇÂ
Ïà¹ØÎĵµ£º
OracleÖ÷¼ü×Ô¶¯Ôö³¤
Õ⼸Ìì¸ãOracle£¬ÏëÈñíµÄÖ÷¼üʵÏÖ×Ô¶¯Ôö³¤£¬²éÍøÂçʵÏÖÈçÏ£º
create table simon_example
(
id number(4) not null primary key,
name varchar2(25)
)
-- ½¨Á¢ÐòÁУº
-- Create sequence
create sequence SIMON_SEQUENCE &nb ......
OracleµÄÍâ¼üÓÃÀ´ÏÞÖÆ×Ó±íÖвο¼µÄ×ֶεÄÖµ£¬±ØÐëÔÚÖ÷±íÖдæÔÚ¡£¶øÇÒÔÚÖ÷±íµÄ¼Ç¼·¢Éú±ä»¯µ¼ÖÂÍâ¼ü²Î¿¼Î¨Ò»Ô¼ÊøÖµ·¢ÉúÁ˱仯ʱ£¬¶¨ÒåÁËһϵÁеĶ¯×÷¡£
ÔÚSQL92±ê×¼Öж¨ÒåÁ˼¸ÖÖÍâ¼ü¸Ä±äºó£¬ÈçºÎ´¦Àí×Ó±í¼Ç¼µÄ¶¯×÷£¬ÆäÖаüÀ¨£º
ÏÞÖÆRestrict£ºÕâÖÖ·½Ê½²»ÔÊÐí¶Ô±»²Î¿¼µÄ¼Ç¼µÄ¼üÖµÖ´Ðиüлòɾ³ýµÄ²Ù×÷£»
ÖÃΪ¿ÕSet to nu ......
Ç°¼¸Ìì²Ù×÷Öз¢Ïֵģ¬Ò²²»ÖªµÀÊDz»ÊÇÎÒûÓиÄÅäÖû¹ÊÇÔõôµÄ£¬ÎÒ±¾È˵ÄÊý¾Ý¿â¾ÍÊÇĬÈÏ°²×°µÄ£¬È»ºó½«scottÓû§½âËøÁË£¬scottÓû§Ó¦¸ÃÊÇÆÕͨÓû§£¬¶ø²»ÊÇDBAÓû§¡£°´ÕÕ³£Àí·ÖÎö˵£¬ËûÓ¦¸ÃÊDz»ÊÇÄܹ»½øÈëϵͳ£¬Ò»°ãµÄʱºò£¬É趨ȨÏÞµÄʱºò¶¼»áÕâÑùÉè¡£
ÎÒ½«excelµÄÊý¾Ýµ¼ÈëoracleÖУ¬Ö´ÐеÄÈÕÖ¾Îļ ......
OracleµÄsql*plusÊÇÓëoracle½øÐн»»¥µÄ¿Í»§¶Ë¹¤¾ß¡£ÔÚsql*plusÖУ¬¿ÉÒÔÔËÐÐsql*plusÃüÁîÓësql*plusÓï¾ä¡£
¡¡¡¡
¡¡¡¡ÎÒÃÇͨ³£Ëù˵µÄDML¡¢DDL¡¢DCLÓï¾ä¶¼ÊÇsql*plusÓï¾ä£¬ËüÃÇÖ´ÐÐÍêºó£¬¶¼¿ÉÒÔ±£´æÔÚÒ»¸ö±»³ÆΪsql bufferµÄÄÚ´æÇøÓòÖУ¬²¢ÇÒÖ»Äܱ£´æÒ»Ìõ×î½üÖ´ÐеÄsqlÓï¾ä£¬ÎÒÃÇ¿ÉÒÔ¶Ô±£´æÔÚsql bufferÖеÄsql Óï¾ä½ø ......