Counter in a Primary Key
Hello,
I work with VB6 and ADO in Sql-Server database, I would like work with Oracle databases but in my table in Sql-Server I have a primary key field that is a automatic counter (identity).
Is possible in Oracle has a primary key field that is a counter (progressive of a number)?
You certainly can. You generally want to create a sequence object and a before insert trigger to populate the primary key column for this sort of thing. There is an example of this sort of thing here: http://www.ddbcinc.com/askddbc/topic.asp?TOPIC_ID=239
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Similar Messages
-
IR - if count (primary key) cannot change to count different column
Apex 4.1.1.00.23 Windows 7 IE8 / Firefox 16
If I add a Group By and Count to an Interactive report and choose the primary key column as the one to Count, run the report and then edit the Group By to count a different column, the result set does not change, and if I edit the Group By again it shows that the Counted column has reverted back to the primary key column.
If I initially choose a different column I can change it and rerun the report successfully, but once I choose the primary key column it cannot be changed. This seems to happen on all applications and all browsers. Is it a bug in Apex?
Thanks,
Nick.I've tried this in 4.1.0.00.32: works normally. In 4.1.1.00.23 however i'm getting the weird behaviour: you can count on any column, but the moment you count the same column as the one grouped on you can not change the column back to another one anymore. Something which works fine in 4.1.0.00.32.
-
HOW TO GET COUNT IN OF COMPOSITE PRIMARY KEYS USING ECLIPSELINK
Hi all,
We are currently migrating our application form oracle 10g to 11 g and hence migrating from toplink to eclipselink.
we are unable to fire the count query and getting the following exception ...
Error Code: 909
Call: SELECT COUNT() FROM T_USER_MESSAGE t0, T_USER t2, T_MESSAGE_RECIPIENT t1 WHERE ((((t2.PERSISTENT_ID = ?) AND (t2.SITE_CODE = ?)) AND (t1.DELETED_BY_RECIPIENT = ?)) AND (((t2.PERSISTENT_ID = t1.RECIPIENT_ID) AND (t2.SITE_CODE = t1.RECIPIENT_SITE)) AND ((t0.PERSISTENT_ID = t1.MESSAGE_ID) AND (t0.SITE_CODE = t1.MESSAGE_SITE))))
bind => [13398610, 1, F]
please advise .
we suspect that this could be because of the composite primary key in one of the tables .
any pointers to specify how count(*) could be used in this scenario would be of great help ..
Thanks in advanceWhat is the query being used, include the JPQL/expression code.
What is the error message (I assume this is a database error?).
What version are you using, can you try the latest EclipseLink 2.1 release.
James : http://www.eclipselink.org -
What is the diffrence between Row id and primary key ?
dear all
my question is about creating materialized views parameters (With Rowid and
With Primary kry)
my master table contains a primary key
and i created my materialized view as follow:
CREATE MATERIALIZED VIEW LV_BULLETIN_MV
TABLESPACE USERS
NOCACHE
LOGGING
NOCOMPRESS
NOPARALLEL
REFRESH FAST ON DEMAND
WITH PRIMARY KEY
AS
SELECT
BCODE ID, BTYPE BTYPE_ID,
BDATE THE_DATE,SYMBOL_CODE STOCK_CODE,
BHEAD DESC_E, BHEADARB DESC_A,
BMSG TEXT_E, BMSGARB TEXT_A,
BURL URL, BTIME THE_TIME
FROM BULLETIN@egid_sefit;
I need to know is there a diffrence between using (with row id) and (with primary key) on the performance of the query?Hi again,
fast refreshing complex views based on rowids, according to the previous subject.
(You're example shows that) are not possible.
Complex remote (replication) snapshots cannot be based on Rowid too.
for 10.1
http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_6002.htm#sthref5054
for 10.2
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6002.htm#sthref6873
So I guess (didn't check it) that this applies ONLY to replication snapshots.
This is not documented clearly though (documentation bug ?!)
Documentation states that the following is generally not possible with Rowid MVIEWS:
Distinct or aggregate functions
GROUP BY or CONNECT BY clauses
Subqueries
Joins
Set operations
Rowid materialized views are not eligible for fast refresh after a master table reorganization until a complete refresh has been performed.
The main purpose of my statements was to try to give a few tips how to avoid common problems with this complex subject, like for example: being able to CREATE an MVIEW with fast refresh clause does not really guarantee that it will refresh fast in the long run (reorganisation, partition changes) if ROWID based, further the rowid mviews have limitations according to the documentation (no group by, no connect by, link see above) plus fast refresh means only to use filter columnns of the mview logs, plus for aggregates you need additional count (*) pseudo columns.
kind regards
Karsten -
Create a materized view without primary key constraint on the base table?
Hi
I tried to create a materized view but I got this error:
SQL> CREATE MATERIALIZED VIEW TABLE1_MV REFRESH FAST
START WITH
to_date('04-25-2009 03:00:13','MM-dd-yyyy hh24:mi:ss')
NEXT
sysdate + 1
AS
select * from TABLE1@remote_db
SQL> /
CREATE MATERIALIZED VIEW TABLE1_MV REFRESH FAST
ERROR at line 1:
ORA-12014: table 'TABLE1' does not contain a primary key constraint.
TABLE1 in remote_db doesn't have a primary key constraint. Is there anyway that I can create a materized view on a base table which doesn't have a primary key constraint?
Thanks
LizHi,
Thanks for your helpful info. I created a materialized view in the source db with rowid:
SQL> CREATE MATERIALIZED VIEW log on TABLE1 with rowid;
Materialized view log created.
Then I created a MV on the target DB:
CREATE MATERIALIZED VIEW my_schema.TABLE1_MV
REFRESH FAST
with rowid
START WITH
to_date('04-25-2009 03:00:13','MM-dd-yyyy hh24:mi:ss')
NEXT
sysdate + 1
AS
select * from TABLE1@remote_db
SQL> /
CREATE MATERIALIZED VIEW my_schema.TABLE1_MV
ERROR at line 1:
ORA-12018: following error encountered during code generation for
"my_schema"."TABLE1_MV"
ORA-00942: table or view does not exist
TABLE1 exists in remote_db:
SQL> select count(*) from TABLE1@remote_db;
COUNT(*)
9034459
Any clue what is wrong?
Thanks
Liz -
Violation of Primary Key after a successful Update of BP
When I've updated a BP via VB.net is there something I should do with the BP object after I've done an update?
I can't seem to do consecative updates or I get the following error:
Violation of PRIMARY KEY constraint 'CRD1_PRIMARY'. Cannot insert duplicate key in object 'CRD1'
This is the code I use for updating:
For i = 0 To oBusinessPartner.Addresses.Count - 1
oBusinessPartner.Addresses.SetCurrentLine(i)
If (oBusinessPartner.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo) Then
'** Check only SHIP TO Addresses
If (oBusinessPartner.Addresses.AddressName = cbSAPShipTo.SelectedItem) Then
'** Address User wishes to update
oBusinessPartner.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo
oBusinessPartner.Addresses.AddressName = lSAPAddressItems(iIndex).Company
oBusinessPartner.Addresses.Street = lSAPAddressItems(iIndex).Address1
oBusinessPartner.Addresses.City = lSAPAddressItems(iIndex).City
oBusinessPartner.Addresses.ZipCode = lSAPAddressItems(iIndex).Postal
oBusinessPartner.Addresses.State = lSAPAddressItems(iIndex).Prov
oBusinessPartner.Addresses.Country = lSAPAddressItems(iIndex).Country
End If
End If
Next
lRetCode = oBusinessPartner.Update()
I check to make sure the address i want to up date is a ShipTo address, then I check to make sure that the item I am editing matches the one in the BPObject's CurrentLine.
Then I just change the values and .Update() it
After I've done this though, if I try to update another ShipTo address in the same BP, it comes up with that error.
Should I kill the BP object and reinitialize it?Hi Tyler,
I totally understand what you wanna do.
The clauses which you use is trying to add a new address in the name of existing address.
You have to do 'setcurrentline' clause, I guess.
But now, you don't know 'what is the ShipTo line'.
Then, I think you'd better use some simple, easy but timely expensive way.
1. Count the records in CRD1 under conditions of the cardcode.
-> then you can get the number of addresses of the business partner.
2. use a loop (while, for.. doesn't matter.)
-> Now you can use setcurrentline clause.
3. If the addressname is 'ShipTo', then you can update the record, and exit loop.
pseudo code comes below.
sql = "Select count(*) FROM OCRD WHERE cardcode = 'aaa'"
ors.doquery sql
for i=1 to ors.fields.item(0)
oBusinessPartners.Addresses.setcurrentline(i)
if obusinessPartners.Addresses.AddressName = "ShipTo" then
oBusinessPartners.block = "newBlock"
exit for
end if
next i
Hope this useful for you.
Regards,
Hyunil choi. -
Sql*loader and sequence() for primary keys
I have a question regarding SQL*Loader with the sequence() function and using it for a primary key to load records in multiple tables from one input record. I am pulling data from a delimited file and populating several tables from each row. For the primary key, I am using the sequence function.
For the first table (the parent), I use sequence(40000,1) for the key. Since the remaining inserts are based on the same logical record, I use sequence(40000,1) for those too (one record for each month). The problem comes in when a child record does not pass a WHEN clause (the amount is zero). Then it almost seems as if the parent record is not loaded and the child (or children) that does pass the WHEN clause are assigned to the next parent! Obviously, the sequence is getting out of sync between the children and the parent.
I've looked in the documentation and tried several different ways to attack this problem. Is there a bug in SQLLDR (8.1.7) or is it just my coding.
I will try to include the files below but they are very large.
Thanks for your help.
Dan
***CONTROL FILE***
LOAD DATA
INFILE 'rent.csv'
INTO TABLE BUDGET_LINE
append
WHEN TOT_AMT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER CHAR,
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
JUN_AMT FILLER CHAR,
JUN_CNT FILLER CHAR,
JUL_AMT FILLER CHAR,
JUL_CNT FILLER CHAR,
AUG_AMT FILLER CHAR,
AUG_CNT FILLER CHAR,
SEP_AMT FILLER CHAR,
SEP_CNT FILLER CHAR,
OCT_AMT FILLER CHAR,
OCT_CNT FILLER CHAR,
NOV_AMT FILLER CHAR,
NOV_CNT FILLER CHAR,
DEC_AMT FILLER CHAR,
DEC_CNT FILLER CHAR,
CUT FILLER CHAR,
NETMANGEN FILLER CHAR,
NETMAN_item BOUNDFILLER CHAR,
NETMAN_item_seq BOUNDFILLER CHAR,
NETMAN_location BOUNDFILLER CHAR,
UPDATED_ON DATE "MM/DD/YYYY",
NETMAN_com_desc BOUNDFILLER CHAR,
NETMAN_vendor BOUNDFILLER CHAR,
NETMAN_generation BOUNDFILLER CHAR,
CREATED_ON SYSDATE,
CREATED_BY CONSTANT '0',
UPDATED_BY CONSTANT '0',
ACTIVE CONSTANT 'T',
GL_CODE_COMBO_ID CONSTANT '0',
BUDGET_TYPE CONSTANT 'B',
AMOUNT_TYPE CONSTANT 'D',
source constant 'N',
BUDGET_LINE_ID SEQUENCE(40000,1),
DESCRIPTION "(:NETMAN_item)||'-'||(:NETMAN_item_seq)||'; '||:NETMAN_com_desc||'; '||:NETMAN_vendor||' ('||:NETMAN_generation||')'"
INTO TABLE GL_CODE_TEMP
append
WHEN TOT_AMT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
SPENDER CHAR ,
ACCT CHAR ,
TOT_AMT FILLER CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '1',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '2',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '3',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '4',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '5',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '6',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '7',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
JUN_AMT FILLER CHAR,
JUN_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '8',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
JUN_AMT FILLER CHAR,
JUN_CNT FILLER CHAR,
JUL_AMT FILLER CHAR,
JUL_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '9',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
JUN_AMT FILLER CHAR,
JUN_CNT FILLER CHAR,
JUL_AMT FILLER CHAR,
JUL_CNT FILLER CHAR,
AUG_AMT FILLER CHAR,
AUG_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '10',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
JUN_AMT FILLER CHAR,
JUN_CNT FILLER CHAR,
JUL_AMT FILLER CHAR,
JUL_CNT FILLER CHAR,
AUG_AMT FILLER CHAR,
AUG_CNT FILLER CHAR,
SEP_AMT FILLER CHAR,
SEP_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '11',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
JUN_AMT FILLER CHAR,
JUN_CNT FILLER CHAR,
JUL_AMT FILLER CHAR,
JUL_CNT FILLER CHAR,
AUG_AMT FILLER CHAR,
AUG_CNT FILLER CHAR,
SEP_AMT FILLER CHAR,
SEP_CNT FILLER CHAR,
OCT_AMT FILLER CHAR,
OCT_CNT FILLER CHAR,
AMOUNT CHAR
INTO TABLE BUDGET_COST
append
WHEN AMOUNT != '0'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
NETMAN_ITEM_NO FILLER POSITION(1) CHAR TERMINATED BY ',',
BUDGET_LINE_ID SEQUENCE(40000,1),
PERIOD_ID CONSTANT '12',
SPEND FILLER CHAR,
ACCOUNT FILLER CHAR,
TOT_AMT FILLER CHAR,
JAN_AMT FILLER CHAR,
JAN_CNT FILLER CHAR,
FEB_AMT FILLER CHAR,
FEB_CNT FILLER CHAR,
MAR_AMT FILLER CHAR,
MAR_CNT FILLER CHAR,
APR_AMT FILLER CHAR,
APR_CNT FILLER CHAR,
MAY_AMT FILLER CHAR,
MAY_CNT FILLER CHAR,
JUN_AMT FILLER CHAR,
JUN_CNT FILLER CHAR,
JUL_AMT FILLER CHAR,
JUL_CNT FILLER CHAR,
AUG_AMT FILLER CHAR,
AUG_CNT FILLER CHAR,
SEP_AMT FILLER CHAR,
SEP_CNT FILLER CHAR,
OCT_AMT FILLER CHAR,
OCT_CNT FILLER CHAR,
NOV_AMT FILLER CHAR,
NOV_CNT FILLER CHAR,
AMOUNT CHAR
*** PIECE OF DATA FILE ***
Item,Spender,Account,Total Amt,Jan Amt,Jan Count,Feb Amt,Feb Count,Mar Amt,Mar Count,Apr Amt,Apr Count,May Amt,May Count,Jun Amt,Jun Count,Jul Amt,Jul Count,Aug Amt,Aug Count,Sep Amt,Sep Count,Oct Amt,Oct Count,Nov Amt,Nov Count,Dec Amt,Dec Count,Status,Netman Gen,Netman Item,Netman Unit,Location,Last Update Date,Component Description,Vendor Description,Generation Process
10110993,10993,8301-01,90134,7480,0,7480,0,7480,0,7480,0,7480,0,7480,0,7480,0,7480,0,7480,0,7480,0,7667,0,7667,0,0,+,LEASE PYMT,207,WIMOS,5/22/2002,LEASE PAYMENTS,"VIKING HOLDING, INC.",ACTUAL BUDGET
10410993,10993,8301-04,15240,1270,0,1270,0,1270,0,1270,0,1270,0,1270,0,1270,0,1270,0,1270,0,1270,0,1270,0,1270,0,0,+,JANITORIAL,58,WIMOS,5/22/2002,JANITORIAL,BUILDING ONE SVC SOLUTION,ACTUAL BUDGET
10810993,10993,8301-08,2232,186,0,186,0,186,0,186,0,186,0,186,0,186,0,186,0,186,0,186,0,186,0,186,0,0,+,ELECTRIC,77,WIMOS,5/22/2002,"UTILITIES (GAS,ELEC.,ETC)",WISCONSIN PUBLIC SERVICE,AVGD 01 04 07 10 NOT WEIGHTED
10910993,10993,8301-09,4220,26,0,348,0,609,0,383,0,348,0,371,0,348,0,371,0,360,0,348,0,360,0,348,0,0,+,FIRE EQUIP,51,WIMOS,5/22/2002,RENT CONTRACT SERVICES,"CENTRALCOM, INC.",ACTUAL EXPERIENCE
11610993,10993,8301-16,1272,106,0,106,0,106,0,106,0,106,0,106,0,106,0,106,0,106,0,106,0,106,0,106,0,0,+,L/H MOSINE,1,WIMOS,5/22/2002,LEASEHOLD IMPROVEMENTS,ELLIS STONE,ACTUAL BUDGET
10110994,10994,8301-01,69960,5830,0,5830,0,5830,0,5830,0,5830,0,5830,0,5830,0,5830,0,5830,0,5830,0,5830,0,5830,0,0,+,LEASE PYMT,228,WISTEWEL,5/22/2002,LEASE PAYMENTS,BJ INVESTMENTS LLC,ACTUAL BUDGET
10410994,10994,8301-04,840,70,0,70,0,70,0,70,0,70,0,70,0,70,0,70,0,70,0,70,0,70,0,70,0,0,+,JANITORIAL,69,WISTEWEL,5/22/2002,JANITORIAL,MARSDEN,ACTUAL BUDGET
10710994,10994,8301-07,6067,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6067,0,0,+,LEASE PYMT,228,WISTEWEL,5/22/2002,LEASE PAYMENTS,BJ INVESTMENTS LLC,ASSUME 5% INCREASE OVER ACTUAL 2000 EXPENSES
10810994,10994,8301-08,2460,205,0,205,0,205,0,205,0,205,0,205,0,205,0,205,0,205,0,205,0,205,0,205,0,0,+,ELECTRIC,84,WISTEWEL,5/22/2002,"UTILITIES (GAS,ELEC.,ETC)",BJ INVESTMENTS LLC,AVGD 03 06 09 NOT WEIGHTED
10910994,10994,8301-09,1050,70,0,70,0,105,0,105,0,70,0,105,0,35,0,140,0,35,0,70,0,210,0,35,0,0,+,SANITATION,12,WISTEWEL,5/22/2002,RENT CONTRACT SERVICES,WASTE MANAGEMENT OF WIS,ACTUAL EXPERIENCE
11910994,10994,8301-19,1099,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1099,0,0,0,0,0,0,0,0,0,0,+,INSURANCE,6,WISTEWEL,5/22/2002,INSURANCE,BJ INVESTMENTS LLC,ACTUAL EXPERIENCE
10110998,10998,8301-01,2440,2440,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,+,LEASE PYMT,47,ILELG,5/22/2002,LEASE PAYMENTS,ELGIN AIRPORT BUSINESS PK,ACTUAL BUDGET
10410998,10998,8301-04,146,146,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,+,LEASE PYMT,47,ILELG,5/22/2002,LEASE PAYMENTS,ELGIN AIRPORT BUSINESS PK,ACTUAL BUDGET
10610998,10998,8301-06,336,28,0,28,0,28,0,28,0,28,0,28,0,28,0,28,0,28,0,28,0,28,0,28,0,0,+,DRINK H2O,46,ILELG,5/22/2002,COOLER AND BOTTLED WATER,"HINCKLEY & SCHMITT, INC.",AVGD 01 02 03 04 05 06 07 08 09 10
10710998,10998,8301-07,276,276,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,+,LEASE PYMT,47,ILELG,5/22/2002,LEASE PAYMENTS,ELGIN AIRPORT BUSINESS PK,ASSUME 5% INCREASE OVER ACTUAL 2000 EXPENSES
10810998,10998,8301-08,3108,433,0,315,0,234,0,173,0,181,0,292,0,320,0,337,0,316,0,153,0,183,0,171,0,0,+,ELECTRIC,20,ILELG,5/22/2002,"UTILITIES (GAS,ELEC.,ETC)",COMMONWEALTH EDISON,AVGD 01 02 03 04 05 06 07 08 09 10 WEIGHTED
*** SCRIPT FOR TABLES LOADED ***
CREATE TABLE BUDGET_LINE (
BUDGET_LINE_ID NUMBER NOT NULL,
BUDGET_TYPE CHAR (1) NOT NULL,
GL_CODE_COMBO_ID NUMBER NOT NULL,
AMOUNT_TYPE CHAR (1) NOT NULL,
ACTIVE CHAR (1) DEFAULT 'T' NOT NULL,
SOURCE CHAR (1),
CUT CHAR (1),
DESCRIPTION VARCHAR2 (180),
CAP_ITEM_ID NUMBER,
PBT_ID NUMBER,
BILL_ID NUMBER,
CREATED_ON DATE DEFAULT SYSDATE NOT NULL,
CREATED_BY NUMBER NOT NULL,
UPDATED_ON DATE DEFAULT SYSDATE NOT NULL,
UPDATED_BY NUMBER NOT NULL,
CHECK (ACTIVE IN ('T','F') ) ,
CHECK (CUT IN ('C',NULL) ),
CONSTRAINT BUDGET_LINE_PRI
PRIMARY KEY ( BUDGET_LINE_ID ) ) ;
CREATE TABLE BUDGET_COST (
BUDGET_LINE_ID NUMBER NOT NULL,
PERIOD_ID NUMBER NOT NULL,
AMOUNT NUMBER (13,2),
CONSTRAINT BUDGET_COST_PRI
PRIMARY KEY ( BUDGET_LINE_ID, PERIOD_ID ) ) ;
CREATE TABLE GL_CODE_TEMP (
BUDGET_LINE_ID NUMBER NOT NULL,
SPENDER CHAR (5),
ACCT CHAR (7),
GL_CODE_COMBO_ID NUMBER,
CONSTRAINT GL_CODE_TEMP_BDGT_ID
PRIMARY KEY ( BUDGET_LINE_ID ) ) ;Thanks for the reply .. user do have their user credentials but only for the application ... but all users use a common loader and control file once they log into the application. So irrespective of which user is logged in he selects the same control file and loads to the same table mentioned in the control file .. i instead want user to be able to load to the table in control file but into his schema like username.tablename instead of just the tablename mentioned in .ctl file.
-
Form Validation on Complex Primary Key
I have a that inserts/updates a table with a 2 coulmn primary key (ticket_num, ticket_seq). Is there anyway to create a page validation item that will keep users from violating the pk constraint and getting the ugly ORA-00001 error.
I think I just don't understand the syntax of the "SQL Expression" validation.
I would like to just find if the key already exists, but the following does not seem to catch it. I have put the following in validation expression 1.
(select count(*)
from system_issue_timings
where ticket_num = :P3_TICKET_NUM
and ticket_seq = :P3_TICKET_SEQ) > 0The pl/sql with count(*) above will not work as select count(*) into... will never raise no_data_found, it will result in zero in v_test.
The other thing to watch out for on this type of validation (whether implemented as sql not exists or as a pl/sql returning boolean or pl/sql returning error) is that if you are doing updates on this page then you need to either :
1. not fire the validation when updating (assuming you cannot modify the primary key columns on the page), or
2. specifically exclude the row being updated from the validation lookup (using rowid for example) as otherwise it will satisfy the condition and fail the validation.
You want to probably use 'sql NOTexists' validation as it "Passes if the query return no rows." :
select 1
from system_issue_timings
where ticket_num = :P3_TICKET_NUM
and ticket_seq = :P3_TICKET_SEQ
Glen
Edited by: gjmorris on Sep 24, 2008 1:02 PM - added actual solution. -
How to Create primary key index with duplicate rows.
Hi All,
While rebuilding an index on a table , I am getting error that there are duplicate rows in a table.
Searching out the reason led me to an interesting observation.
Please follow.
SELECT * FROM user_ind_columns WHERE table_name='SERVICE_STATUS';
INDEX_NAME TABLE_NAME COLUMN_NAME COLUMN_POSITION COLUMN_LENGTH CHAR_LENGTH DESCEND
SERVICE_STATUS_PK SERVICE_STATUS SUBSCR_NO_RESETS 2 22 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS STATUS_TYPE_ID 3 22 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS ACTIVE_DT 4 7 0 ASC
SERVICE_STATUS_PK SERVICE_STATUS SUBSCR_NO 1 22 0 ASC
SELECT index_name,index_type,table_name,table_type,uniqueness, status,partitioned FROM user_indexes WHERE index_name='SERVICE_STATUS_PK';
INDEX_NAME INDEX_TYPE TABLE_NAME TABLE_TYPE UNIQUENESS STATUS PARTITIONED
SERVICE_STATUS_PK NORMAL SERVICE_STATUS TABLE UNIQUE VALID NO
SELECT constraint_name ,constraint_type,table_name,status,DEFERRABLE,DEFERRED,validated,index_name
FROM user_constraints WHERE constraint_name='SERVICE_STATUS_PK';
CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME STATUS DEFERRABLE DEFERRED VALIDATED INDEX_NAME
SERVICE_STATUS_PK P SERVICE_STATUS ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED SERVICE_STATUS_PK
1. Using index scan:
SELECT COUNT (*)
FROM (SELECT subscr_no, active_dt, status_type_id, subscr_no_resets
FROM service_status
GROUP BY subscr_no, active_dt, status_type_id, subscr_no_resets
HAVING COUNT (*) > 1) ;
no rows returned
Explain plan:
Operation OBJECT Name ROWS Bytes Cost OBJECT Node IN/OUT PStart PStop
SELECT STATEMENT Optimizer MODE=CHOOSE 519 K 14756
FILTER
SORT GROUP BY NOSORT 519 K 7 M 14756
INDEX FULL SCAN ARBOR.SERVICE_STATUS_PK 10 M 158 M 49184
2. Using Full scan:
SELECT COUNT (*)
FROM (SELECT /*+ full(s) */ subscr_no, active_dt, status_type_id, subscr_no_resets
FROM service_status s
GROUP BY subscr_no, active_dt, status_type_id, subscr_no_resets
HAVING COUNT (*) > 1) ;
71054 rows returned.
Explain Plan:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 1 24123
SORT AGGREGATE 1
VIEW 519 K 24123
FILTER
SORT GROUP BY 519 K 7 M 24123
TABLE ACCESS FULL ARBOR.SERVICE_STATUS 10 M 158 M 4234
Index SERVICE_STATUS_PK is a unique and composite primary key VALID index. And the constraint is ENABLED and VALIDATED still having duplicate rows in table.
How it is possible?
Is it an Oracle soft Bug??
Regards,
Saket Bansalsaket bansal wrote:
Values are inserted as single rows inserts through an GUI interface.And you still claim to have over 71K duplicate records, without the GUI getting any kind of errors?
That does not add up and can only be explained by a "bug".
I tried inserting a duplicate record but failed.
SQL> insert into service_status (select * from service_status where rownum <2);
insert into service_status (select * from service_status where rownum <2)
ERROR at line 1:
ORA-00001: unique constraint (ARBOR.SERVICE_STATUS_PK) violatedAre you really sure there is no other way data in this table is populated/manipulated in bulk? -
My problem is this: I have data in a couple of temporary tables including
relations (one table referencing records from another table by using
temporary keys).
Next, I would like to insert the data from the temp tables to my productive tables which have the same structure but their own identity keys. Hence, I need to translate the 'temporary' keys to regular identity keys in my productive tables.
This is even more difficult because the system is highly concurrent, i.e. multiple sessions may try to insert
data that way simultaneously.
So far we were running the following solution, using a combination of
identity_insert and ident_current:
create table doc(id int identity primary key, number varchar(100))
create table pos (id int identity primary key, docid int references doc(id), qty int)
create table #doc(idx int, number varchar(100))
create table #pos (docidx int, qty int)
insert #doc select 1, 'D1'
insert #doc select 2, 'D2'
insert #pos select 1, 10
insert #pos select 1, 12
insert #pos select 2, 32
insert #pos select 2, 9
declare @docids table(ID int)
set identity_insert doc on
insert doc (id,number)
output inserted.ID into @docids
select ident_current('doc')+idx,number from #doc
set identity_insert doc off
-- Since scope_identity() is not reliable, we get the inserted identity values this way:
declare @docID int = (select min(ID) from @docids)
insert pos (docid,qty) select @docID+docidx-1, qty from #pos
Since the request to ident_current() is located directly in the insert statement, we always have an implicit transaction which should be thread safe to a certain extend.
We never had a problem with this solution for years until recently when we were running in occasional primary key violations. After some reasearch it turned out, that there were concurrent sessions trying to insert records in this way.
Does anybody have an explanation for the primary key violations or an alternative solution for the problem?
Thank you
David>> My problem is this: I have data in a couple of temporary tables including relations (one table referencing records [sic] from another table by using temporary keys [sic]). <<
NO, your problem is that you have no idea how RDBMS and SQL work.
1. Rows are not anything like records; this is a basic concept.
2. Temp tables are how old magnetic tape file mimic scratch tapes. SQL programmers use CTEs, views, derived tables, etc.
3. Keys are a subset of attributes of an entity, fundamental characteristics of them! A key cannot be temporary by definition.
>> Next, I would like to insert the data from the temp tables to my production tables which have the same structure but their own IDENTITY keys. Hence, I need to translate the 'temporary' keys to regular IDENTITY keys in my productive tables. <<
NO, you just get worse. IDENTITY is a 1970's Sybase/UNIX dialect, based on the sequential file structure used on 16-bit mini computers back then. It counts the physical insertion attempts (not even successes!) and has nothing to with a logical data model. This
is a mag tape drive model of 1960's EDP, and not RDBMS.
>> This is even more difficult because the system is highly concurrent, i.e. multiple sessions may try to insert data that way simultaneously. <<
Gee, that is how magnetic tapes work, with queues. This is one of many reasons competent SQL programers do not use IDENTITY.
>> So far we were running the following solution, using a combination of IDENTITY_INSERT and IDENT_CURRENT: <<
This is a kludge, not a solution.
There is no such thing as a generic “id” in RDBMS; it has to be “<something in particular>_id” to be valid. You have no idea what the ISO-11179 rules are. Even worse, your generic “id” changes names from table to table! By magic, it starts as a “Doc”,
then becomes a “Pos” in the next table! Does it wind up as a “doc-id”? Can it become a automobile? A squid? Lady Gaga?
This is the first principle of any data model; it is based on the Law of Identity; remember that from Freshman Logic 101? A data element has one and only one name in a model.
And finally, you do not know the correct syntax for INSERT INTO, so you use the 1970's Sybase/UNIX dialect! The ANSI/ISO Standard uses a table consrtuctor:
INSERT INTO Doc VALUES (1, 'D1'), (2, 'D2');
>> We never had a problem with this solution for years until recently when we were running in occasional PRIMARY KEY violations. After some research it turned out, that there were concurrent sessions trying to insert records [sic] in this way. <<
“No matter how far you have gone down the wrong road, turn around.” -- Turkish proverb.
You have been mimicking a mag tape file system and have not written correct SQL. It has caught up with you in a way you can see. Throw out this garbage and do it right.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
FillSchema picks too many primary key columns
I don't know whether this is an ODP.NET error or a Microsoft error.
Oracle9i Release 9.2.0.1.0
ODP.NET 9.2.0.4
.NET Framework 1.1
Create a table with one primary key column and one unique column and name the primary key column like the unique column with the suffix "_ID":
CREATE TABLE t_bib_uebertrag_kap(
  kapazitaet_id NUMBER(8) NOT NULL
   CONSTRAINT pk_kapa primary key,
  kapazitaet VARCHAR2(15) NOT NULL
   CONSTRAINT a_un_kapa unique,
  geschwindigkeit NUMBER(12) NOT NULL,
  bemerkung VARCHAR2(255)
After calling FillSchema on this table the PrimaryKey property of the DataTable contains 2 columns: KAPAZITAET_ID and KAPAZITAET.
The same happens with other tables and similar column names
R. LüthkeTony, I'm gonna find time to try this because I was thinking it probably would be a double check.
BUT... Oracle is written in C, and I imagine the extra check as a simple if comparison for the new value versus a constant NULL value. Kind of like checking for end of string. It's already doing things like checking datatypes and that as it inserts data, and I don't think this additional check (if it even exists) would add any significant overhead.
But unless I find a much larger performance hit than I expect, I'm gonna stick with creating the NOT NULL's explicitly. Good data modelling trumps small performance tricks for me.
My main worry is if/when somebody removes the primary key constraint (such as the example above where they might do a CREATE TABLE x AS SELECT * FROM y). Or if the data model gets updated to where the primary key becomes just a unique key, then the NOT NULL goes away when it shouldn't. I don't like basic table and column properties changing.
Okay.. test done. Ran about 31,000 records from dba_tables through an insert into two tables, both with primary keys and one with explicit NOT NULLs. No measurable difference in stats detected.
With NOT NULL and PRIMARY KEY:
call count cpu elapsed disk query current rows
Parse 1 0.35 0.35 0 0 0 0
Execute 1 1.88 1.83 0 24792 35887 30954
Fetch 0 0.00 0.00 0 0 0 0
total 2 2.24 2.18 0 24792 35887 30954
Now with only PRIMARY KEY.
call count cpu elapsed disk query current rows
Parse 1 0.37 0.36 0 0 0 0
Execute 1 1.87 1.83 0 24792 35887 30954
Fetch 0 0.00 0.00 0 0 0 0
total 2 2.24 2.19 0 24792 35887 30954 -
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
Hi,
I am trying to delete data from a table by dropping a partition. I have identified all the child tables by running the following command.
select 'select count(*) from '||table_name||' where employee_id = 100;'
from dba_constraints
where constraint_type='R'
and r_constraint_name in
(select constraint_name from dba_constraints
where constraint_type in ('P','U') and table_name='EMPLOYEE);
'SELECTCOUNT(*)FROM'||TABLE_NAME||'WHEREEMPLOYEE_ID_ID=100;'
select count(*) from PT_ORDERS where employee_id = 100;
select count(*) from PT_DEP where employee_id = 100;
select count(*) from PT_SKILLSET where employee_id = 100;
I dropped the partition for employee_id 100 in all of the child tables. The select count(*) returns 0 rows for each of the above.
When I try to run the below command on the EMPLOYEE table, I get 'ORA-02266: unique/primary keys in table referenced by enabled foreign keys'.
alter table EMPLOYEE drop partition EMP_ID_100;
I cant see why I am unable to drop this partition now as there is now child data in any of the referenced tables. Any suggestions or help on this would be greatly appreciated.
Thanks.
Rgs,
RobYou should disable foreign key constraints first and drop partition. Deletion of rows or dropping partitions in childs don't work in this case
as you have the global dependency:
<PRE>
SQL> create table scott.t (x int primary key, y int)
2 partition by list (y) (
3 partition p_1 values(1), partition p_2 values(2))
4 /
Table created.
SQL> create table scott.t_c (x int references scott.t(x), y int)
2 partition by list (y) (
3 partition p_1 values(1), partition p_2 values(2))
4 /
Table created.
SQL> insert into scott.t values(1,1)
2 /
1 row created.
SQL> insert into scott.t values(2,2)
2 /
1 row created.
SQL> insert into scott.t_c values(1,1)
2 /
1 row created.
SQL> insert into scott.t_c values(2,2)
2 /
1 row created.
SQL> commit;
Commit complete.
SQL> alter table scott.t_c drop partition p_2;
Table altered.
SQL> alter table scott.t drop partition p_2;
alter table scott.t drop partition p_2
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
SQL> select constraint_name from dba_constraints
2 where owner = 'SCOTT' and constraint_type = 'P'
3 and table_name = 'T';
CONSTRAINT_NAME
SYS_C0011058
SQL> select constraint_name from dba_constraints
2 where owner = 'SCOTT' and constraint_type = 'R'
3 and r_constraint_name = 'SYS_C0011058';
CONSTRAINT_NAME
SYS_C0011059
SQL> alter table scott.t_c disable constraint SYS_C0011059;
Table altered.
SQL> alter table scott.t drop partition p_2;
Table altered.
SQL> alter table scott.t_c enable novalidate constraint SYS_C0011059;
Table altered.
</PRE>
I guess you should consider such option as Referencial partitioning (with some restrictions).
Best wishes,
Dmitry. -
Add a primary key to table.
Hello everybody,
I want to add a primary key to a table but it doesn't work.
select count(*), count(id) from tableA;
COUNT(*) COUNT(ID)
830447 830447
You see: The number of ids is equal to the number of rows. The ID is not marked as unique but it should be unique. I try to set id as the primary key:
alter table tableA add constraint "pk_constraint" PRIMARY KEY (id);
But I a get an error message: ORA-02437: cannot validate (pk_constraint) - primary key violated.
What is the problem?
I use Oracle 11g.user9206958 wrote:
Hello everybody,
I want to add a primary key to a table but it doesn't work.
select count(*), count(id) from tableA;
COUNT(*) COUNT(ID)
830447 830447
You see: The number of ids is equal to the number of rows. The ID is not marked as unique but it should be unique. I try to set id as the primary key:
alter table tableA add constraint "pk_constraint" PRIMARY KEY (id);
But I a get an error message: ORA-02437: cannot validate (pk_constraint) - primary key violated.
What is the problem?
I use Oracle 11g.Revisit your query... 11g can help much in this sql.... select count(*), count(id) from tableA;... to get what your desired output should be.
Edited by: Z.K. on Mar 30, 2010 1:15 PM -
SQLLDR direct path allows duplicates in primary key
I would like to use sqlldr direct path to load millions of records in the table but direct path allows duplicates on the primary key constraints.
inserts duplicates
sqlldr deploy_ctl/deploy_ctl@dba01mdm control=ctl_test.ctl direct=true
primary key is enabled
I am not understanding the behavior that why primary key is still enabled -- (logically it should have disabled than inserted duplicates)
does not insert duplicates
sqlldr deploy_ctl/deploy_ctl@dba01mdm control=ctl_test.ctl
primary key is enabled
Please can I know if there is any work around to use direct path with primary constraints in place.Dear,
Look at the following example
mhouri.world> drop table t1;
Table dropped.
mhouri.world> create table t1 (id number);
Table created.
mhouri.world> alter table t1 add constraint t1_pk primary key (id);
Table altered.
mhouri.world> select table_name, index_name, status
2 from user_indexes
3 where table_name = 'T1';
TABLE_NAME INDEX_NAME STATUS
T1 T1_PK VALID
mhouri.world> select count(1) from t1;
COUNT(1)
0 and here call sqlldr
C:\>sqlldr xxx/xxx@xxxx control=c.ctl bad=c.bad direct=trueAnd see what happen to the primary key index
mhouri.world> select count(1) from t1;
COUNT(1)
4
mhouri.world> select * from t1;
ID
1
2
2
3
mhouri.world> select table_name, index_name, status
2 from user_indexes
3 where table_name = 'T1';
TABLE_NAME INDEX_NAME STATUS
T1 T1_PK UNUSABLE
mhouri.world> alter index t1_pk rebuild;
alter index t1_pk rebuild
ERROR at line 1:
ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found The primary key index is made unusable and this is why you have duplicate records
best regards
Mohamed Houri -
create table SEN_TEMP
E_NO NUMBER not null,
E_NAME VARCHAR2(50),
E_TEAM VARCHAR2(50)
insert into sen_temp (E_NO, E_NAME, E_TEAM)
values (1, 'A1', 'T1')
insert into sen_temp (E_NO, E_NAME, E_TEAM)
values (2, 'A2', 'T2')
insert into sen_temp (E_NO, E_NAME, E_TEAM)
values (3, 'A3', 'T3')
Executing the Below
SELECT *
FROM sen_temp
where rownum = 1
order by e_no desc;
Output
E_NO E_NAME E_TEAM
1 A1 T1
Now am Gng to Add a Primary Key Constraint On the Column E_no
alter table sen_temp add constraint pk_e_no primary key (e_no)
Now Am Executing the Same query
SELECT *
FROM sen_temp
where rownum = 1
order by e_no desc
But the
Output Is
E_NO E_NAME E_TEAM
3 A3 T3
Can Anyone Tell me, the way how the primary key is affecting the querySen wrote:
k den, why its returning e-no as 3 after adding a primary key..Most likely the execution plan has changed due to the addition of the primary key. See my example below:
SQL> create table SEN_TEMP
2 (
3 E_NO NUMBER not null,
4 E_NAME VARCHAR2(50),
5 E_TEAM VARCHAR2(50)
6 )
7 /
Table created.
SQL> insert into sen_temp (E_NO, E_NAME, E_TEAM)
2 values (1, 'A1', 'T1')
3 /
1 row created.
SQL> insert into sen_temp (E_NO, E_NAME, E_TEAM)
2 values (2, 'A2', 'T2')
3 /
1 row created.
SQL> insert into sen_temp (E_NO, E_NAME, E_TEAM)
2 values (3, 'A3', 'T3')
3 /
1 row created.
SQL> SELECT /*+gather_plan_statistics*/ *
2 FROM sen_temp
3 where rownum = 1
4 order by e_no desc;
E_NO E_NAME E_TEAM
1 A1 T1
1 row selected.
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(null,null,'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 8hajz83tnvwnw, child number 0
SELECT /*+gather_plan_statistics*/ * FROM sen_temp where rownum = 1
order by e_no desc
Plan hash value: 3862566870
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 3 | | | |
| 1 | SORT ORDER BY | | 1 | 1 | 1 |00:00:00.01 | 3 | 73728 | 73728 | |
|* 2 | COUNT STOPKEY | | 1 | | 1 |00:00:00.01 | 3 | | | |
| 3 | TABLE ACCESS FULL| SEN_TEMP | 1 | 3 | 1 |00:00:00.01 | 3 | | | |
Predicate Information (identified by operation id):
2 - filter(ROWNUM=1)
Note
- dynamic sampling used for this statement (level=2)
25 rows selected.
SQL> alter table sen_temp add constraint pk_e_no primary key (e_no)
2 /
Table altered.
SQL> SELECT /*+gather_plan_statistics*/ *
2 FROM sen_temp
3 where rownum = 1
4 order by e_no desc;
E_NO E_NAME E_TEAM
3 A3 T3
1 row selected.
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(null,null,'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 8hajz83tnvwnw, child number 0
SELECT /*+gather_plan_statistics*/ * FROM sen_temp where rownum = 1
order by e_no desc
Plan hash value: 577902443
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 2 |
|* 1 | COUNT STOPKEY | | 1 | | 1 |00:00:00.01 | 2 |
| 2 | TABLE ACCESS BY INDEX ROWID| SEN_TEMP | 1 | 3 | 1 |00:00:00.01 | 2 |
| 3 | INDEX FULL SCAN DESCENDING| PK_E_NO | 1 | 1 | 1 |00:00:00.01 | 1 |
Predicate Information (identified by operation id):
1 - filter(ROWNUM=1)
Note
- dynamic sampling used for this statement (level=2)
25 rows selected.See how in the first case Oracle did a full table scan and in the second case it used an index? That's why your results are different.
Maybe you are looking for
-
Error in SQL Statement (ODS data loading Error)
Hello Gurus... I am trying to loading the data Info Source To ODS in my ODS Key Figure Z_IVQUA (Invoice Quantity) is getting the Error Message Data shows 0 from 0 Records. I was Remove the Key Field from ODS Then try to load the data but i am getting
-
Unresponsive iMac 27" i3 had to be unplugged it before I could reboot. What's up?
My iMac 27" i3 wouldn't wake from sleep this morning and wouldn't boot with the power button until I unplugged it and replugged it. What gives? This has never happened before. Should I be worried?
-
It's time to regale you all again with my overly-annoying basic questions! according to Lenovo, my T500 is 'Mobile broadband ready'. Does this mean I can shove in any WWAN card and expect it to work? Or will only the Lenovo-supplied cards (like the o
-
PC suite problems with 6280 & 6270
i have Pc suite 6.84.10.3 on windows XP , use the cable as a connection .. PC suite fails to download applications of a size more than 1MB into nokia 6280 & 6270 eventhough i load it into the memory card where there's enough free memory .. Help Pleas
-
How do I uninstall the HP 6500 completely
I have a HP 6500 E709n wireless printer that I have tried to install on my computer running Vista X64 OS and I have been unsuccessful. I have more problems trying to get it installed than I could possibly mention. What I want to do is completely unin