OracleµÄrownumÔÀíºÍʹÓÃ
ÔÎijö×Ô£ºhttp://tenn.javaeye.com/blog/99339
ÔÚOracle
ÖУ¬Òª°´Ìض¨Ìõ¼þ²éѯǰNÌõ¼Ç¼£¬Óøörownum
¾Í¸ã¶¨ÁË¡£
select * from emp where rownum
<= 5
¶øÇÒÊéÉÏÒ²¸æ½ë£¬²»ÄܶÔrownum
ÓÃ">"£¬ÕâÒ²¾ÍÒâζ×Å£¬Èç¹ûÄãÏëÓÃ
select * from emp where rownum
> 5
ÔòÊÇʧ°ÜµÄ¡£ÒªÖªµÀΪʲô»áʧ°Ü£¬ÔòÐèÒªÁ˽ârownum
±³ºóµÄ»úÖÆ£º
1 Oracle
executes your query.
2 Oracle
fetches the first row and calls it row number 1.
3 Have we gotten past row number meets the criteria? If no, then Oracle
discards the row, If yes, thenOracle
return the row.
4 Oracle
fetches the next row and advances the row number (to 2, and then to 3, and then to 4, and so forth).
5 Go to step 3.
Á˽âÁËÔÀí£¬¾ÍÖªµÀrownum
>²»»á³É¹¦£¬ÒòΪÔÚµÚÈý²½µÄʱºò²éѯ³öµÄÐÐÒѾ±»¶ªÆú£¬µÚËIJ½²é³öÀ´µÄrownum
ÈÔÈ»ÊÇ1,ÕâÑùÓÀÔ¶Ò²²»»á³É¹¦¡£
ͬÑùµÀÀí£¬rownum
Èç¹ûµ¥¶ÀÓÃ=,Ò²Ö»ÓÐÔÚrownum
=1ʱ²ÅÓÐÓá£
¶ÔÓÚrownum
À´ËµËüÊÇoracle
ϵͳ˳Ðò·ÖÅäΪ´Ó²éѯ·µ»ØµÄÐеıàºÅ£¬·µ»ØµÄµÚÒ»ÐзÖÅäµÄÊÇ1£¬µÚ¶þÐÐÊÇ2£¬ÒÀ´ËÀàÍÆ£¬Õâ¸öα×ֶοÉÒÔÓÃÓÚÏÞÖƲéѯ·µ»ØµÄ×ÜÐÐÊý£¬¶øÇÒrownum
²»ÄÜÒÔÈκαíµÄÃû³Æ×÷Ϊǰ׺¡£
¾ÙÀý˵Ã÷£º
ÀýÈç±í£ºstudent(ѧÉú)±í£¬±í½á¹¹Îª£º
ID¡¡¡¡¡¡ char(6)¡¡¡¡¡¡¡¡¡¡ --ѧºÅ
name¡¡¡¡¡¡¡¡VARCHAR2(10)¡¡¡¡¡¡--ÐÕÃû create table student (ID char(6), name VARCHAR2(100));
insert into sale values('200001',‘ÕÅÒ»’);
insert into sale values('200002',‘Íõ¶þ’);
insert into sale values('200003',‘ÀîÈý’);
insert into sale values('200004',‘ÕÔËÄ’);
commit;
(1) rownum
¶ÔÓÚµÈÓÚijֵµÄ²éѯÌõ¼þ
Èç¹ûÏ£ÍûÕÒµ½Ñ§Éú±íÖеÚÒ»ÌõѧÉúµÄÐÅÏ¢£¬¿ÉÒÔʹÓÃrownum
=1×÷ΪÌõ¼þ¡£µ«ÊÇÏëÕÒµ½Ñ§Éú±íÖеڶþÌõѧÉúµÄÐÅÏ¢£¬Ê¹ÓÃrownum
=2½á¹û²é²»µ½Êý¾Ý¡£ÒòΪrownum
¶¼ÊÇ´Ó1¿ªÊ¼£¬µ«ÊÇ1ÒÔÉϵÄ×ÔÈ»ÊýÔÚrownum
×öµÈÓÚÅжÏÊÇʱÈÏΪ¶¼ÊÇfalseÌõ¼þ£¬ËùÒÔÎÞ·¨²éµ½rownum
= n£¨n>1µÄ×ÔÈ»Êý£©¡£
SQL> select rownum
,id,name from student where rownum
=1;£¨¿ÉÒÔÓÃÔÚÏ
Ïà¹ØÎĵµ£º
-- Create the user
create user SMCQUERY
identified by SMCQUERY;
-- Grant/Revoke role privileges
grant connect to SMCQUERY;
-- Grant/Revoke system privileges
grant select any table to SMCQUERY;
grant debug any procedure to SMCQUERY;
grant debug connect session to SMCQUERY;
grant cr ......
trunc()º¯ÊýÓÐÁ½ÖÖÓ÷¨ 1£ººóÃæ¸úÈÕÆÚ 2£º ºóÃæ¸úÊý×Ö
A£º SELECT a.times,to_date(a.times,'yyyymmdd'),trunc(to_date(a.times,'yyyymmdd'),'month') from dmf_loan_limit a
ÏÔʾµÄ½á¹ûΪ£º
1 20080131 2008-1-31 2008-1-1
2 20080131 &nb ......
http://mrhaozi.itpub.net/post/41048/495175
ÎﻯÊÓͼ
ÀûÓÃÇ¿ÖƲéѯÖØдºÍеÄÇ¿´óµÄµ÷Õû¹ËÎʳÌÐò — ËüÃÇʹÄú²»ÔÙÐèҪƾ²Â²â½øÐй¤×÷ — µÄÒýÈ룬ÔÚ 10g ÖйÜÀíÎﻯÊÓͼ±äµÃ¸ü¼ÓÈÝÒ×
ÎﻯÊÓͼ (MV) — Ò²³ÆΪ¿ìÕÕ — Ò»¶Îʱ¼äÀ´ÒѾ¹ã·ºÊ¹Óá£MV ÔÚÒ»¸ö¶ÎÖд洢²éѯ½á¹û£¬²¢ÇÒÄܹ»ÔÚÌá½»²éѯ ......
oracleÈÕÆÚº¯Êý£¬
TO_DATE¸ñʽ
¡¡¡¡Day:
¡¡¡¡dd number 12
¡¡¡¡dy abbreviated fri
¡¡¡¡day spelled out friday
¡¡¡¡ddspth spelled out, ordinal twelfth
¡¡¡¡Month:
¡¡¡¡mm number 03
¡¡¡¡mon abbreviated mar
¡¡¡¡month spelled out march
¡¡¡¡Year:
¡¡¡¡yy two ......
import Java.io.*;
¡¡¡¡import java.util.*;
¡¡¡¡import java.sql.*;
¡¡¡¡public class LobPros
¡¡¡¡{
¡¡¡¡/**
¡¡¡¡* OracleÇý¶¯³ÌÐò
¡¡¡¡*/
¡¡¡¡private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
¡¡¡¡/**
¡¡¡¡* ORACLEÁ¬½ÓÓÃURL
¡¡¡¡*/
¡¡¡¡p ......