Sequences in fragmented tables in oracle9i
how can I create a sequence that somehow checks what the nextval is as I have the same customer table in two databases? do I need to build a trigger?
I tried to use LAST_NUMBER from USER_SEQUENCES but it is not updated during normal db operation (says the oracle complete ref).
many thanks for your help!
The SQL and PL/SQL forum at
PL/SQL
may be the best place to ask this question.
-- CJ
Similar Messages
-
Question regarding sequences and fragmented data
Hi all,
I plan to implement two identical database schemas on two different oracle database servers. The two databases will then be linked via a Database Link and a View will be used to show the data from both db's using 1 sql statement.
My question is this:
If 5 records are inserted into the table on the first database and then 10 records are inserted into the matching table on the second database, how would the sequence for the table in the first database know that the next value should be 16 and not 6.
I hope this makes sense, any questions just ask.
Thanks,
MartinOk, I am not sure if I fully undserstand the question but let's give it a go. In the first place a sequence is stored in the data dictionary of a database. Te fact that you have two servers (and two databases : is that correct ?) means that you have two sequences also. The sequence is local to each db.
If you want the tables to be aware of each other so that the next record takes into account also the records in the other db you may have to manually generate the sequence. I don't know if you can share the sequence between two dbs but let's see if anyone else does.
Regards -
How to CREATE SEQUENCE in one table
dear all
the one thing i want to know when i use CREATE SEQUENCE in one table like this and then at that table
CREATE SEQUENCE oproduct_sequence
START WITH 1 INCREMENT BY 1
nocache
create table oproduct(
tname varchar2(20) not null,
tid int default oproduct_sequence.nextval
the system indicat that i cannot use this way to create table , so i really want to know how can i achieve this method
becuase when i want to insert inot table oproduct only use
insert into oproduct valuse('aaaa');
and the result like
aaaaa 1
bbbb 2Actual name is before insert trigger. Some examples are listed below:
Example Number 1 ...
create sequence product_seq start with 1 increment 1
create or replace trigger product_insert before insert for each row begin
select productseq.nextval
into :new.product_id
from dual;
end;
Example Number 2 ...
How to create an autoincrement field in a table with a sequence ...
SQLWKS> create table bob(a number , b varchar2(21));
Statement processed.
First create a sequence
SQLWKS> create sequence x ;
Statement processed.
Then create the trigger.
create trigger y before insert on bob
for each row
when (new.a is null)
begin
select x.nextval into :new.a from dual;
end;
Example Number 3 ...
First create a sequence:
create sequence emp_no_seq;By default it increments by 1 starting at 0.
Use its values when inserting data into the table:
insert into t_emp values (emp_no_seq.nexval, 'Joe Black');~ Madrid. -
How to view database table in oracle9i Jdeveloper
Hi,
how to view database table in oracle9i jdeveloper,any manual setting .please help me.
thanks
saran.In Jdeveloper go to View-->Connection Nevigator. there you will see all kind of connctions. Expand Database and check if your DB connection is present there. If not, you need to create using right clicking on Database and choose New Database Connecton. Here few screens will be there where you need to put the TNS entries of your database.
Once DB connection is created, you can expand the connection by clicking on + icon and you can see different available schema objects. Again you need to expand Tables and you can look for specific table in there.
Hope this clears your doubts.
Thanks,
Mukesh Uchaniya -
How to view database table in oracle9i developer
Hi,
how to view database table in oracle9i developer,any manual setting .please help me.
thanks
saran.Hi;
1. This site side related EBS for your issue there is sqldeveloer dedicated forum side
Forum Home » Application Development in PL/SQL » SQL Developer (Not for general SQL/PLSQL questions)
2. Please see:
http://docs.oracle.com/cd/B10501_01/java.920/a96655.pdf
Regard
Helios -
Multiple sequences on one table?
I have a simple table with 3 columns: ID, DML_ID and VALUE. The table was designed to be a metadata table with values for certain DML_IDs. The table has been maintained by IT. However, now the users wants to have control over some of the values. Let's call it User_Maintained values. IT does DML on this table and migrate the change to acceptance and production. At the same time users do DML in production. This causes ID conflict between dev, acc and prod.
My solution is to use 2 sequences, one for IT_maintained IDs the other for User_maintained IDs. One of the sequences starts with a much bigger number like 1000000 to avoid the conflict. Create a before insert trigger on the table to pick the right sequence number depends on if the DML is IT or user maintained.
My question here is, is it ok to use 2 sequences on one table? Is it against best practice of Oracle?
Another idea from my co-worker is, use single sequence instead of 2. The sequence will reside in production database and all the 3 databases (dev, acc and prod) will get ID from the same sequence through dblink. Personally I don't like the idea because I don't think getting sequence from production to be used in development is the "best pratice" of Oracle. Although I don't know where I can find the document to support my opinion.
Any idea is appreciated!!
SharonI've discussed with the DBAs and some developers, we all have concern about the idea of one sequence on production being used by all 3 databases (dev, acc and prod). Database clone is one issue. Also making one database (dev or acc) relies on another (production) is not a good approach. Each database should be as independent as possible - only create the linkage when it's necessary. In this case I don't think it's necessary.
I will go with one sequence for user maintained values (in prod), and a manual increase number (max(id) of IT maintained value plus 1) for IT list.
I do all these because the table was a bad design from the first begining so I can't really come up with a correct solution to work around this.
Thanks for everybody who gave input here. Very appreciated! -
How to find the sequence for a table.
Hi Everyone,
I've got plenty of sequences. How can I identify that what are the sequences acting on a table?
Regards,
BS2012.Greg.Spall wrote:
In my last job, we used the table/column comments to point to the sequence.
so:
CREATE SEQUENCE seq_test1;
CREATE TABLE my_table
(id number);
COMMENT ON TABLE my_table IS 'Test table for demonstration purposes on OTN';
COMMENT ON COLUMN my_table.id IS 'Primary Key, sequence populated: seq_test1';... or something like that :P
But yeah, outside of that, good luck if you have no documentation!Of course, ALL of the 'code search' solutions put forth are assuming the references will be found in PL/SQL packages. That ignores the potential that the code could be located somewhere else, like application code that exists OUTSIDE of the database .... Bottom line is that there is no 100% one-size-fits-all method for automating the discovery of relationships between tables and sequences. -
How to serach most fragmented tables in database(10g)
How to serach most fragmented tables in database(10g) and query
I mean
Most DML operations happened(mainly deletion ) by
which HWM is set for the table. I know by rebuilding
table segment can be compressed and we ggain free
space in tablespace too.OK, but to what end do you gain that free space in the tablespace? Say you had a table of 1,000,000 rows, and you deleted 900,000 of those rows, emptying out 'x' of 'y' extents. If you would expect the table to again grow to 1,000,000 rows (not an unreasonable assumption) then you will just need to reclaim again (by grabbing new extents) the space you freed up with your reorg. -
How to get a list of most fragmented tables in Oracle?
Is there an SQL on how to get a list of most fragmented tables in Oracle DBMS?
Thanks! I would just like to ask you, what do the negative values mean in wasted space?
Is there an easy way to improve defragmentation state?
TABLE NAME SIZE ACTUAL DATA WASTER SPACE
TREE 0 0 0
GC_S 3744 4651.9 -907.9
TRAIL 104 113.04 -9.04
ASSOCIATION_RULES 272 353 -81
ATTRIBUTES 1728 2528.12 -800.12
AUDITACTION 128 208.48 -80.48
DV 18608 36266.47 -17658.47
S134 728 903.08 -175.08
A178 344 518.75 -174.75
S129 728 896.48 -168.48
AGS_NODES 2864 4510.33 -1646.33
S149 472 633.79 -161.79
S127 728 871.62 -143.62
tu 2232 3619.76 -1387.76
PCd_DATA 3112 4371.75 -1259.75 -
Hi Gurus,
Can any one throw light on Sequencing in Planning Table (MF50)?
Where do we use this?
What are pre requistites?
How is useful?
As anyone made a scenario on this.
Please reply.
SriniDear Srini,
Can any one throw light on Sequencing in Planning Table (MF50)?
Where do we use this?
What are pre requistites?
How is useful?
1) MF50 is Mostly used in REM process
2) say for example you have two PV's for one material in REM
3) Demand given for this material is 100 Nos
4) after running MRP, system will pick one PV for 100 Nos
5) Now, we can go in MF50, & we can split the qty 100 Nos between two PV's
PV 1 - 50 Nos
PV 2 - 50 Nos
6) Now you can see in MD04, for this material will be splitted ( I.e two plan orders with 50 Each Nos )
7 ) on the whole, MF50 is used to Split Demand Quantities between PV's
Your old & good Forum member
so suggest you to close all your previous threads
Plz don't misundersatnd
Regards
Madhu Kumar -
Hi,
We are using following query to check fragmented tables. Is it correct?
Oracle 10.2.0.4 (64bit) and OS AIX 6.1 (64bit).
select owner,table_name,blocks,num_rows,avg_row_len,round(((blocks*16/1024)),2)||'MB' "TOTAL_SIZE",
round((num_rows*avg_row_len/1024/1024),2)||'Mb' "ACTUAL_SIZE",
round(((blocks*16/1024)-(num_rows*avg_row_len/1024/1024)),2) ||'MB' "FRAGMENTED_SPACE"
from all_tables WHERE Owner IN ('USERNAME');
I am using alter table move with parallel (due to huge size of data ) option and rebuild index for De-fragmentation. Is its OK?Hemant K Chitale,
Your multiplier of 16 is correct if the block size of the tablespace containing that table is 16KB.
DB block size is 16 kb.
What amount / proportion of "FRAGMENTED_SPACE" would you consider as qualifying a table for a rebuild ? Why ? What if you insert more rows into the table ?
Following is the ouptput of query I have posted in my first post. These are partitions tables
TABLE_NAME
BLOCKS
NUM_ROWS
AVG_ROW_LEN
TOTAL_SIZE
ACTUAL_SIZE
FRAGMENTED_SPACE
CRBT_DLY_SU
3426310
1134350200
104
53536.09MB
112507.27Mb
-58971.17MB
PST_VOICE_SU
5619763
373006533
376
87808.8MB
133753.26Mb
-45944.46MB
PRE_WEB_SU
2545843
627771700
125
39778.8MB
74836.22Mb
-35057.42MB
After the end of month I move partitions of tables into new created tablespace (alter table move partition with parallel option) , then rebuild index with parallel option. Now I am confused that how tables are fragmented with huge amount of data.
Are the tables in tablespaces with LMT and Segment Space Management AUTO ? OR do you need to consider PCTUSED (which is ignored with Segment Space Management AUTO) ? Are the tables set to the default PCTFREE of 10 ?
Yes tablespaces are LMT and Segment Space Management is Auto. -
Help-how can i see the sequence in the table?
Hi, i created sequence for the table. but how can i view the sequence as a column in the table? like the sequence started with 1 and increment by 1. how can i make it available as a column in the table? thanks a lot for anyone's prompt reply. much appreciated.
eg.
Create table:
create table t1 (
id number(10),
col1 varchar(2)
Create sequence:
CREATE SEQUENCE "PEMARTEN"."T1_ID" NOCYCLE NOORDER CACHE 20 NOMAXVALUE MINVALUE 1 INCREMENT BY 1 START WITH 1
You can do 2 things:
Use the sequence in your insert query:
eg.
insert into t1 (id, col1) values (t1_id.nextval, 'example');
OR
Create a before insert trigger (prefered):
CREATE OR REPLACE TRIGGER "PEMARTEN"."BI_T1" BEFORE INSERT ON "PEMARTEN"."T1"
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
new_id number;
BEGIN
SELECT t1_id.nextval
INTO new_id
FROM dual;
:new.id := new_id;
END;
Now you can just insert data:
insert into t1 (col1) values ('example');
sequence.nextval increments the sequence and returns the next value
sequence.currval returns the current value of a sequence
I hope that helps.
Kind regards,
Pieter -
Dear all,
I am using the following command to find out the fragmented tables or indexes, which ofcource returns names of the tables and indexes which are fragmented.
select * from dba_segments where extents > 10 and owner like '%DB%'
output is 43 rows
Next I just rebuild certian indexes and still when I query the above sql statement I see the index which was rebuild is still present which means that the extents are stiil greater than 10.
I also tried by first dropping the index and creating it again. Still the index is fragmented.
What can I do.
Regards
SL1) The fact that an object has more than 10 extents is completely unrelated to whether it is fragmented or not.
2) Since you haven't specified the Oracle version or the type of tablespace, assuming you've got a recent version of Oracle and are using locally managed tablespaces, the number of extents allocated to an object is pretty much irrelevent, particularly if you've got automatic extent allocation.
3) If you are on a recent version of Oracle using LMT's, it is essentially impossible for objects to be fragmented for most any reasonable definition of "fragmented".
Justin -
Hi guys,
I would like to create a table and populate it with lot of data to make some tests, but I also would like to have a high fragmented table to simulate this.
is there any script that create this environment?
thanksHi ,
Please try this ,Not tested.
1-Create table without any index.
2-insert data.
3-create index
4-update some data
5-drop Index.
6-create index
7-insert another data
check now select * from dba_segments where extents > 10;
Regards
faheem latif -
Error while relating sequence to a table
thanks for a quick reply.
i incorporated the suggestions that i got from here and i am getting the following error while i am trying to create a trigger:
ERROR at line 1:
ORA-04089: cannot create triggers on objects owned by SYS
It is pretty self-explanatory but I dont know why I am getting this error. I am connected as sys/change_on_install as SYSDBA
Help please!!
MaheshMahesh,
Hehehe well I had a little chuckle here after reading that. Don't create objects as SYS, that be a bad thing, unless your an elite hax0r.
First make a new user and create that table and trigger and sequence under this new user. The create user syntax is below. It is wise to make a user also that has DBA privs, so you don't need to be connecting as SYS (The syntax below makes a DBA user). This is very helpful if your forget your SYS password (which you really should be changing).
Note that you will have to specify the new user name, password, and in particular the TABLESPACE this new user will be making objects in. I put USR as it, but check to see if you have this tablespace or find one to make objects in, because right now your makeing tables in the SYSTEM table space which is a baaad thing.
DROP USER "U_TYLER";
CREATE USER "U_TYLER" IDENTIFIED BY "MY_PASSWORD_HERE"
DEFAULT TABLESPACE "USR"
TEMPORARY TABLESPACE "TEMP"
PROFILE DEFAULT ACCOUNT UNLOCK;
GRANT "CONNECT" TO "U_TYLER";
GRANT "RESOURCE" TO "U_TYLER";
GRANT "DBA" TO "U_TYLER";
ALTER USER "STB" DEFAULT ROLE ALL;
GRANT CREATE SYNONYM TO U_TYLER;
GRANT DROP PUBLIC SYNONYM TO U_TYLER;
GRANT CREATE PUBLIC SYNONYM TO U_TYLER;
Reply back if your still having some troubles, cause we love to help people worldwide :).
Tyler
Maybe you are looking for
-
Oracle CRM On Demand Outlook Integration - Add-in shows inactive
I have followed the steps given in the Oracle CRM On Demand->MySetup. After installing the OEI, the dll file is registered. In MS outlook->Tools->Trust Center->Add-ins. The Siebel Outlook Integration Add-ins is shown in the "Inactive Application Add-
-
How to find the memory contents
hai freinds can any one tell my query, i have exported soem field to abap memory, during debugging i want to see the contents of it , so u used the system settings and tried i am getting the abap memoried but i am unable to see my memory id if any on
-
InDesign CS5, unklare Schrift
Ich habe in InDesign CS5 schwarze Schrift auf rotem Hintergrund. Nun wird beim Ausdruck und beim pdf die schwarze Schrift ca. mit 0.5 mm weiss um die Buchstaben ausgedruckt, was ein sehr unsauberes Schriftbild gibt. Ich habe aber keinen Textschatten
-
Can i unlock the american contract phone in india
i wanna buy iphone 6 in usa which cost around 200$, and can it be unlocked in india for usage with indian networks.
-
Firefox halts and reuires shutdown and re-start
Hello, I imagine that you have had more than one question about the incident I will be describing. I open Firefox and begin web activity, checking e-mails etc. Firefox will halt and require an error report and a re-start. It does this several times,