Oracle²ã´Î²éѯºÍ·ÖÎöº¯ÊýÔںŶÎѡȡÖеÄÓ¦ÓÃ
Oracle²ã´Î²éѯºÍ·ÖÎöº¯ÊýÔںŶÎѡȡÖеÄÓ¦ÓÃ
ÕªÒª
Ò»×éÁ¬ÐøµÄÊý£¬È¥µôÖмäһЩÊý£¬ÈçºÎÇó³öʣϵÄÊýµÄÇø¼ä£¨¼´ºÅ¶Î£©£¿ÖªµÀºÅ¶ÎµÄÆðÖ¹£¬ÈçºÎÇó³ö¸ÃºÅ¶ÎÄÚËùÓеÄÊý£¿ÖªµÀÒ»¸ö´óµÄºÅ¶Î·¶Î§ºÍÒѾȡ¹ýµÄºÅ¶Î£¬ÈçºÎÇó³ö¿ÉÓõĺŶΣ¿ÀûÓÃOracleÌṩµÄÇ¿´óµÄ²éѯ¹¦ÄÜÒÔ¼°·ÖÎöº¯Êý£¬ÎÒÃÇ¿ÉÒÔºÜÇáËɵĽâ¾öÉÏÊöÎÊÌâ¡£
¹Ø¼ü´Ê£º
ºÅ¶Îѡȡ¡¢Á¬ÐøÊý¡¢¶Ïµã¡¢²ã´Î²éѯ¡¢·ÖÎöº¯Êý¡¢connect by¡¢rownum¡¢level¡¢lead¡¢lag
1. ÎÊÌâµÄÌá³ö
ÔÚʵ¼Ê¹¤×÷ÖУ¬ÎÒÃdz£³£»áÅöµ½ºÅ¶ÎѡȡµÄÎÊÌ⣬ÀýÈ磺
Ò»×éÁ¬ÐøµÄÊý£¬È¥µôÖмäһЩÊý£¬ÒªÇó³öʣϵÄÊýµÄÇø¼ä£¨¼´ºÅ¶Î£©
ÀýÈ磺һ´®Êý×ÖΪ1,2,3,4,7,9,10£¬ÔòºÅ¶ÎΪ1-4,7-7,9-10
ÖªµÀºÅ¶ÎµÄÆðÖ¹£¬ÒªÇó³ö¸ÃºÅ¶ÎÄÚËùÓеÄÊý
ÀýÈ磺ºÅ¶ÎΪ1-3,15-15£¬ÔòºÅ¶ÎÄÚËùÓеÄÊýΪ1,2,3,15
Ò»×éÊý£¬Öмä¿ÉÄÜÓжϵ㣬ҪÇó³öȱʧµÄÊý
ÀýÈ磺һ´®Êý×ÖΪ1,2,3,4,7,9,10£¬ÔòȱʧµÄÊýΪ5,6,8
ÒÑÖª´óºÅ¶Î·¶Î§¼°ÒÑÓúŶη¶Î§£¬Çó¿ÉÓúŶη¶Î§
ÀýÈ磺´óºÅ¶Î·¶Î§0-999,ÒÑÓúŶη¶Î§0-200,399-599£¬Ôò¿ÉÓúŶη¶Î§Îª201-398,600-999
2. »ù´¡ÖªÊ¶
ÏÈ×öÏÂÈÈÉíÔ˶¯£¬»Ø¹Ëһϲã´Î²éѯºÍlead£¯lagº¯ÊýµÄÔËÓá£
2.1 αÁÐrownumºÍlevel
αÁоÍÊDz¢·ÇÔÚ±íÖÐÕæÕý´æÔÚµÄÁС£ÒÑÓкܶà×ÊÁϽéÉÜrownumºÍlevelÕâÁ½¸öαÁС£ÕâÀïÖ»ÏëÇ¿µ÷Ò»µã£¬Î±ÁÐÊÇÖ»Õë¶Ô½á¹û¼¯µÄ¡£
2.2 ÀûÓòã´Î²éѯ¹¹ÔìÁ¬ÐøµÄÊý
²úÉú5¡«8Õâ4¸öÁ¬ÐøµÄÊý
PHP code:
select * from (select rownum+4 from dual connect by rownum<5);
select * from (select level+4 from dual connect by level<5);
........
ÒÔ8ÔÂΪ½ç£¬ÀýÈç2005Äê8ÔÂ1ÈÕ£¬Ö®Ç°µÄÔÚУѧÉúÈëѧÄê·ÝΪ2001¡«2004£¬Ö®ºóµÄΪ2002¡«2005¡£Çóµ±Ç°ÈÕÆÚϵÄÔÚУѧÉúÈëѧÄê·Ý£º
PHP code:
select * from (select to_char(add_months(sysdate, 4), 'yyyy') - rownum from dual connect by rownum<
Ïà¹ØÎĵµ£º
²©ÑåÅàѵ²¿ÊÇĿǰ¹úÄÚΨһµÄ Oracle ¹Ù·½ÊÚȨ ERP ÈÏÖ¤Åàѵ»ú¹¹
Ŀǰ£¬Oracle Ó¦ÓÃϵͳÔÚÈ«Çò¿ç¹ú¹«Ë¾µÃµ½¹ã·ºÓ¦Óã¬ÖîÈçÖйúÒÆ¶¯¡¢ÉîÛÚ»ªÎª¡¢»ôÄáΤ¶û¡¢¿µÃ÷˹Öйú¡¢ÃÀ¹úÂÁÒµ¡¢DHL ºÍ±¦ÐÅÈí¼þµÈÖªÃû¹«Ë¾¡£Îª´Ë£¬Oracle ×Éѯ¹ËÎÊÊÇÈ«ÇòºÍÖйúÊг¡ÉÏ×î½ôȱµÄÈ˲ÅÖ®Ò»¡£Í¨¹ýOracle ÉÌÎñÌ×¼þÈÏÖ¤µÄ×Éѯ¹ËÎ ......
select nvl2(replace(translate('69584.00.00','.0123456789','000000000000'),'0',''),'·ñ','ÊÇ') IsNumber from dual;
select id,nvl2(replace(translate(id,'.0123456789','000000000000'),'0',''),'·ñ','ÊÇ') IsNumber
from tbl2 ......
Æô¶¯¸÷¸öģʽµÄ¹ý³Ì£º
1.nomount ----¶Á²ÎÊýÎļþ---À©ÄÚ´æ/Æô½ø³Ì£¨Ö÷ÒªÊÇÖØ½¨¿ØÖÆÎļþ£©
2.mount ------¶Á²ÎÊýÎļþ---ÕÒ¿ØÖÆÎļþ---¿ª¿ØÖÆÎļþ---ÕÒÊý¾ÝÎļþ/ÈÕÖ¾ÎļþλÖÃÓëÃû³Æ---ÁªÏµÊµÀýÓëÊý¾Ý¿â
£¨Ö÷ÒªÊǻָ´Êý¾Ý¿â£©
3.open--------´ò¿ªÊý¾ÝÎļþ---´ò¿ªÈÕÖ¾Îļþ ......
ÔÚ$ORACLE_HOME/sqlplus/admin/login.sql (»òÕßÊÇglogin.sql)ÖÐÌí¼Ó£º
set termout off
COLUMN prompter new_value m_prompt
select host_name || ':' || instance_name ||' >' prompter
from sys.v_$insta ......