Check duplicate record all by preventing insertion
Hello
I have a scenario where I need to insert records from 20 000 to 30 000 daily in a table that has data in millions.
Keep inserting a record in duplicate and in the event of any duplicate record, this issue need to be logged in another table.
I used FORALL except SAVE to allow loading of all records not not duplicate. But with this approach, I am unable to know which record was duplicate or problems in the insertion.
Also I can't use triggers to connect each record before insertion because I only need the duplicate records. Also, trigger will slow down performance.
Guide kindly on what approach I should follow to do this (which are also good performance as data are huge).
Kind regards
Karki
Logging error clause does not support dyrect path operations, you must remove the Add indicator to use.
This is because the logging of errors using autonomous transaction.
create table test_tomkt_raw (c1 varchar2(20), c2 varchar2(20), c3 varchar2(20)); Table created Executed in 0,015 seconds create table test_mkt (c1 varchar2(20), c2 varchar2(20), c3 varchar2(20)); Table created Executed in 0,031 seconds create table test_mkt_log (c1 varchar2(20), c2 varchar2(20), c3 varchar2(20)); Table created Executed in 0,078 seconds insert into test_tomkt_raw VALUES( 'A','B','C'); 1 row inserted Executed in 0,015 seconds insert into test_tomkt_raw VALUES( 'A','B','C'); 1 row inserted Executed in 0 seconds insert into test_tomkt_raw VALUES( 'D','E','F'); 1 row inserted Executed in 0 seconds insert into test_tomkt_raw VALUES( 'R','BD','AC'); 1 row inserted Executed in 0 seconds insert into test_tomkt_raw VALUES( 'AQ','SB','AC'); 1 row inserted Executed in 0,016 seconds insert into test_tomkt_raw VALUES( 'AA','BA','CA'); 1 row inserted Executed in 0 seconds insert into test_tomkt_raw VALUES( 'A','B','C'); 1 row inserted Executed in 0 seconds insert into test_tomkt_raw VALUES( 'D','E','F'); 1 row inserted Executed in 0,016 seconds ALTER TABLE test_mkt ADD PRIMARY KEY (C1,C2,C3); Table altered Executed in 0,015 seconds BEGIN DBMS_ERRLOG.CREATE_ERROR_LOG('test_mkt'); END; / PL/SQL procedure successfully completed Executed in 0,031 seconds INSERT /* APPEND */ INTO TEST_MKT SELECT * FROM TEST_TOMKT_RAW LOG ERRORS INTO ERR$_TEST_MKT ('TEST_01') --> This can be a variable on your code to identify this operation REJECT LIMIT UNLIMITED ; 5 rows inserted Executed in 0,063 seconds INSERT INTO test_mkt_log SELECT er.c1, er.c2, er.c3 FROM ERR$_TEST_MKT er WHERE er.ora_err_tag$ = 'TEST_01'--> This can be a variable on your code AND er.ora_err_number$ = 1 --> Unique constraint violated ; 3 rows inserted Executed in 0 seconds SELECT * FROM TEST_MKT ; C1 C2 C3 -------------------- -------------------- -------------------- A B C AA BA CA AQ SB AC D E F R BD AC Executed in 0,062 seconds SELECT * FROM TEST_MKT_LOG ; C1 C2 C3 -------------------- -------------------- -------------------- A B C A B C D E F Executed in 0,047 seconds DROP TABLE test_tomkt_raw; Table dropped Executed in 0,032 seconds DROP TABLE test_mkt; Table dropped Executed in 0,094 seconds DROP TABLE err$_test_mkt; Table dropped Executed in 0,078 seconds DROP TABLE test_mkt_log; Table dropped Executed in 0,047 seconds
Tags: Database
Similar Questions
-
Miss an Interface if duplicate records present
Hi all
I'm using ODI 11 g.
I have the flat file interface table where I use IKM as control SQL added, check validation Option, Insert, separate and truncate option as TRUE, control flows as FALSE.
In my case, suppose I have 10 records out of these 2 records are duplicated. So my interface treats 8 discs to the next level.
But I want to the failure of the interface if there is duplicate records.
How to do this?
Thank you
LonyA set the primary key in the database or ODI?
Do it in the database if you wish to fail before inserting.
Do it in ODI and turn control static to true if you want to than his failure after insertion.Kind regards
JeromeFr -
Matching records between 2 tables with duplicate records
Hi all
I need help in what follows.
I have 2 tables Received_bills and Send_bills.
-------------------------------------------------------
-The DOF for Table SEND_BILLS
--------------------------------------------------------
CREATE TABLE SEND_BILLS
(DATE OF "DATUM",
NUMBER OF "PAYMENT."
'CODE' VARCHAR2 (5 BYTE)
) ;
--------------------------------------------------------
-The DOF for Table RECEIVED_BILLS
--------------------------------------------------------
CREATE TABLE 'RECEIVED_BILLS '.
(DATE OF "DATUM",
NUMBER OF "PAYMENT."
'CODE' VARCHAR2 (5 BYTE),
VARCHAR2 (5 BYTE) 'STATUS' ) ;
INSERTION of REM in RECEIVED_BILLS
TOGETHER TO DEFINE
Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');
INSERTION of REM in SEND_BILLS
TOGETHER TO DEFINE
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');
I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.
Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results
the query I wrote is this:
SELECT SEND.*
REC received_bills, send_bills send
WHERE send.datum = rec.datum
AND send.payment = rec.payment
AND send.code = rec.code
AND 'rec.status =' SUCCESS
;
The query results give me this
OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 25 A5 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 25 A5 The result of the correct application would be
OCTOBER 10, 15 19 A1 OCTOBER 10, 15 25 A5 OCTOBER 10, 15 19 A1 The select statement that I need I want to use a loop to insert records in another table.
Can someone help me please?
Thanks in advance.
Best regards
Caroline
Hi, Caroline.
Caroline wrote:
Hi all
I need help in what follows.
I have 2 tables Received_bills and Send_bills.
-------------------------------------------------------
-The DOF for Table SEND_BILLS
--------------------------------------------------------
CREATE TABLE SEND_BILLS
(DATE OF "DATUM",
NUMBER OF "PAYMENT."
'CODE' VARCHAR2 (5 BYTE)
) ;
--------------------------------------------------------
-The DOF for Table RECEIVED_BILLS
--------------------------------------------------------
CREATE TABLE 'RECEIVED_BILLS '.
(DATE OF "DATUM",
NUMBER OF "PAYMENT."
'CODE' VARCHAR2 (5 BYTE),
VARCHAR2 (5 BYTE) 'STATUS');
INSERTION of REM in RECEIVED_BILLS
TOGETHER TO DEFINE
Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');
Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');
INSERTION of REM in SEND_BILLS
TOGETHER TO DEFINE
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');
Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');
I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.
Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results
the query I wrote is this:
SELECT SEND.*
REC received_bills, send_bills send
WHERE send.datum = rec.datum
AND send.payment = rec.payment
AND send.code = rec.code
AND 'rec.status =' SUCCESS
;
The query results give me this
OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 25 A5 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 19 A1 OCTOBER 10, 15 25 A5 The result of the correct application would be
OCTOBER 10, 15 19 A1 OCTOBER 10, 15 25 A5 OCTOBER 10, 15 19 A1 The select statement that I need I want to use a loop to insert records in another table.
Can someone help me please?
Thanks in advance.
Best regards
Caroline
Want to get answers that work? Then make sure that the CREATE TABLE and INSERT statements you post too much work. Test (and, if necessary, correct) your statements before committing. You have a stray "." in the first INSERT statement for received_bills and receikved_bills.status is defined as VARCHAR2 (5), but all values are 6 characters long.
There are 5 lines in send_bills that are similar to the
10 OCTOBER 2015 19 A1
Why do you want that 2 rows like this in the output, not 1 or 3, or 4 or 5? Is it because there are 2 matching rows in received_bills? If so, you can do something like this:
WITH rec AS
(
SELECT the reference, payment, code
, ROW_NUMBER () OVER (PARTITION BY datum, payment, code)
ORDER BY NULL
) AS r_num
OF received_bills
Situation WHERE = 'SUCCESS'
)
send AS
(
SELECT the reference, payment, code
, ROW_NUMBER () OVER (PARTITION BY datum, payment, code)
ORDER BY NULL
) AS r_num
OF send_bills
)
SELECT send.datum, send.payment, send.code
REC, send
WHERE send.datum = rec.datum
AND send.payment = rec.payment
AND send.code = rec.code
AND send.r_num = rec.r_num
;
Note that the main request is very similar to the query you posted, but the last condition has changed.
If you need to insert these lines in another table, you can use this query in an INSERT statement. There is no need of a loop, or for any PL/SQL.
-
Removal of duplicate records: (please respond to it ::))
Hi experts I'm new to the oracle. Me please with this deletion request.
Whenever the mobileno TEST_REG , TEST_MUL matches then it should check for accountno gets duplicated in the TEST_MUL table.
If duplicate accounts exist for this particular mobileno
Then delete this duplicate accountno, whose IDS are not equal in both the
tables (accountno recordings should get deleted from the test_mul table)
Published by: 980560 on January 26, 2013 19:56Script For the query : --------------------- create table test_mul (mobileno VARCHAR2 (20 Byte),accountno VARCHAR2 (20 Byte),id VARCHAR2 (12 Byte),v_date date); create table test_reg (mobileno VARCHAR2 (20 Byte),id VARCHAR2 (12 Byte),r_date date,mas varchar2(1) default 'Y'); alter table test_mul modify v_date default sysdate; alter table test_reg modify r_date default sysdate; Insertion of records into test_reg table : insert into test_reg (mobileno,id) values ('+227299001081','AAA'); insert into test_reg (mobileno,id) values ('+911000000001','BBB'); insert into test_reg (mobileno,id) values ('+911000000002','CCC'); insert into test_reg (mobileno,id) values ('+911000000005','DDD'); insert into test_reg (mobileno,id) values ('+911000000006','EEE'); insert into test_reg (mobileno,id) values ('+911000000007','FFF'); commit; ================================================================== INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','37775521122561','AAA'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','37775521122561','123'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','43443345432344','AAA'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','43443345432344','AAA'); ------------------------------ INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100005169','BBB'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100006867','BBB'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100009602','BBB'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100009602','456'); --------------------------------- INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000005','47775524511505','DDD'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000002','47775521111505','DDD'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000002','47775524511505','789'); ------------------------------- INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000006','47775545611506','EEE'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000006','47775521111506','EEE'); -------------------------------- INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000007','47987521111507','FFF'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000007','47775521111507','FFF'); INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000007','47775521111507','987'); commit;
Question is what you want to do when:
SQL> select * 2 from test_reg 3 / MOBILENO ID R_DATE M -------------------- ------------ --------- - +227299001081 AAA 27-JAN-13 Y +227299001081 BBB 27-JAN-13 Y SQL> select * 2 from test_mul 3 / MOBILENO ACCOUNTNO ID V_DATE -------------------- -------------------- ------------ --------- +227299001081 37775521122561 AAA 27-JAN-13 +227299001081 37775521122561 BBB 27-JAN-13 +227299001081 43443345432344 AAA 27-JAN-13 +227299001081 43443345432344 BBB 27-JAN-13 SQL>
Or when:
SQL> select * 2 from test_reg 3 / MOBILENO ID R_DATE M -------------------- ------------ --------- - +227299001081 AAA 27-JAN-13 Y SQL> select * 2 from test_mul 3 / MOBILENO ACCOUNTNO ID V_DATE -------------------- -------------------- ------------ --------- +227299001081 37775521122561 AAA 27-JAN-13 +227299001081 37775521122561 BBB 27-JAN-13 +227299001081 43443345432344 AAA 27-JAN-13 +227299001081 43443345432344 BBB 27-JAN-13 SQL>
SY.
-
Satellite L750 / 04K keyboard do not record all keystrokes
I just bought a laptop L750 / 04K, but the keyboard does not seem to record all keystrokes.
Often you must press space of once or twice, or other keys as well.It doesn't matter how fast or slow I type it occurs randomly.
Any help to fix this would be greatly appreciated.
I use windows 7 64-bit mode.
Hey Buddy,
Have you noticed the same behavior with external keyboard? Probably only the internal keyboard is faulty and so not all of the keys will be recognized.
Also check the current version of BIOS and have a look at the official website of Toshiba for an update:
But if an external keyboard works properly the internal keyboard needs to be replaced. Lifetime warranty valid it can be done free of charge of an authorized service.
Check this box!
-
HDR-CX240... How can I get the camera to record all FILES VIDEO in MP4 format. Is this possible? I can't find how to change what default file to save to. Any help would be appreciated.
Hi dang201,
There is no option to save the video in mp4 format only. You can check on the MProot folder on your memory card for mp4 files. The. MTS files are normally saved in another folder called flow.
If my post answered your question, please mark it as "accept as a Solution.
-
My computer is no longer automatically recognizes all the devices inserted in the disks.
My computer is no longer automatically recognizes all the devices inserted into readers, like a CD or SD card photo. Recently I bought a micro sd card for my phone, but when I insert in the USB port, it recognizes that no more. How to do that everything works again. I have XP Service Pack 2
Hi Danny Bralski,-Did you change on your computer before this problem?Follow the steps listed in the order.Method 1: Check if the USB port is defective.
If you connect a USB device to a defective port, the device will not work. Try connecting the device to a different port. If all USB ports are in use, disconnect one of the other devices and plug the problematic device into that port.
Method 2: Check if there is a problem with the device.
If you have another computer that is working properly, plug this computer to see if you encounter the same problem. If you have the same problem, there could be a problem with the unit.
If you believe that your device is defective, contact the manufacturer.
Method 3: Run the troubleshooter from the link given below:
-
APEX 5.0 Export to CSV produces duplicate records
Good day to you all:
I use APEX 5.0, and I have a classic report that has a total number of lines of 274. (274 documents also in SQL Developer). However, when I export the report to CSV, duplicate records are produced and the total number of lines increases to 365. Has anyone already known this before bug in APEX 5.0? I tried to reproduce the report to a type of interactive, but I get the same results when you export to CSV. Advice or guidance would be appreciated. Thank you.
Aqua
Hey Aqua,
If you are APEX 5.0.0 or 5.0.1? And which version of the database, you are on?
There was a problem with CLOB (which are used for the download) in 5.0.0 running on specific versions of 11 GR 2. A fix is included in the 5.0.1 patch set.
Concerning
Patrick
-
Hi gurus of the Oracle,.
Good morning/afternoon/evening!
There are several methods to effectively identify duplicate records. e.g. row_number() and group by, but all of these methods to highlight the duplicate record only. Which means that if your table has data such as
ID Name Room Date 1 ABC 203 20/07/2015 2 FGH 109 20/09/2015 3 HSF 202 20/08/2015 4 REF 201 20/08/2015 5 FGH 109 20/09/2015 6 HSF 291 24/08/2015 And I want to find duplicates based on name/room/day
Most of the queries will give me
Or the other
ID Name Room Date 5 FGH 109 20/09/2015 or
ID Name Room Date 2 FGH 109 20/09/2015
They don't give me two files unless I first do a group by (or Row_Number) in an internal query and then try to get the two lines in the outer query. In my view, should not be the way.
I need a report which highlights the two records only
ID Name Room Date 2 FGH 109 20/09/2015 5 FGH 109 20/09/2015 Hope that is clear.
Thanks in advance!
Hello
34MCA2K2 wrote:
Hi gurus of the Oracle,.
Good morning/afternoon/evening!
There are several methods to effectively identify duplicate records. e.g. row_number() and however all these methods to highlight only the duplicate of group by. Which means that if your table has data such as
ID Name Room Date 1 ABC 203 20/07/2015 2 FGH 109 20/09/2015 3 HSF 202 20/08/2015 4 REF 201 20/08/2015 5 FGH 109 20/09/2015 6 HSF 291 24/08/2015 And I want to find duplicates based on name/room/day
Most of the queries will give me
Or the other
ID Name Room Date 5 FGH 109 20/09/2015 or
ID Name Room Date 2 FGH 109 20/09/2015
They don't give me two files unless I first do a group by (or Row_Number) in an internal query and then try to get the two lines in the outer query. In my view, that shouldn't be the way...
Help the ROW_NUMBER analytic function, that you described is probably the easiest and most effective way to get the desired results.
You can do it without using any kind of subquery (for example, with a self-join or CONNECT BY), but which requires SELECT DISTINCT, which is inefficient.
-
Hello
I'm loading data in the ASO cube directly from the text file (without using a buffer) and numbers of duplicate records are added, but I need the numbers since the last duplicate record to overwrite all previous records. Is it possible to implement in Essbase ASO?
You can use the id of the buffer. The 'aggregate_use_last' property can be set to a buffer during initialization it.
I do not belive there is an option to load the file directly using the command "Import database...". "in this situation.
Kind regards
Sunil
-
Remove all lines and insert them into Oracle can make performance worse?
I m working in a project that I need to make a batch update regularly (every 4 months) of excel files. These files have doesn´t excellent key in their ranks.
The development of a code that deletes all lines and inserts the entire base again is easier than one who checks in all the ranks of its primary key and if necessary update. (sometimes may be a key to 5 columns).
My question is: if I delete all the rows in the tables of the insert it again, it will cause tablespace fragmentation and in a future loss of performance?
Is there a way to avoid this?
Thanks in advance
Alexander
This response helped me a lot.
Thank you all
Remove all lines and insert them into Oracle can make performance worse? -Stack overflow
-
Hi all
Employees check and I would check against records carried out in-house, a source of Adobe. In order to ensure that we use not more or less our license (which is a license for 16 users), as an adobe license can be installed on different devices, even it is a single user license.
Thanks in advance.
Best regards
Changpei Hu.
Since this is an open forum, not Adobe support... you must contact Adobe personnel to help
Chat/phone: Mon - Fri 05:00-19:00 (US Pacific Time)Creative cloud support (all creative cloud customer service problems)
http://helpx.Adobe.com/x-productkb/global/service-CCM.html -
Recover duplicate records.
CREATE TABLE TEST (TNO NUMBER (2), TNAME VARCHAR2 (10));
INSERT INTO TEST VALUES (1, 'TIGER');
INSERT INTO TEST VALUES (2, 'SCOTT');
INSERT INTO TEST VALUES (2, 'MILLER');
INSERT INTO TEST VALUES (2, 'JOHN');
INSERT INTO TEST VALUES (3, 'SMITH');
SELECT * FROM TEST;
NWT TNOM
----- ----------
1 TIGER
SCOTT 2
2 MILLER
2 JOHN
3 SMITH
power required:
NWT TNOM
----- ----------
SCOTT 2
2 MILLER
2 JOHN
I want duplicate records.Have you tried the forum search?
How recover duplicate records have been answered several times ;-)select tno, tname from ( select tno, tname, count(*) over (partition by tno) cnt from test ) where cnt > 1
-
ROW_NUMBER and duplicate records
Hello
Tried to delete duplicate records. The code below works, but would remove all, rather than simply the > #1 records:
(SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
course_reference_number, rowid that RID, row_number() over (partition of)
academic_period, load_week, sub_academic_period, person_uid, course_number,
order of course_reference_number of academic_period, load_week, sub_academic_period,
person_uid, course_number, course_reference_number)
Of THE cea
WHERE (academic_period, load_week, sub_academic_period, person_uid, course_number,)
IN course_reference_number)
(SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
course_reference_number
Of THE cea
GROUP of academic_period, load_week, sub_academic_period, person_uid, course_number,
course_reference_number
HAVING COUNT (*) > 1))
If I try to put 'rn' and rn > 1, I get ora-00933: Sql not correctly completed command
SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
course_reference_number, rowid that RID, row_number() over (partition of)
academic_period, load_week, sub_academic_period, person_uid, course_number,
order of course_reference_number of academic_period, load_week, sub_academic_period,
person_uid, course_number, course_reference_number): the nurse
Of THE cea
WHERE (academic_period, load_week, sub_academic_period, person_uid, course_number,)
IN course_reference_number)
(SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
course_reference_number
Of THE cea
GROUP of academic_period, load_week, sub_academic_period, person_uid, course_number,
course_reference_number
After HAVING COUNT (*) > 1)
and rn > 1
I tried to remove as"rn" and make "rn" and "rn", which gave me an error of syntax also. The '' rn > 1 and '' clause gets an error of syntax also. I gone through a bunch of different Web sites. All of this indicates the syntax I am using will work. However, any query I run into a TOAD, always error when I include the 'rn > 1.
Any ideas? Thank you!
VictoriaYou mix two ways to identify duplicates.
One way is HAVING:
SELECT academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number FROM cea GROUP BY academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number HAVING COUNT(*) > 1)
That tells you just what combinations of your group are more than once.
Another way is to analytical functions:
select * from ( SELECT academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number count(*) over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) cnt FROM cea ) where cnt > 1
This will all return duplicate records - if some combinations has three duplicates, then this will return all three lines.
If you use the ROW_NUMBER() place COUNT() analytical analytical function, you get this:
select * from ( SELECT academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number row_number() over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) rn FROM cea ) where rn > 1
All of these files without duplicates will get rn = 1. Those with duplicates gets rn = 1, rn = 2... If rn > 1 Gets all "unnecessary" records - the ones you want to remove.
If a deletion might look like:
delete cea where rowid in ( select rid from ( SELECT ROWID as rid, row_number() over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) rn FROM cea ) where rn > 1 )
Or if you want to manually inspect before you delete ;-):
select * from cea where rowid in ( select rid from ( SELECT ROWID as rid, row_number() over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) rn FROM cea ) where rn > 1 )
In another answer, you can find a way to remove duplicates with HAVING.
The point is that do you it either with or with ROW_NUMBER() - not both HAVING ;-) -
Delete several duplicate records
Hi all
My table has multiple records, and I want to keep only the first record in the table. Can someone help me on this. I tried following things:
SELECT * FROM the tab
WHERE ROWID in (SELECT MAX (ROWID) <>
IN tab B
WHERE B.col1 = A.col1
AND B.col2 = A.col2
)
This remove the last duplicate record.
I also tried
SELECT * FROM the tab
WHERE ROWID > (SELECT MIN (ROWID)
IN tab B
WHERE B.col1 = A.col1
AND B.col2 = A.col2
)
This was removed and the first record to some places, but it has worked in some places. I am not able to understand why it was wrong in some places.
I'm working on Oracle 10 g
Please suggest.
Thank you.Duplicate records mean reproduce according to specific columns (in your example, col1 and col2).
If you want the trial to be held, you must determine all first according to what, if you mean the first entered record (which is not safe, and you should rely on an explicit column).
You can useSELECT * FROM tab A WHERE ROWID NOT IN (SELECT MIN (ROWID) FROM tab B WHERE B.col1 = A.col1 AND B.col2 = A.col2)
or use a column
SELECT * FROM tab A WHERE col3 NOT IN (SELECT MIN (col3) FROM tab B WHERE B.col1 = A.col1 AND B.col2 = A.col2)
Saad,
Maybe you are looking for
-
I have a MacBook Pro (13 inch, mid-2012), 2.9 ghz processor intel core i7, 8 GB of memory, graphics Intel HD Graphics 4000 1536 MB. I upgraded OS to X EL Capitan 10.11.5 worm (15F34), two weeks back. Since then, my laptop gets overheated in a min wh
-
Qosmio G20 - 127 connection with plasma TV
What is the best way to connect the Qosmio G20-127 with plasma Panasonic TV? Plasma TV has HDMI port. Should what cable I be able to connect to the HDMI port?
-
Assistant printing photographs XP
Is it possible to have the name of a JPEG (picture) printed with it in the Windows XP Photo Printing Wizard? I'm printing pages with several miniature photos and think that there should be a better way to write the names after the fact of hand...
-
At the start, I have this message appears in the box marked 16-bit MS-DOS subsystem message says: C:\window\system321D11 Hhost.exe The NTVDM CPU has encountered an illegal intruction CS, 1216 IP; OP 0100; ffd8ffe000 choose close to teminate the appli
-
I installed msvbvm50.dll, but cannot access
I'm trying to run a program and it says msvbvm50.dll is missing. I downloaded this, but I can't access the program