t_xiaoxi±íÓÐ70000¶àÌõ¼Ç¼¡£
¸öÈ˸оõ1µÄЧÂÊ×îºÃ£¬3´ÎÖ®£¬2×î²î¡£
//²âÊÔͨ¹ýµÄ·ÖÒ³²éѯokokok
select * from (select a1.*, rownum rn from(select ename,job from emp) a1 where rownum<=10)where rn>=5;
ÏÂÃæ×îÖ÷Òª½éÉܵÚÈýÖÖ£º°´rownumÀ´·Ö 1. rownum ·ÖÒ³
SELECT * FROM emp; 2. ÏÔʾrownum[oracle·ÖÅäµÄ]
SELECT e.*, ROWNUM rn FROM (SELECT * FROM emp) e; rnÏ൱ÓÚOracle·ÖÅäµÄÐеÄIDºÅ 3.ÌôÑ¡³ö6¡ª10Ìõ¼Ç¼ ÏȲé³ö1-10Ìõ¼Ç¼
SELECT e.*, ROWNUM rn FROM (SELECT * FROM emp) e WHERE ROWNUM <= 10; Èç¹ûºóÃæ¼ÓÉÏrownum>=6ÊDz»Ðеģ¬ 4. È»ºó²é³ö6-10Ìõ¼Ç¼
SELECT * FROM (SELECT e.*, ROWNUM rn FROM (SELECT * FROM emp) e WHERE ROWNUM <= 10) WHERE rn >= 6; 5. ¼¸¸ö²éѯ±ä»¯
a. Ö¸¶¨²éѯÁУ¬Ö»ÐèÒªÐÞ¸Ä×îÀï²ãµÄ×Ó²éѯ Ö»²éѯ¹ÍÔ±µÄ±àºÅºÍ¹¤×Ê
SELECT * FROM (SELECT e.*, ROWNUM rn FROM (SELECT ename, sal FROM emp) e WHERE ROWNUM <= 10) WHERE rn >= 6; b. ÅÅÐò²éѯ£¬Ö»ÐèÒªÐÞ¸Ä×îÀï²ãµÄ×Ó²éѯ ¹¤×ÊÅÅÐòºó²éѯ6-10ÌõÊý¾Ý
SELECT * FROM (SELECT e.*, ROWNUM rn FROM (SELECT ename, sal FROM emp ORDER by sal) e WHERE ROWNUM <= 10) WHERE rn >= 6;
Óòéѯ½á¹û´´½¨Ð±í
Õâ¸öÃüÁîÊÇÒ»ÖÖ¿ì½ÝµÄ½¨±í·½Ê½
CREATE TABLE mytable (id, name, sal, job, deptno) as SELECT empno, ename, sal, job, deptno FROM emp;
´´½¨ºÃÖ®ºó£¬desc mytable£»ºÍselect * from mytable;¿´¿´½á¹ûÈçºÎ£¿
ºÏ²¢²éѯ ºÏ²¢²éѯ
ÓÐʱÔÚʵ¼ÊÓ¦ÓÃÖУ¬ÎªÁ˺ϲ¢¶à¸öselectÓï¾äµÄ½á¹û£¬¿ÉÒÔʹÓü¯ºÏ²Ù×÷·ûºÅunion£¬union all£¬intersect£¬minus
¶àÓÃÓÚÊý¾ÝÁ¿±È½Ï´óµÄÊý¾Ý¾Ö¿â£¬ÔËÐÐËٶȿ졣 1). union
¸Ã²Ù×÷·ûÓÃÓÚÈ¡µÃÁ½¸ö½á¹û¼¯µÄ²¢¼¯¡£µ±Ê¹ÓøòÙ×÷·ûʱ£¬»á×Ô¶¯È¥µô½á¹û¼¯ÖÐÖظ´ÐС£ SELECT ename, sal, job FROM emp WHERE sal >2500
UNION
SELECT ename, sal, job FROM emp WHERE job = 'MANAGER'; 2).union all
¸Ã²Ù×÷·ûÓëunionÏàËÆ£¬µ«ÊÇËü²»»áÈ¡ÏûÖظ´ÐУ¬¶øÇÒ²»»áÅÅÐò¡£ SELECT ename, sal, job FROM emp WHERE sal >2500 UNION ALL
SELECT ename, sal, job FROM emp WHERE job = 'MANAGER';
¸Ã²Ù×÷·ûÓÃÓÚÈ¡µÃÁ½¸ö½á¹û¼¯µÄ²¢¼¯¡£µ±Ê¹ÓøòÙ×÷·ûʱ£¬»á×Ô¶¯È¥µô½á¹û¼¯ÖÐÖظ´ÐС£ 3). intersect
ʹÓøòÙ×÷·ûÓÃÓÚÈ¡µÃÁ½¸ö½á¹û¼¯µÄ½»¼¯¡£
SELECT ename, sal, job FROM emp WHERE sal >2500 INTERSECT
SELECT ename, sal, job FROM emp WHERE job = 'MANAGER'; 4). minus
ʹÓøIJÙ×÷·ûÓÃÓÚÈ¡µÃÁ½¸ö½á¹û¼¯µÄ²î¼¯£¬ËûÖ»»áÏÔʾ´æÔÚµÚÒ»¸ö¼¯ºÏÖУ¬¶ø²»´æÔÚµÚ¶þ¸ö¼¯ºÏÖеÄÊý¾Ý¡£
SELECT ename, sal, job FROM emp WHERE sal >2500 MINUS
SELECT ename, sal, job FROM emp WHERE job = 'MANAGER'; £¨MINUS¾ÍÊǼõ·¨µÄÒâ˼£©
´´½¨Êý¾Ý¿âÓÐÁ½ÖÖ·½·¨£º
1). ͨ¹ýoracleÌṩµÄÏòµ¼¹¤¾ß¡£¡Ì
database Configuration Assistant ¡¾Êý¾Ý¿âÅäÖÃÖúÊÖ¡¿ 2).ÎÒÃÇ¿ÉÒÔÓÃÊÖ¹¤²½ÖèÖ±½Ó´´½¨¡£
Æߣºjava²Ù×÷oracle
javaÁ¬½Óoracle
½éÉÜ£ºÇ°ÃæÎÒÃÇÒ»Ö±ÔÚplsqlÖвÙ×÷oracle£¬ÄÇôÈçºÎÔÚjava ³ÌÐòÖвÙ×÷Êý¾Ý¿âÄØ£¿ ÏÂÃæÎÒÃǾÙÀý˵Ã÷£¬Ð´Ò»¸öjava£¬·ÖÒ³ÏÔʾemp±íµÄÓû§ÐÅÏ¢¡£ Java´úÂë
1. package com.sp; 2.
3. import java.sql.Connection; 4. import java.sql.DriverManager; 5. import java.sql.ResultSet; 6. import java.sql.Statement; 7.
8. //ÑÝʾ ÈçºÎʹÓà jdbc_odbcÇÅÁ¬½Ó·½Ê½ 9. public class TestOracle { 10.
11. public static void main(String[] args) {
12. try { 13.
14. // 1.¼ÓÔØÇý¶¯
15. Class.forName(\iver\ 16.
17. // 2.µÃµ½Á¬½Ó
18. Connection ct = DriverManager.getConnection(
19. \racle\\ 20.
21.\ 22.
23. // ´ÓÏÂÃ濪ʼ£¬ºÍSQL ServerһģһÑù
24. Statement sm = ct.createStatement();
25. ResultSet rs = sm.executeQuery(\ct * from emp\
26. while (rs.next()) { 27. //̞
28. System.out.println(\Óû§Ãû£º \2));
29. //ĬÈÏÊÇ´Ó1¿ªÊ¼±àºÅµÄ 30. }
31. } catch (Exception e) { 32. e.printStackTrace(); 33. } 34. } 35.}
Ôڵõ½Á¬½ÓÄÇÀҪȥÅäÖÃÊý¾ÝÔ´£¬µã»÷¿ØÖÆÃæ°å-->ϵͳºÍ°²È«-->¹ÜÀí¹¤¾ß-->Êý¾ÝÔ´(ODBC),´ò¿ªºóµãÌí¼Ó,Èçͼ£º ¿ÉÒÔ¿´µ½£¬ÓиöOracle in OraDb10g_home1µÄÇý¶¯£¬ËüÊÇOracle°²×°Íêºó×Ô¶¯¼ÓÉÏÈ¥µÄ¡£ Ñ¡Öк󣬵ãÍê³É£¬ÔÙÌîÈçÏÂÐÅÏ¢,Èçͼ£º
ÕâÑùÅäºÃºó»ù±¾¾Í¿ÉÒÔÁË£¬µ«ÎªÁË°²È«Æð¼û£¬½¨Òé´ó¼Ò²âÊÔһϣ¬µã»÷ Test Connection°´Å¥£¬ ²âÊÔͨ¹ýºóµãok,È»ºóÊý¾ÝÔ´¾ÍÉú³ÉÁË£¬Èçͼ£º
È»ºó°ÑÊý¾ÝÔ´Ãû³Æд½øjdbc.odbc:Àï¡£
ÕâÀïҪעÒ⣺jdbcodbcÄܲ»ÄÜÔ¶³ÌÁ¬½ÓÄØ£¿²»ÄÜÔ¶³ÌÁ¬½Ó£¬Ò²¾ÍÊÇÄãÕâÑùдµÄ»°¾ÍÒâζ×Åjava³ÌÐòºÍoracleÊý¾Ý¿âÓ¦¸ÃÊÇÔÚͬһ̨»úÆ÷ÉÏ£¬ÒòΪÕâÀïûÓÐÖ¸¶¨IPµØÖ·£¬¿Ï¶¨Ä¬ÈϾÍÊDZ¾µØ¡£Èç¹ûÒªÔ¶³ÌÁ¬£¬¾ÍÓÃjdbc,jdbcÊÇ¿ÉÒÔÔ¶³ÌÁ¬µÄ¡£
ÔËÐÐTestOracle.java,¿ØÖÆ̨Êä³ö.......................
¿ÉϧÎÒûÔËÐгɹ¦£¬Ëµ
java.sql.SQLException: No suitable driver found for jdbc.odbc:testConnectOracle
at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.sp.TestOracle.main(TestOracle.java:18) ²»ÖªµÀΪʲô¡£¡£¡£
½ÓÏÂÀ´½²½âÓÃJDBCµÄ·½Ê½Á¬½ÓOracle Java´úÂë
1. package com.sp; 2.
3. import java.sql.Connection; 4. import java.sql.DriverManager; 5. import java.sql.ResultSet; 6. import java.sql.Statement; 7.
8. //ʹÓà jdbcÁ¬½Óoracle
9. public class TestOracle2 { 10.
11. public static void main(String[] args) { 12. try { 13.
14. // 1.¼ÓÔØÇý¶¯
15. Class.forName(\eDriver\ 16.
17. // 2.µÃµ½Á¬½Ó
18. Connection ct = DriverManager.getConnection 19.
20.(\\\ 21.
22. // ´ÓÏÂÃ濪ʼ£¬ºÍSQL ServerһģһÑù
23. Statement sm = ct.createStatement();
24. ResultSet rs = sm.executeQuery(\ct * from emp\
25. while (rs.next()) { 26. //̞
27. System.out.println(\Óû§Ãû£º \2));