DBMS_RANDOM.Random
hi,
i want to see all the options available in DBMS_RANDOM package.
like the same how can i see from DBMS_LOB,AND other dbms packages.
is there any dictionary is available.
please advice.
thanks
sivasankar.s
Everything you wanted to know about DBMS_XXXX packages...
http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/toc.htm
.... excerpt below....
DBMS_RANDOM
Using DBMS_RANDOM
Security Model
Operational Notes
Summary of DBMS_RANDOM Subprograms
INITIALIZE Procedure
NORMAL Function
RANDOM Procedure
SEED Procedures
STRING Function
TERMINATE Procedure
VALUE Functions Message was edited by:
Mark Reichman
Similar Messages
-
Role to run DBMS_RANDOM.RANDOM
What role should I grant a user to run:
Select DBMS_RANDOM.RANDOM from dual;Hi,
You should have Execute Privilege on that Package.
Thanks & Regards,
Pavan Kumar N -
(ORACLE8)DBMS_RANDOM PACKAGE를 이용하여 RANDOM NUMBER를 생성하는 방법
제품 : ORACLE SERVER
작성날짜 : 1999-03-04
(Oracle8)dbms_random package 를 이용하여 random number 를 생성하는 방법
=====================================================================
Oracle8 에서는 random number 를 생성하는 dbms_random package 를 제공한다.
이를 이용하여 random number 를 생성하는 방법을 알아본다.
1. sys user 로 접속하여 (또는 svrmgrl 에 connect internal) 다음의
script를 수행한다. script의 위치는 $ORACLE_HOME/rdbms/admin 이다.
dbmsoctk.sql, prvtoctk.plb, dbmsrand.sql
경우에 따라서는 utlraw.sql, prvtrawb.plb 를 먼저 수행해야 할 수도 있다.
2. random number generator 를 다음과 같이 초기화한다. randomness 를 보장
받기 위하여 seed 는 적어도 5 digits 이상으로 해야만 한다.
Example :
SQL> exec dbms_random.initialize (12345);
PL/SQL procedure successfully completed.
3. random number 를 생성한다.
Example 1 :
SQL> set serveroutput on
SQL> declare
2 random_number binary_integer;
3 begin
4 random_number := dbms_random.random;
5 dbms_output.put_line(to_char(random_number));
6 end;
7 /
2116177396
PL/SQL procedure successfully completed.
Example 2 :
DECLARE
i BINARY_INTEGER;
BEGIN
dbms_random.initialize(19254);
i := dbms_random.random;
INSERT INTO some_table VALUES(i);
dbms_random.terminate;
END;
4. memory 를 release 하기 위하여 random number generator 를 종료한다.
Example:
SQL> exec dbms_random.terminate;
PL/SQL procedure successfully completed.
5. random number generator 를 초기화한 이후에 seed 를 변경한다.
Example:
SQL> exec dbms_random.seed (12346);
PL/SQL procedure successfully completed.
6. 참고사항
a. dbms_random.terminate 을 이용하여 정상적으로 random number
generator 를 종료한 이후에 다시 dbms_random.random 를 수행하면
error 는 발생하지 않으나 값은 return 되지 않는다.
b. random 함수를 바로 SQL 문장에 사용할 수 없다.
Example:
SQL> exec dbms_random.initialize (12345);
PL/SQL procedure successfully completed.
SQL> insert into x values(dbms_random.random);
insert into x values(dbms_random.random)
ERROR at line 1:
ORA-06571: Function RANDOM does not guarantee
not to update the database. -
hallo,
i would like to know how DBMS_RANDOM package can be implemented.
can you please explain with example.
is there any other means of performimg random sampling?
thank you
regards,
raoHi
Desc DBMS_RANDOM;
PROCEDURE INITIALIZE
Názov argumentu Typ In/Out predvolene?
VAL BINARY_INTEGER IN
FUNCTION NORMAL RETURNS NUMBER
FUNCTION RANDOM RETURNS BINARY_INTEGER
PROCEDURE SEED
Názov argumentu Typ In/Out predvolene?
VAL BINARY_INTEGER IN
PROCEDURE SEED
Názov argumentu Typ In/Out predvolene?
VAL VARCHAR2 IN
FUNCTION STRING RETURNS VARCHAR2
Názov argumentu Typ In/Out predvolene?
OPT CHAR IN
LEN NUMBER IN
PROCEDURE TERMINATE
FUNCTION VALUE RETURNS NUMBER
FUNCTION VALUE RETURNS NUMBER
Názov argumentu Typ In/Out predvolene?
LOW NUMBER IN
HIGH NUMBER IN
Example in SQL+:
Exec DBMS_RANDOM.INITIALIZE(100);
SELECT DBMS_RANDOM.Normal
, DBMS_RANDOM.RANDOM
, DBMS_RANDOM.VALUE()
, DBMS_RANDOM.VALUE(10,100)
FROM DUAL;
milos -
SQL Query Result with Random Sorting
Hi Experts,
My Oracle Version : Oracle9i
I have three tables which are given below,
Table Name: check_team
team_id team_code
100 A
101 B
102 C
103 D
Table Name: check_product
product_id product_code
1 XXX
2 XYZ
Table Name: check_team_products
tprod_id tprod_team_id tprod_product_id
1 100 1
2 100 2
3 101 1
4 101 2
5 102 1
6 102 2
7 103 1
8 103 2
Required Output First Time:
team_id team_code product_id product_code
100 A 1 XXX
101 B 2 XYZ
102 A 1 XXX
103 B 2 XYZ
Required Output Second Time:
team_id team_code product_id product_code
100 B 2 XYZ
101 A 1 XXX
102 B 2 XYZ
103 A 1 XXXI need the result as Required Output specified above and also the result has to be random too.. Can someone help me in writing a SQL Query to get results as that?
Added Oracle VersionSo, is it something like this you want?
SQL> ed
Wrote file afiedt.buf
1 with check_team as (select 100 as team_id, 'A' as team_code from dual union all
2 select 101, 'B' from dual union all
3 select 102, 'C' from dual union all
4 select 103, 'D' from dual)
5 ,check_product as (select 1 as product_id, 'XXX' as product_code from dual union all
6 select 2, 'XYZ' from dual)
7 ,check_team_products as (select 1 as tprod_id, 100 as tprod_team_id, 1 as tprod_product_id from dual union all
8 select 2, 100, 2 from dual union all
9 select 3, 101, 1 from dual union all
10 select 4, 101, 2 from dual union all
11 select 5, 102, 1 from dual union all
12 select 6, 102, 2 from dual union all
13 select 7, 103, 1 from dual union all
14 select 8, 103, 2 from dual)
15 --
16 -- end of test data
17 --
18 select team_id, team_code, product_id, product_code
19 from (
20 select t.team_id, t.team_code, p.product_id, p.product_code
21 ,row_number() over (partition by team_id order by dbms_random.random()) as rn
22 from check_team t join check_team_products tp on (tp.tprod_team_id = t.team_id)
23 join check_product p on (p.product_id = tp.tprod_product_id)
24 )
25* where rn = 1
SQL> /
TEAM_ID T PRODUCT_ID PRO
100 A 2 XYZ
101 B 1 XXX
102 C 2 XYZ
103 D 1 XXX
SQL> /
TEAM_ID T PRODUCT_ID PRO
100 A 2 XYZ
101 B 1 XXX
102 C 2 XYZ
103 D 1 XXX
SQL> /
TEAM_ID T PRODUCT_ID PRO
100 A 1 XXX
101 B 2 XYZ
102 C 1 XXX
103 D 1 XXX -
I would like to return a number between 0-9999 through the dbms_random function. I am trying this:
exec dbms_random.initialize(1234);
select dbms_random.random from dual;
RANDOM
-3.10E+08
this is not what I am looking for. Anyone know how I can get the desired results I am looking for?SQL> SELECT DBMS_RANDOM.Value(0,9999) FROM dual;
DBMS_RANDOM.VALUE(0,9999)
2499.13527
SQL> /
DBMS_RANDOM.VALUE(0,9999)
6274.76354TTFN
John -
Could anyone please let me know how to use the dbms_random package?
I used DBMS_RANDOM in my procedure but I noticed that the random repeated a number. I think this is strange. I ran the code again and it worked well. Is it possible that the DBMS_RANDOM procedure may repeat a number. Below is the output screen and my code.
SQL> BEGIN
2 RANDOM_SAMPLING;
3 COMMIT;
4 END;
5 /
The Range numbers: 1350467 : 1350485
This is the range to insert: 1350480
This is the range to insert: 1350484
This is the range to insert: 1350484
PL/SQL procedure successfully completed.
M_num := 1350485 - 1350467+ 1;
WHILE COUNTER < MARK_20_PERCENT
LOOP
RANDNUM := mod(abs(dbms_random.random), M_NUM )+1350467;
DBMS_OUTPUT.PUT_LINE(' About to insert. This is the range to insert: '||RANDNUM);
INSERT INTO T
SELECT *
FROM b
WHERE T_KEY = RANDNUM;
COUNTER := COUNTER + 1;
END LOOP;
Edited by: user8738152 on May 27, 2011 12:10 PM -
No random command in Oracle PL/SQL ???????
Hi,
Is there command for random in PL/SQL ?
Thxs
Monica
nullThe following is an example of using dbms_random, simulating dice rolling.
declare
i integer;
s varchar2(200);
t varchar2(200);
begin
dbms_random.initialize(13);
--dbms_random.seed(13);
for i in 1..33 loop
s:=dbms_random.random;
s:=substr(s, length(s)-1, length(s)) mod 6 + 1;
t:=dbms_random.random;
t:=substr(t, length(t)-1, length(t)) mod 6 + 1;
if s>t then
dbms_output.put_line(s| |', '| |t);
else
dbms_output.put_line(t| |', '| |s);
end if;
end loop;
dbms_random.terminate;
end;
null -
How can I select random records from one column
How can I random select 400 records from a column contains more than 500,000 records? And how long will it take in oracle? Thanks.
here is one option: (just change 5 to suit your needs...)
SQL>select * from (
2 select object_name
3 from all_objects
4 order by dbms_random.random
5 ) where rownum < 5
6 /
OBJECT_NAME
UTL_SYS_COMPRESS
GV_$LOG_HISTORY
GV_$LOGMNR_LOGS
WWV_FLOW_THEME_7
SQL>/
OBJECT_NAME
WWV_FLOW_UPGRADE_REPORT
WRI$_ADV_SQLT_STATISTICS_PK
V_$DATABASE
GV_$SERVICEMETRIC
SQL>/
OBJECT_NAME
WWV_FLOW_CREATE_FLOW_API
WRH$_SERVICE_WAIT_CLASS_BL
EXU8SNAPL
GV$SERVICEMETRIC_HISTORY
SQL> well, regarding how long will it take... it depends from lots of variables...
Cheers,
Andrea -
Is there any way to do a SELECT from a table/view, and tell it to randomize the order the rows are returned in?
TIA -You can use the following technic:
select *
from emp a,
(select sys.dbms_random.random rnd,
eno
from emp) b
where a.eno=b.eno
order by b.rnd;
Best of Luck
Samujjwal Basu -
Hi ,
I have One table with 5 columns.It has 20,000 records.
FILE_TYPE item rev_number path part_type
FILE abc XYZ
FILE abc XYZ
FILE abc XYZ
FILE xyz XYZ
FILE xyz XYZ
FILE dfg XYZ
I want output like
FILE_TYPE item rev_number path part_type
FILE abc XYZ
FILE xyz XYZ
FILE abc XYZ
FILE xyz XYZ
FILE abc XYZ
FILE abc XYZ
I don't want item_numbers in consecutive order (like abc,abc,abc...,xyz,xyz).Item number can repeat any number of times(like 1 st table)
Thanks in Advance
LaxmanSELECT file_type, item, rev_number, path, part_type
FROM table
ORDER BY DBMS_RANDOM.RANDOM()No guarantees on performance for 20,000 rows.
John -
How to randomly select one of two rows?
I have a table from which I am selecting a husband and wife on separate rows. From each couple I want to select either the husband or the wife.
I had faulty logic like the below:
select * from
(select row_number() OVER (partition by s.case_id order by n.date_created) rn,s.case_id scase_id,first_name,last_name
from couples) x,
(select abs(mod(dbms_random.random(),2))+1 randrow from dual) y
WHERE y.randrow = x.rnwhich doesn't work because there is a separate random number for each row, so you could end up with (for example)
RN randnum
1 2
2 1
and get a NULL set.
There must be a way to generate a single random number per case_id, but I'm having trouble thinking how to do it.
Thanks,
Jonwith couples as (select 1 as case_id
,'Sam' as first_name
,'Bachour' as last_name
from dual
union all
select 1 as case_id
,'Jennifer' as first_name
,'Hawkins' as last_name
from dual
union all
select 2 as case_id
,'John' as first_name
,'Smith' as last_name
from dual
union all
select 2 as case_id
,'Nancy' as first_name
,'Smith' as last_name
from dual)
select *
from
(select row_number() over (partition by case_id order by dbms_random.random) rn
,case_id
,first_name
,last_name
from couples)
where rn = 1 -
dear friends,
please tell me how to generate random password using empno from emp table both from frontend forms and through plsql.Look at this.. I wrote this to generate password for one of the jobs that we run every 90 days..
CREATE OR REPLACE procedure GENERATE_RANDOM
IS
cursor c1 is
select username
from password_age where FLAG='Y';
V_Random_number binary_integer;
V_Prefix varchar2(4);
V_Password varchar2(9);
begin
FOR crec IN c1
LOOP
V_Random_number := dbms_random.random;
V_Password := substr(to_char(abs(V_Random_number)),1,5);
V_Prefix := substr(to_char(sysdate,'DAY'),2,1)||to_char(add_months(sysdate,substr(V_Random_number,2,3)),'MON');
Update password_age set passwd = V_Prefix||V_Password where username = crec.username;
commit;
END LOOP;
end;
/ -
Query to return list of all missing primary key ids from table T1
I found this query online that returns a start and stop for a range of all missing primary key id values from table T1. However i want to rewrite this query to return a whole list of all the missing primary key ids and not a start and stop range. any help plz?
select strt, stp
from (select m.id + 1 as strt,
(select min(id) - 1 from T1 x where x.id > m.id) as stp
from T1 m left outer join T1 r on m.id = r.id - 1 where r.id is null)x where stp is not nullwith t as
select 1 as id from dual union all
select 2 as id from dual union all
select 3 as id from dual union all
select 5 as id from dual union all
select 8 as id from dual union all
select 10 as id from dual union all
select 11 as id from dual union all
select 20 as id from dual
select id_start + level missing_id
from (
select id id_start,
nullif(lead(id) over(order by id) - 1, id) id_end
from t
start with id_end is not null
connect by prior id_start = id_start
and prior dbms_random.random is not null
and level <= id_end - id_start
MISSING_ID
4
6
7
9
12
13
14
15
16
17
18
MISSING_ID
19
12 rows selected.Or:
with t as
select 1 as id from dual union all
select 2 as id from dual union all
select 3 as id from dual union all
select 5 as id from dual union all
select 8 as id from dual union all
select 10 as id from dual union all
select 11 as id from dual union all
select 20 as id from dual
select id_start + level - 1 missing_id
from (
select min(id) id_start,
max(id) id_end
from t
connect by level <= id_end - id_start
minus
select id
from t
MISSING_ID
4
6
7
9
12
13
14
15
16
17
18
MISSING_ID
19
12 rows selected.SY. -
Pagination query help needed for large table - force a different index
I'm using a slight modification of the pagination query from over at Ask Tom's: [http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html]
Mine looks like this when fetching the first 100 rows of all members with last name Smith, ordered by join date:
SELECT members.*
FROM members,
SELECT RID, rownum rnum
FROM
SELECT rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
WHERE rownum <= 100
WHERE rnum >= 1
and RID = members.rowidThe difference between this and the one at Ask Tom's is that my innermost query just returns the ROWID. Then in the outermost query we join the ROWIDs returned to the members table, after we have pruned the ROWIDs down to only the chunk of 100 we want. This makes it MUCH faster (verifiably) on our large tables, as it is able to use the index on the innermost query (well... read on).
The problem I have is this:
SELECT rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindateThis will use the index for the predicate column (last_name) instead of the unique index I have defined for the joindate column (joindate, sequence). (Verifiable with explain plan). It is much slower this way on a large table. So I can hint it using either of the following methods:
SELECT /*+ index(members, joindate_idx) */ rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
SELECT /*+ first_rows(100) */ rowid as RID
FROM members
WHERE last_name = 'Smith'
ORDER BY joindateEither way, it now uses the index of the ORDER BY column (joindate_idx), so now it is much faster as it does not have to do a sort (remember, VERY large table, millions of records). So that seems good. But now, on my outermost query, I join the rowid with the meaningful columns of data from the members table, as commented below:
SELECT members.* -- Select all data from members table
FROM members, -- members table added to FROM clause
SELECT RID, rownum rnum
FROM
SELECT /*+ index(members, joindate_idx) */ rowid as RID -- Hint is ignored now that I am joining in the outer query
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate
WHERE rownum <= 100
WHERE rnum >= 1
and RID = members.rowid -- Merge the members table on the rowid we pulled from the inner queriesOnce I do this join, it goes back to using the predicate index (last_name) and has to perform the sort once it finds all matching values (which can be a lot in this table, there is high cardinality on some columns).
So my question is, in the full query above, is there any way I can get it to use the ORDER BY column for indexing to prevent it from having to do a sort? The join is what causes it to revert back to using the predicate index, even with hints. Remove the join and just return the ROWIDs for those 100 records and it flies, even on 10 million records.
It'd be great if there was some generic hint that could accomplish this, such that if we change the table/columns/indexes, we don't need to change the hint (the FIRST_ROWS hint is a good example of this, while the INDEX hint is the opposite), but any help would be appreciated. I can provide explain plans for any of the above if needed.
Thanks!Lakmal Rajapakse wrote:
OK here is an example to illustrate the advantage:
SQL> set autot traceonly
SQL> select * from (
2 select a.*, rownum x from
3 (
4 select a.* from aoswf.events a
5 order by EVENT_DATETIME
6 ) a
7 where rownum <= 1200
8 )
9 where x >= 1100
10 /
101 rows selected.
Execution Plan
Plan hash value: 3711662397
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 521K| 192 (0)| 00:00:03 |
|* 1 | VIEW | | 1200 | 521K| 192 (0)| 00:00:03 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 1200 | 506K| 192 (0)| 00:00:03 |
| 4 | TABLE ACCESS BY INDEX ROWID| EVENTS | 253M| 34G| 192 (0)| 00:00:03 |
| 5 | INDEX FULL SCAN | EVEN_IDX02 | 1200 | | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("X">=1100)
2 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
443 consistent gets
0 physical reads
0 redo size
25203 bytes sent via SQL*Net to client
281 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
101 rows processed
SQL>
SQL>
SQL> select * from aoswf.events a, (
2 select rid, rownum x from
3 (
4 select rowid rid from aoswf.events a
5 order by EVENT_DATETIME
6 ) a
7 where rownum <= 1200
8 ) b
9 where x >= 1100
10 and a.rowid = rid
11 /
101 rows selected.
Execution Plan
Plan hash value: 2308864810
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 201K| 261K (1)| 00:52:21 |
| 1 | NESTED LOOPS | | 1200 | 201K| 261K (1)| 00:52:21 |
|* 2 | VIEW | | 1200 | 30000 | 260K (1)| 00:52:06 |
|* 3 | COUNT STOPKEY | | | | | |
| 4 | VIEW | | 253M| 2895M| 260K (1)| 00:52:06 |
| 5 | INDEX FULL SCAN | EVEN_IDX02 | 253M| 4826M| 260K (1)| 00:52:06 |
| 6 | TABLE ACCESS BY USER ROWID| EVENTS | 1 | 147 | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter("X">=1100)
3 - filter(ROWNUM<=1200)
Statistics
8 recursive calls
0 db block gets
117 consistent gets
0 physical reads
0 redo size
27539 bytes sent via SQL*Net to client
281 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
101 rows processed
Lakmal (and OP),
Not sure what advantage you are trying to show here. But considering that we are talking about pagination query here and order of records is important, your 2 queries will not always generate output in same order. Here is the test case:
SQL> select * from v$version ;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
SQL> show parameter pga
NAME TYPE VALUE
pga_aggregate_target big integer 103M
SQL> create table t nologging as select * from all_objects where 1 = 2 ;
Table created.
SQL> create index t_idx on t(last_ddl_time) nologging ;
Index created.
SQL> insert /*+ APPEND */ into t (owner, object_name, object_id, created, last_ddl_time) select owner, object_name, object_id, created, sysdate - dbms_random.value(1, 100) from all_objects order by dbms_random.random;
40617 rows created.
SQL> commit ;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(user, 'T', cascade=>true);
PL/SQL procedure successfully completed.
SQL> select object_id, object_name, created from t, (select rid, rownum rn from (select rowid rid from t order by created desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
OBJECT_ID OBJECT_NAME CREATED
47686 ALL$OLAP2_JOIN_KEY_COLUMN_USES 28-JUL-2009 08:08:39
47672 ALL$OLAP2_CUBE_DIM_USES 28-JUL-2009 08:08:39
47681 ALL$OLAP2_CUBE_MEASURE_MAPS 28-JUL-2009 08:08:39
47682 ALL$OLAP2_FACT_LEVEL_USES 28-JUL-2009 08:08:39
47685 ALL$OLAP2_AGGREGATION_USES 28-JUL-2009 08:08:39
47692 ALL$OLAP2_CATALOGS 28-JUL-2009 08:08:39
47665 ALL$OLAPMR_FACTTBLKEYMAPS 28-JUL-2009 08:08:39
47688 ALL$OLAP2_DIM_LEVEL_ATTR_MAPS 28-JUL-2009 08:08:39
47689 ALL$OLAP2_DIM_LEVELS_KEYMAPS 28-JUL-2009 08:08:39
47669 ALL$OLAP9I2_HIER_DIMENSIONS 28-JUL-2009 08:08:39
47666 ALL$OLAP9I1_HIER_DIMENSIONS 28-JUL-2009 08:08:39
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc ;
OBJECT_ID OBJECT_NAME LAST_DDL_TIME
37534 com/sun/mail/smtp/SMTPMessage 06-FEB-2010 03:46:14
13133 oracle/jdbc/driver/OracleLog$3 06-FEB-2010 03:45:44
11749 /b9fe5b99_OraRTStatementComman 06-FEB-2010 03:43:49
42266 SI_GETCLRHSTGRFTR 06-FEB-2010 03:40:20
16695 /2940a364_RepIdDelegator_1_3 06-FEB-2010 03:38:17
36539 sun/io/ByteToCharMacHebrew 06-FEB-2010 03:28:57
26815 /7a628fb8_DefaultHSBChooserPan 06-FEB-2010 03:26:55
14044 /d29b81e1_OldHeaders 06-FEB-2010 03:12:12
36145 /4e492b6f_SerProfileToClassErr 06-FEB-2010 03:11:09
12920 /25f8f3a5_BasicSplitPaneUI 06-FEB-2010 03:11:06
15752 /2f494dce_JDWPThreadReference 06-FEB-2010 03:09:31
11 rows selected.
SQL> set autotrace traceonly
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid order by last_ddl_time desc
2 ;
11 rows selected.
Execution Plan
Plan hash value: 44968669
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 91200 | 180 (2)| 00:00:03 |
| 1 | SORT ORDER BY | | 1200 | 91200 | 180 (2)| 00:00:03 |
|* 2 | HASH JOIN | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 3 | VIEW | | 1200 | 30000 | 98 (0)| 00:00:02 |
|* 4 | COUNT STOPKEY | | | | | |
| 5 | VIEW | | 40617 | 475K| 98 (0)| 00:00:02 |
| 6 | INDEX FULL SCAN DESCENDING| T_IDX | 40617 | 793K| 98 (0)| 00:00:02 |
| 7 | TABLE ACCESS FULL | T | 40617 | 2022K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("T".ROWID="T1"."RID")
3 - filter("RN">=1190)
4 - filter(ROWNUM<=1200)
Statistics
1 recursive calls
0 db block gets
348 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 ;
11 rows selected.
Execution Plan
Plan hash value: 882605040
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 1 | VIEW | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 40617 | 1546K| 80 (2)| 00:00:01 |
|* 4 | SORT ORDER BY STOPKEY| | 40617 | 2062K| 80 (2)| 00:00:01 |
| 5 | TABLE ACCESS FULL | T | 40617 | 2062K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("RN">=1190)
2 - filter(ROWNUM<=1200)
4 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
343 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from t, (select rid, rownum rn from (select rowid rid from t order by last_ddl_time desc) where rownum <= 1200) t1 where rn >= 1190 and t.rowid = t1.rid ;
11 rows selected.
Execution Plan
Plan hash value: 168880862
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 1 | HASH JOIN | | 1200 | 91200 | 179 (2)| 00:00:03 |
|* 2 | VIEW | | 1200 | 30000 | 98 (0)| 00:00:02 |
|* 3 | COUNT STOPKEY | | | | | |
| 4 | VIEW | | 40617 | 475K| 98 (0)| 00:00:02 |
| 5 | INDEX FULL SCAN DESCENDING| T_IDX | 40617 | 793K| 98 (0)| 00:00:02 |
| 6 | TABLE ACCESS FULL | T | 40617 | 2022K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("T".ROWID="T1"."RID")
2 - filter("RN">=1190)
3 - filter(ROWNUM<=1200)
Statistics
0 recursive calls
0 db block gets
349 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> select object_id, object_name, last_ddl_time from (select t1.*, rownum rn from (select * from t order by last_ddl_time desc) t1 where rownum <= 1200) where rn >= 1190 order by last_ddl_time desc ;
11 rows selected.
Execution Plan
Plan hash value: 882605040
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 1 | VIEW | | 1200 | 62400 | 80 (2)| 00:00:01 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 40617 | 1546K| 80 (2)| 00:00:01 |
|* 4 | SORT ORDER BY STOPKEY| | 40617 | 2062K| 80 (2)| 00:00:01 |
| 5 | TABLE ACCESS FULL | T | 40617 | 2062K| 80 (2)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("RN">=1190)
2 - filter(ROWNUM<=1200)
4 - filter(ROWNUM<=1200)
Statistics
175 recursive calls
0 db block gets
388 consistent gets
0 physical reads
0 redo size
1063 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
11 rows processed
SQL> set autotrace off
SQL> spool offAs you will see, the join query here has to have an ORDER BY clause at the end to ensure that records are correctly sorted. You can not rely on optimizer choosing NESTED LOOP join method and, as above example shows, when optimizer chooses HASH JOIN, oracle is free to return rows in no particular order.
The query that does not involve join always returns rows in the desired order. Adding an ORDER BY does add a step in the plan for the query using join but does not affect the other query.
Maybe you are looking for
-
Please advise, i have somehow downloaded some extra tracks of the same songs, plus their relavant albums showing in songs/albums lists on my ipod nano 7th gen,how can i remove the unwanted extra songs/albums safely. Please note i am a newcomer to u
-
Mount USB stick on an ASA 5505?
Hello, I have an ASA 5505 and the built in flash is pretty small and I need to put 3 .pkg on it for Anyconnect 4. I formated an USB Stick (4GB) to FAT32 and put in the USB Port 2 on the back and rebooted the firewall. But in the filemanager I see dis
-
Af:query prefill search fields on task flow enter
Hello. What is given: Bounded task flow A with shared data control scope. Task flow contains one page fragment with two components: <af:query> and <af:table>. Table takes data from read only view object B. <af:query> is bound to search criteria withi
-
Old Accessories don't work.
So, I had an original iPhone. Paid full price for it. Then they dropped the price by $200. Bought a car integration kit for my MINI ($300 + installation), as well as a dock for my desk, etc. etc. Now I have the new iPhone and it won't work with any o
-
Converting from decimal to binary to hexadecimal to octal
hello everyone, my question is, Is there a way to get decimal input from user and print the binary, hexadecimal and octal value of that decimal? just like C does in printf command