ORACLE ORDER BYÓ÷¨×ܽá
½ñÌìÔÚ¹äÂÛ̳µÄʱºò¿´µ½shiyiwanͬѧдÁËÒ»¸öºÜ¼òµ¥µÄÓï¾ä£¬¿ÉÊÇorder byºóÃæµÄÐÎʽȴ±È½ÏÐÂÓ±£¨¶ÔÓÚÎÒÀ´ËµÅ¶£©£¬ÒÔÇ°´ÓÀ´Ã»¿´¹ýÕâÖÖÓ÷¨£¬¾ÍÏë¼ÇÏÂÀ´£¬ÕýºÃ×ܽáÒ»ÏÂORDER BYµÄ֪ʶ¡£
1¡¢ORDER BY ÖйØÓÚNULLµÄ´¦Àí
ȱʡ´¦Àí£¬OracleÔÚOrder by ʱÈÏΪnullÊÇ×î´óÖµ£¬ËùÒÔÈç¹ûÊÇASCÉýÐòÔòÅÅÔÚ×îºó£¬DESC½µÐòÔòÅÅÔÚ×îÇ°¡£
µ±È»£¬ÄãÒ²¿ÉÒÔʹÓÃnulls first »òÕßnulls last Óï·¨À´¿ØÖÆNULLµÄλÖá£
Nulls firstºÍnulls lastÊÇOracle Order byÖ§³ÖµÄÓï·¨
Èç¹ûOrder by ÖÐÖ¸¶¨Á˱í´ïʽNulls firstÔò±íʾnullÖµµÄ¼Ç¼½«ÅÅÔÚ×îÇ°(²»¹ÜÊÇasc »¹ÊÇ desc)
Èç¹ûOrder by ÖÐÖ¸¶¨Á˱í´ïʽNulls lastÔò±íʾnullÖµµÄ¼Ç¼½«ÅÅÔÚ×îºó (²»¹ÜÊÇasc »¹ÊÇ desc)
ʹÓÃÓï·¨ÈçÏ£º
--½«nullsʼÖÕ·ÅÔÚ×îÇ°
select * from zl_cbqc order by cb_ld nulls first
--½«nullsʼÖÕ·ÅÔÚ×îºó
select * from zl_cbqc order by cb_ld desc nulls last
2¡¢¼¸ÖÖÅÅÐòµÄд·¨
µ¥ÁÐÉýÐò£ºselect<column_name> from <table_name> order by <column_name>; £¨Ä¬ÈÏÉýÐò£¬¼´Ê¹²»Ð´ASC£©
µ¥ÁнµÐò£ºselect <column_name> from <table_name> order by <column_name> desc;
¶àÁÐÉýÐò£ºselect <column_one>, <column_two> from <table_name> order by <column_one>, <column_two>;
¶àÁнµÐò£ºselect <column_one>, <column_two> from <table_name> order by <column_one> desc, <column_two> desc;
¶àÁлìºÏÅÅÐò£ºselect <column_one>, <column_two> from <table_name> order by <column_one> desc, <column_two> asc;
3¡¢½ñÌì¿´µ½µÄÐÂд·¨
SQL> select * from tb;
BLOGID BLOGCLASS
---------- ------------------------------
1 ÈËÉú
2 ѧϰ
3 ¹¤×÷
5 ÅóÓÑ
SQL> select * from tb order by decode(blogid,3,1,2), blogid;
BLOGID BLOGCLASS
---------- ------------------------------
3 ¹¤×÷
1 ÈËÉú
2 ѧϰ
5 ÅóÓÑ
ÎÒËù˵µÄ¾ÍÊÇÉÏÃæºìÉ«µ
Ïà¹ØÎĵµ£º
Ŀ¼
==================================================================
1.´ø¿ÕÖµµÄÅÅÁÐ
2.Top/Bottom N²éѯ
3.First/LastÅÅÃû²éѯ
4.°´²ã´Î²éѯ
Ò»¡¢´ø¿ÕÖµµÄÅÅÁУº
¼ÙÈç±»ÅÅÁеÄÊý¾ÝÖк¬ÓпÕÖµÄØ£¿
SQL> select region_id, customer_id,
2 ......
oracleÖÐÁ¬½ÓÓë»á»°²»ÊÇÒ»¸ö¸ÅÄî!!!
ÔÚOracleÖУ¬Á¬½ÓÖ»ÊÇ¿Í»§½ø³ÌºÍÊý¾Ý¿âʵÀýÖ®¼äµÄÒ»ÌõÌØÊâÏß·£¬×î³£¼ûµÄ¾ÍÊÇÍøÂçÁ¬½Ó¡£ÕâÌõÁ¬½Ó¿ÉÄÜÁ¬½Óµ½Ò»¸öרÓ÷þÎñÆ÷½ø³Ì£¬Ò²¿ÉÄÜÁ¬½Óµ½µ÷¶ÈÆ÷¡£ÈçÇ°ËùÊö£¬Á¬½ÓÉÏ¿ÉÒÔÓÐ0¸ö»ò¶à¸ö»á»°£¬Õâ˵Ã÷¿ÉÒÔÓÐÁ¬½Ó¶øÎÞÏàÓ¦µÄ»á»°¡£ÁíÍ⣬һ¸ö»á»°¿ÉÒÔÓÐÁ¬½ÓÒ²¿ÉÒÔûÓÐÁ¬½Ó¡£Ê¹Óø߼¶Oracle N ......
½ñÌìÒ»¸öÅóÓÑÔÚÎʹØÓÚ´´½¨ÊÓͼʱºòWITH CHECK OPTIONÊÇʲôÒâ˼£¬ÎÒµ±Ê±Ò²Ã»¶àÏ룬¾Í±È½ÏÁýͳµÄ»Ø´ðÁËһϡ£ºóÀ´×Ô¼ºÏëÁËÏ룬ºÃÏñ×Ô¼ºÒ²¼Ç²»Ì«Çå³þÁË£¬ÄÔ×ÓÀïÖ»Óиö´ó¸ÅµÄÓ¡Ïó¡£
ºÃÁË»°²»¶à˵£¬ÏÂÃ滹ÊÇͨ¹ýʵÑéÀ´¿´Ò»Ï°ɡ£
C:\Documents and Settings\Admin>sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Product ......
ÔÚOracleÖпÉÒÔ´´½¨×éºÏË÷Òý£¬¼´Í¬Ê±°üº¬Á½¸ö»òÁ½¸öÒÔÉÏÁеÄË÷Òý¡£ÔÚ×éºÏË÷ÒýµÄʹÓ÷½Ã棬OracleÓÐÒÔÏÂÌص㣺
1¡¢ µ±Ê¹ÓûùÓÚ¹æÔòµÄÓÅ»¯Æ÷£¨RBO£©Ê±£¬Ö»Óе±×éºÏË÷ÒýµÄÇ°µ¼ÁгöÏÖÔÚSQLÓï¾äµÄwhere×Ó¾äÖÐʱ£¬²Å»áʹÓõ½¸ÃË÷Òý£»
2¡¢ ÔÚʹÓÃOracle9i֮ǰµÄ»ùÓڳɱ¾µÄÓÅ»¯Æ÷£¨CBO£©Ê± ......
ÔÚÊý¾Ý¿âδÆô¶¯Ö®Ç°µÇ½´Ó¶øÆô¶¯Êý¾Ý¿âÈç¹ûûÓпÚÁîÎļþ£¬ÔÚÊý¾Ý¿âδÆô¶¯Ö®Ç°¾ÍÖ»ÄÜͨ¹ý²Ù×÷ϵͳÈÏÖ¤.ʹÓÃRman£¬ºÜ¶àʱºòÐèÒªÔÚnomount,mountµÈ״̬¶ÔÊý¾Ý¿â½øÐд¦Àí¡£ËùÒÔͨ³£ÒªÇósysdbaȨÏÞÈç¹ûÊôÓÚ±¾µØDBA×飬¿ÉÒÔͨ¹ý²Ù×÷ϵͳÈÏÖ¤µÇ½Èç¹ûÊÇÔ¶³ÌsysdbaµÇ½£¬ÐèҪͨ¹ýpasswordfileÈÏÖ¤¡£
1.remote_login_passwordfile ......