ORACLE GROUPING_IDº¯Êý
¿ÉÒÔʹÓÃGROUPING_IDº¯Êý½èÖúHAVING×Ó¾ä¶Ô¼Ç¼½øÐйýÂË£¬½«²»°üº¬Ð¡¼Æ»òÕß×ܼƵļǼ³ýÈ¥¡£GROUPING_ID()º¯Êý¿ÉÒÔ½ÓÊÜÒ»Áлò¶àÁУ¬·µ»ØGROUPINGλÏòÁ¿µÄÊ®½øÖÆÖµ¡£GROUPINGλÏòÁ¿µÄ¼ÆËã·½·¨Êǽ«°´ÕÕ˳Ðò¶ÔÿһÁе÷ÓÃGROUPINGº¯ÊýµÄ½á¹û×éºÏÆðÀ´¡£
¹ØÓÚGROUPINGº¯ÊýµÄʹÓ÷½·¨¿ÉÒԲμûÎÒÇ°ÃæÐ´µÄһƪÎÄÕÂ
http://blog.csdn.net/wh62592855/archive/2009/11/16/4818072.aspx
1¡¢GROUPING_IDÓ÷¨ÊµÀý
SQL> select
2 division_id,job_id,
3 grouping(division_id) as div_grp,
4 grouping(job_id) as job_grp,
5 grouping_id(division_id,job_id) as grp_id,
6 sum(salary)
7 from employees2
8 group by cube(division_id,job_id)
9 order by division_id,job_id;
DIV JOB DIV_GRP JOB_GRP GRP_ID SUM(SALARY)
--- --- ---------- ---------- ---------- -----------
BUS MGR 0 0 0 530000
BUS PRE 0 0 0 800000
BUS WOR 0 0 0 280000
BUS 0 1 1 1610000
OPE ENG 0 0 0 245000
OPE MGR &nbs
Ïà¹ØÎĵµ£º
½ñÌìÔÚ¹äÂÛ̳µÄʱºò¿´µ½shiyiwanͬѧдÁËÒ»¸öºÜ¼òµ¥µÄÓï¾ä£¬¿ÉÊÇorder byºóÃæµÄÐÎʽȴ±È½ÏÐÂÓ±£¨¶ÔÓÚÎÒÀ´ËµÅ¶£©£¬ÒÔǰ´ÓÀ´Ã»¿´¹ýÕâÖÖÓ÷¨£¬¾ÍÏë¼ÇÏÂÀ´£¬ÕýºÃ×ܽáÒ»ÏÂORDER BYµÄ֪ʶ¡£
1¡¢ORDER BY ÖйØÓÚNULLµÄ´¦Àí
ȱʡ´¦Àí£¬OracleÔÚOrder by ʱÈÏΪnullÊÇ×î´óÖµ£¬ËùÒÔÈç¹ûÊÇASCÉýÐòÔòÅÅÔÚ×îºó£¬DESC½µÐòÔòÅÅÔÚ×îǰ¡£
......
2.¸ù¾ÝOracle Êý¾Ý¿âscott ģʽϵÄemp ±íºÍdept ±í£¬Íê³ÉÏÂÁвÙ×÷£º
(1) ²éѯ20ºÅ²¿ÃŵÄËùÓÐÔ±¹¤ÐÅÏ¢£»
(2) ²éѯËùÓй¤ÖÖΪCLERK µÄÔ±¹¤µÄÔ±¹¤ºÅ¡¢Ô±¹¤ÃûºÍ²¿Ãźţ»
(3) ²éѯ½±½ðCOMM ¸ßÓÚ¹¤×ÊSAL µÄÔ±¹¤ÐÅÏ¢£»
  ......
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
¸ø³öÕûÊý,·µ»Ø¶ÔÓ¦µÄ×Ö·û;
SQL> select chr(54740) zhao,chr(65) chr65 from ......
oracleµÄ·ÖÎöº¯Êýover ¼°¿ª´°º¯Êý
Ò»£º·ÖÎöº¯Êýover
Oracle´Ó8.1.6¿ªÊ¼Ìṩ·ÖÎöº¯Êý£¬·ÖÎöº¯ÊýÓÃÓÚ¼ÆËã»ùÓÚ×éµÄijÖÖ¾ÛºÏÖµ£¬ËüºÍ¾ÛºÏº¯ÊýµÄ²»Í¬Ö®´¦ÊÇ
¶ÔÓÚÿ¸ö×é·µ»Ø¶àÐУ¬¶ø¾ÛºÏº¯Êý¶ÔÓÚÿ¸ö×éÖ»·µ»ØÒ»ÐС£
ÏÂÃæÍ¨¹ý¼¸¸öÀý×ÓÀ´ËµÃ÷ÆäÓ¦Óᣠ&nb ......
¡¡¡¡decode()º¯ÊýÊÇORACLE PL/SQLÊǹ¦ÄÜÇ¿´óµÄº¯ÊýÖ®Ò»£¬Ä¿Ç°»¹Ö»ÓÐORACLE¹«Ë¾µÄSQLÌṩÁ˴˺¯Êý£¬ÆäËûÊý¾Ý¿â³§É̵ÄSQLʵÏÖ»¹Ã»Óд˹¦ÄÜ¡£
DECODEº¯ÊýÊÇORACLE PL/SQLÊǹ¦ÄÜÇ¿´óµÄº¯ÊýÖ®Ò»£¬Ä¿Ç°»¹Ö»ÓÐORACLE¹«Ë¾µÄSQLÌṩÁ˴˺¯Êý£¬ÆäËûÊý¾Ý¿â³§É̵ÄSQLʵÏÖ»¹Ã»Óд˹¦ÄÜ¡£DECODEÓÐÊ²Ã´Ó ......