0 Bewertungen0% fanden dieses Dokument nützlich (0 Abstimmungen)
37 Ansichten5 Seiten
The document discusses Oracle sequences. It provides details on how to create sequences using the CREATE SEQUENCE statement and the various parameters that can be used such as INCREMENT BY, START WITH, MAXVALUE, CACHE etc. It also describes how to generate and use sequence numbers in SQL statements for primary key generation and inserting values.
The document discusses Oracle sequences. It provides details on how to create sequences using the CREATE SEQUENCE statement and the various parameters that can be used such as INCREMENT BY, START WITH, MAXVALUE, CACHE etc. It also describes how to generate and use sequence numbers in SQL statements for primary key generation and inserting values.
Copyright:
Attribution Non-Commercial (BY-NC)
Verfügbare Formate
Als TXT, PDF, TXT herunterladen oder online auf Scribd lesen
The document discusses Oracle sequences. It provides details on how to create sequences using the CREATE SEQUENCE statement and the various parameters that can be used such as INCREMENT BY, START WITH, MAXVALUE, CACHE etc. It also describes how to generate and use sequence numbers in SQL statements for primary key generation and inserting values.
Copyright:
Attribution Non-Commercial (BY-NC)
Verfügbare Formate
Als TXT, PDF, TXT herunterladen oder online auf Scribd lesen
http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.p hp how to analyse http://www.dba-oracle.com/art_builder_get_schema_syntax.htm http://www.oracle-base.com/articles/10g/Auditing_10gR2.php http://www.dba-oracle.com/art_builder_get_schema_syntax.htm http://www.dba-oracle.com/art_builder_get_schema_syntax.htm http://www.scribd.com/doc/123218/Oracle-Streams-Step-by-Step-Doc http://www.scribd.com/doc/123218/Oracle-Streams-Step-by-Step-Doc http://www.oracle.com/pls/db10g/portal.portal_demo3?selected=3 http://psoug.org/reference/dbms_stats.html http://psoug.org/reference/dbms_stats.html ANALYZE table scott compute statistics; ANALYZE table om.emp1 estimate statistics sample 25 percent; ANALYZE table om.emp1 estimate statistics sample 1000 rows; analyze index om.emp1 compute statistics; analyze index om.emp1 validate structure; Step 33 Upgrade Statistics Tables Created by the DBMS_STATS Package
If you created statistics tables using the DBMS_STATS.CREATE_STAT_TABLE procedur
e, then upgrade these tables by executing the following procedure: EXECUTE DBMS_STATS.UPGRADE_STAT_TABLE('SYS','EMP1'); In the example, 'SYS' is the owner of the statistics table and 'dictstattab' is the name of the statistics table. Execute this procedure for each statistics tab le.
-------------------------------------------ABOVE MENTION FOR TODAYS WORKS ------
-------------------------- http://allinterview.com/showanswers/28754.html http://www.dba-oracle.com/art_builder_buffers.htm how to predict largest cache select a.sal from emp a where 3=(select distinct(count(b.sal)) from emp b where a.sal<=b.sal) Select sal from emp e where 3>=(select count (Sal) from emp where sal>e.sal) order by sal desc; DECLARE @SQL VARCHAR(2000), @N INT SET @N = 5 SET @N = @N - 1 SET @sql = 'select top 1 salary from ABC where salary not in ( SELECT TOP ' + CAST(@n AS VARCHAR(100)) + ' salary FROM ABC ) ' SELECT @SQL EXEC (@SQL) select top 1 salary from (select distinct top 9 salary from EmpMaster order by salary desc)a SQLWKSdesc v$db_object_cache Name Null? Type ----------------------------------------- -------- ---------------------------- OWNER VARCHAR2(64) NAME VARCHAR2(1000) DB_LINK VARCHAR2(64) NAMESPACE VARCHAR2(28) TYPE VARCHAR2(28) SHARABLE_MEM NUMBER LOADS NUMBER EXECUTIONS NUMBER LOCKS NUMBER PINS NUMBER KEPT VARCHAR2(3) CHILD_LATCH NUMBER INVALIDATIONS select owner, name, kept from v$db_object_cache where owner = 'OM' / create sequence OM.my_seq; create or replace trigger PIN_STUFF after startup on database begin sys.dbms_shared_pool.keep( 'SCOTT.MY_SEQ', 'Q' ); end; / CREATE SEQUENCE empseq_1 INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE CACHE 10; The NOCYCLE option indicates that the sequence cannot generate more values after reaching its maximum or minimum value. The CACHE clause preallocates a set of sequence numbers and keeps them in memory so that sequence numbers can be accessed faster. When the last of the sequence numbers in the cache has been used, the database r eads another set of numbers into the cache Sequence created. SQL> create table testseq 2 (roll number, 3 name varchar2(20)); Table created. SQL> select * from testseq; ROLL NAME ---------- -------------------- 1 vibha 2 rama 3 rahul SQL> select empseq_1.currval from dual; CURRVAL ---------- 3 SQL> select empseq_1.nextval from dual; NEXTVAL ---------- 4 SQL> select empseq_1.nextval from dual; NEXTVAL ---------- 5 SQL> select empseq_1.nextval from dual; NEXTVAL ---------- 6 SQL> select empseq_1.nextval from dual; NEXTVAL ---------- 7 CREATE SEQUENCE empseq_3 INCREMENT BY 1 START WITH 1 MAXVALUE 10 NOCYCLE CACHE 9; ERROR at line 1: ORA-08004: sequence EMPSEQ_3.NEXTVAL exceeds MAXVALUE and cannot be instantiated CREATE SEQUENCE empseq_4 INCREMENT BY 1 START WITH 1 MAXVALUE 10 NOCYCLE NOCACHE CACHE 9; CREATE SEQUENCE [ schema. ]sequence [ { INCREMENT BY | START WITH } integer | { MAXVALUE integer | NOMAXVALUE } | { MINVALUE integer | NOMINVALUE } | { CYCLE | NOCYCLE } | { CACHE integer | NOCACHE } | { ORDER | NOORDER } ] [ { INCREMENT BY | START WITH } integer | { MAXVALUE integer | NOMAXVALUE } | { MINVALUE integer | NOMINVALUE } | { CYCLE | NOCYCLE } | { CACHE integer | NOCACHE } | { ORDER | NOORDER } ]... ; create table employee (order_id number, order_date date, customer_id number) CREATE SEQUENCE orders_seq START WITH 1000 INCREMENT BY 1 NOCACHE NOCYCLE; INSERT INTO employee (order_id, line_item_id, product_id) VALUES (orders_seq.currval, 1, 2359);
create or replace trigger product_insert on baba
before insert for each row begin select productseq.nextval into :new.name from dual; end; / Sequences in Oracle Oracle has a standard function for automatically generate a sequence of number. This can be very usefull for generating a unique number to insert in a primary k ey field. A sequence is a stored object in the database. Sequences can be created in the Oracle database with a CREATE SEQUENCE statement . The syntax is: CREATE SEQUENCE sequence_name; You can add optional parameters to this statement. Example: CREATE SEQUENCE customer_seq INCREMENT BY 1 CACHE 10; The following sequence parameters are possible: Parameter Example Description INCREMENT BY INCREMENT BY 1 Specify the interval between sequence numbers. T his integer value can be any positive or negative integer, but it cannot be 0. T his value can have 28 or fewer digits. The absolute of this value must be less t han the difference of MAXVALUE and MINVALUE. If this value is negative, then the sequence descends. If the increment is positive, then the sequence ascends. If you omit this clause, the interval defaults to 1. START WITH START WITH 1000 Specify the first sequence number to be generated. Use this clause to start an ascending sequence at a value greater tha n its minimum or to start a descending sequence at a value less than its maximum . For ascending sequences, the default value is the minimum value of the sequenc e. For descending sequences, the default value is the maximum value of the seque nce. This integer value can have 28 or fewer digits. MAXVALUE MAXVALUE 99999999 Specify the maximum value the sequence c an generate. This integer value can have 28 or fewer digits. MAXVALUE must be eq ual to or greater than START WITH and must be greater than MINVALUE. NOMAXVALUE NOMAXVALUE Specify NOMAXVALUE to indicate a maximum value o f 1 with 27 zeros for an ascending sequence or -1 for a descending sequence. Thi s is the default. MINVALUE MINVALUE=1 Specify the minimum value of the sequence. This integer value can have 28 or fewer digits. MINVALUE must be less than or equal t o START WITH and must be less than MAXVALUE. NOMINVALUE NOMINVALUE Specify NOMINVALUE to indicate a minimum value o f 1 for an ascending sequence or -1026 for a descending sequence. This is the de fault. CYCLE CYCLE Specify CYCLE to indicate that the sequence continues to generat e values after reaching either its maximum or minimum value. After an ascending sequence reaches its maximum value, it generates its minimum value. After a desc ending sequence reaches its minimum, it generates its maximum. NOCYCLE NOCYCLE Specify NOCYCLE to indicate that the sequence ca nnot generate more values after reaching its maximum or minimum value. This is t he default. CACHE CACHE 10 Specify how many values of the sequence Oracle prealloca tes and keeps in memory for faster access. This integer value can have 28 or few er digits. The minimum value for this parameter is 2. For sequences that cycle, this value must be less than the number of values in the cycle. You cannot cache more values than will fit in a given cycle of sequence numbers. If a system fai lure occurs, all cached sequence values that have not been used in committed DML statements are lost. The potential number of lost values is equal to the value of the CACHE parameter. NOCACHE NOCACHE Specify NOCACHE to indicate that values of the s equence are not preallocated. If you omit both CACHE and NOCACHE, Oracle caches 20 sequence numbers by default. ORDER ORDER Specify ORDER to guarantee that sequence numbers are generated i n order of request. You may want to use this clause if you are using the sequenc e numbers as timestamps. Guaranteeing order is usually not important for sequenc es used to generate primary keys. ORDER is necessary only to guarantee ordered g eneration if you are using Oracle with Real Application Clusters. If you are usi ng exclusive mode, sequence numbers are always generated in order. NOORDER NOORDER Specify NOORDER if you do not want to guarantee sequence numbers are generated in order of request. This is the default. How to use a sequence You can use a sequence in the following way in SQL: select customer_seq.nextval from dual; INSERT INTO customers(id, name) VALUES (customer_seq.nextval,'custome r name');