- 最后登录
- 2014-4-16
- 在线时间
- 12 小时
- 威望
- 0
- 金钱
- 104
- 注册时间
- 2013-8-20
- 阅读权限
- 10
- 帖子
- 33
- 精华
- 0
- 积分
- 0
- UID
- 1191
|
1#
发表于 2014-1-20 21:29:33
|
查看: 4559 |
回复: 4
刘,您好:
在序列中有cache参数和order参数,我的问题是如果为noorder,在内存中cache的序列按照一定顺序分配的还是随机分配数的?如下是我的操作过程,为什么object_id会是连续的呢?是否与nextval有关系?请你帮忙解答一下,谢谢。
SQL>
SQL> create sequence emp_seq
2 start with 1
3 increment by 1
4 minvalue 1
5 nomaxvalue
6 cache 100
7 noorder;
Sequence created.
SQL> insert into emp_text (owner,object_name,object_type) select owner,object_name,object_type from dba_objects where rownum<10000;
9999 rows created.
SQL> SELECT * FROM EMP_TEXT WHERE ROWNUM<20;
OWNER OBJECT_NAME OBJECT_TYPE OBJECT_ID
------------------------------ ------------------------------ ------------------------------ ------------
PUBLIC V$MAP_LIBRARY SYNONYM
SYS V_$MAP_FILE VIEW
PUBLIC V$MAP_FILE SYNONYM
SYS V_$MAP_FILE_EXTENT VIEW
PUBLIC V$MAP_FILE_EXTENT SYNONYM
SYS V_$MAP_ELEMENT VIEW
PUBLIC V$MAP_ELEMENT SYNONYM
SYS V_$MAP_EXT_ELEMENT VIEW
PUBLIC V$MAP_EXT_ELEMENT SYNONYM
SYS V_$MAP_COMP_LIST VIEW
PUBLIC V$MAP_COMP_LIST SYNONYM
OWNER OBJECT_NAME OBJECT_TYPE OBJECT_ID
------------------------------ ------------------------------ ------------------------------ ------------
SYS V_$MAP_SUBELEMENT VIEW
PUBLIC V$MAP_SUBELEMENT SYNONYM
SYS V_$MAP_FILE_IO_STACK VIEW
PUBLIC V$MAP_FILE_IO_STACK SYNONYM
SYS V_$SQL_REDIRECTION VIEW
PUBLIC V$SQL_REDIRECTION SYNONYM
SYS V_$SQL_PLAN VIEW
PUBLIC V$SQL_PLAN SYNONYM
19 rows selected.
SQL>
SQL>
SQL> COMMIT;
Commit complete.
SQL> select dbms_metadata.get_ddl('SEQUENCE','EMP_SEQ') FROM DUAL;
DBMS_METADATA.GET_DDL('SEQUENCE','EMP_SEQ')
--------------------------------------------------------------------------------
CREATE SEQUENCE "AMY"."EMP_SEQ" MINVALUE 1 MAXVALUE 99999999999999999999999
99999 INCREMENT BY 1 START WITH 1 CACHE 100 NOORDER NOCYCLE
1 row selected.
SQL> declare
cursor emp_cursor is
2 3 select * from emp_text for update;
4 v_object_name emp_text%rowtype;
5 begin
6 open emp_cursor;
7 loop
fetch emp_cursor
8 9 into v_object_name;
10 if emp_cursor%found then
11 update emp_text
12 set object_id =
13 (emp_seq.nextval)
14 where object_name = v_object_name.object_name;
15 end if;
16 exit when emp_cursor%notfound;
17 end loop;
18 close emp_cursor;
19 end;
20 /
PL/SQL procedure successfully completed.
SQL> COMMIT;
Commit complete.
SQL> SELECT * FROM EMP_TEXT WHERE ROWNUM<20;
OWNER OBJECT_NAME OBJECT_TYPE OBJECT_ID
------------------------------ ------------------------------ ------------------------------ ------------
PUBLIC V$MAP_LIBRARY SYNONYM 1
SYS V_$MAP_FILE VIEW 2
PUBLIC V$MAP_FILE SYNONYM 3
SYS V_$MAP_FILE_EXTENT VIEW 4
PUBLIC V$MAP_FILE_EXTENT SYNONYM 5
SYS V_$MAP_ELEMENT VIEW 6
PUBLIC V$MAP_ELEMENT SYNONYM 7
SYS V_$MAP_EXT_ELEMENT VIEW 8
PUBLIC V$MAP_EXT_ELEMENT SYNONYM 9
SYS V_$MAP_COMP_LIST VIEW 10
PUBLIC V$MAP_COMP_LIST SYNONYM 11
OWNER OBJECT_NAME OBJECT_TYPE OBJECT_ID
------------------------------ ------------------------------ ------------------------------ ------------
SYS V_$MAP_SUBELEMENT VIEW 12
PUBLIC V$MAP_SUBELEMENT SYNONYM 13
SYS V_$MAP_FILE_IO_STACK VIEW 14
PUBLIC V$MAP_FILE_IO_STACK SYNONYM 15
SYS V_$SQL_REDIRECTION VIEW 16
PUBLIC V$SQL_REDIRECTION SYNONYM 17
SYS V_$SQL_PLAN VIEW 18
PUBLIC V$SQL_PLAN SYNONYM 19
|
|