SQL & PL/SQL :: Duplicate Detection - Display All Occurrences?
Feb 24, 2010
For every record which came yeterday in table ABC, I need to find if same record data does exists in historical records of the same table, and if match is find, I need to display all the occurrences.
For example Data got inserted yesterday as
SQL RES : Col 1= "A" Col 2: "B" Col 3: "C" Date = Sysdate -1
then, I need to scan through Query results from the history where I can find if there exists same combination already.and if so I need to display both i.e Record form yesterday and from history.
Here is the one I am using to get the base data.
with base as(
select Col 1, Col 2, Col 3,A.Create_DT
from A,B
where A.ID = B.ID
)
i have master-detail form.in master my bill_id gets generated when new form is open and i copy the same bill_id in detail(tabular)for each item.all the items which i enter in detail form get save the same bill_id which got generated.
in another form(which is tabular) i want to display bill_id's from detail form.but in detail form . There are same bill_id's more than once.but i want to display those bill_id's which are more than once only once.
how to display the data which is shown below without duplicate records in compid and compname and all policy_id's should be there while excuting this query iam getting this data.
select distinct comp_id as compid, comp_disp_name as company, plcy_id as policyid,
19734 Save the Children 9013 GPA 19734 Save the Children 9012 GMC 20097 JMT 9486 GTL 10890 Steelco Gujarat Ltd. 9727 CAR 17330 Golden Jubilee Hotels Limited 8915 CGL 23117 NBHC 9093 GMC 17542 Heinz India 10693 Fire 19821 KSK Fabricators 10341 D&O 3769 Jones Lang Lasalle India 9199 WC 19821 KSK Fabricators 10340 WC
create table eresults (student_name varchar2(20), section_name varchar2(4), exam_id NUMBER (4)) marks NUMBER (3))
[code]....
My requirement is that I need another column named "top scored" which will show how many times each student took highest marks for his Section in each exam_id"
For example in above data the following students "Top scored" for thier respective section in each exam_id:
STUDENT_NAME SECTION EXAM_ID DOLLY A 1 RIZWAN B 1 PAUL C 2 ZAKIR D 2
[code]....
So, based on above my requirement is as below
STUDENT_N SECTION_NAME COUNT(EXAM_ID) SUM(MARKS) MAX(MARKS) top_scored ALEENA C 2 147 91 0 ASIM D 2 68 45 1 ASLAM B 2 70 56 0 ATIF D 2 2 2 0 AYSHA B 2 114 78 0
Years ago, someone created a database in Oracle that was carried over and now sits in Oracle 10g. I am developing an application that queries this database and returns the result as XML.
Many (thousands) of rows have an item description that contains an ampersand. I want each of these pieces of data to have it written as & amp; (had to add a space so it would show up here, but you know what I mean) instead of &, but I don't feel like doing thousands of UPDATEs to change this.
Does Oracle have any global find/replace functions that I can call? I'd rather do one update statement that replaces all occurances of & with & amp; but I can't seem to find a function that will do this.
I'm thinking something that would work like:
UPDATE table SET column1=REPLACE(column1,oldstr,newstr);
How can i identify all the occurences of raise_application_error(-20XXX, '<the message>'); within all database objects, and replace them with other text?
I have a table of documents (excel, word, pdf, txt) stored in blob column. I want that SCORE returns the number of occurrences within each document, so I'm using this piece of code:
SELECT bdt.*, SCORE(1) AS score_1, DBMS_CRYPTO.HASH(archivo, 3) AS cod_hashFROM crg_ctx_archivos_recibidos bdt
However I'm getting a maximum score of 10, but I know one of these documents have 490 matches. How can i get the exact number of matches per document? I'm using Oracle 11.2
My Scenario is'....456re0,50kg400,500rfabs43qre30,25kg150,354rf658....'
there is possible,using regexp_substr or other way to get the values, 0,50 and 400,500 and 30,25 and 150,354? I'm using [^re]+[$kg] and the string comes, but only the first occurence..
The M column is used to count the total number of occurrences of a SLOT. Now, as for the N field, this is used to count the occurrence of the SLOT. In my example for the SLOT TRALTEST43S1, it has three occurrences so M will be 3. Why 3, is because of the WIPDATAVALUE. The WIPDATAVALUE of TRALTEST43S1 is 1-2 and 3. 1-2 WIPDATAVALUE signifies two occurrences (one to two) and 3 signifies only one occurrence. As for N, it should just count the number of occurrence. To further explain, see below:
WIPDATAVALUE SLOT N M 1-2 TRALTEST43S1 1 3 -> First occurrence in the total of 3 1-2 TRALTEST43S1 2 3 -> Second occurrence in the total of 3 3 TRALTEST43S1 3 3 -> Third occurrence in the total of 3 4-6 TRALTEST43S2 1 4 -> First occurrence in the total of 4 4-6 TRALTEST43S2 2 4 -> Second occurrence in the total of 4 4-6 TRALTEST43S2 3 4 -> Third occurrence in the total of 4 7 TRALTEST43S12 4 4 -> Fourth occurrence in the total of 4
This is the query that I have so far:
SELECT DISTINCT WIPDATAVALUE, SLOT , LEVEL AS n , m FROM ( SELECT WIPDATAVALUE , SLOT , (dulo - una) + 1 AS m [code]....
I think that my current query is basing its M and N results on WIPDATAVALUE and not the SLOT that is why I get the wrong output. I have also tried to use the WITH Statement and it works well but unfortunately, our system cant accept subquery factoring.
I am trying to create view that selects a number of rows from a table and has a calculated field which is a counter form 1 to n next to each row.
In the below example, s_name is repeated many times each with a differnet serial, I want to cteate a view that shows a counter for the occurences of s_name next to the serial.
CREATE TABLE XYZ ( SERIAL NUMBER PRIMARY KEY, S_NAME VARCHAR2(30) ); INSERT ALL INTO XYZ VALUES (1, 'ABC') INTO XYZ VALUES (11, 'ABC')
The code which I am working on consists of an incoming dynamic string which be in the form of binary digits. The max size of the string will be 12 digits. For example, the string can be '111011000001', '000000000000', '111111011111', etc.
I need to find the number of occurences of '111' in the incoming string. Say in the 1st example, result will be 1, in the 2nd example result will be 0, and in the third example, the result will be 3.
I have been trying to capture the string length and replacing the variables '111' to find the number of occurences, but it isn't giving me the result that I want. This is what I have tried
SQL> conn hr/hr Connected. SQL> show user USER is "HR"
[Code]....
I searched the forum and found a similar topic, and following that guideline, I even tried dividing the string with the length of the pattern. It works in some scenarios (the first and second examples mentioned below), while it fails in some scenarios (third example mentioned below)
SQL> select (length('11101110111') - length(replace('11101110111','111','')))/length('111') as occurences from dual;
OCCURENCES ---------- 3
SQL> select (length('110111110111') - length(replace('110111110111','111','')))/length('111') as occurences from dual;
OCCURENCES ---------- 2
SQL> select (length('111111111111') - length(replace('111111111111','111','')))/length('111') as occurences from dual;
here on your forum but has been following several threads ever since.So anyway here is the thing, I have a query that should return count the number of rows depending on the value of SLOT. Something like this:
As you can see above, on the SLOT TRALTEST43S1, there are three occurrences so M (Total number of occurrences) should be three and that column N should count it. Same goes with the SLOT TRALTEST43S2. This is the query that I have so far:
SELECT DISTINCT WIPDATAVALUE, SLOT , LEVEL AS n , m FROM ( [code]...
I think that my current query is basing its M and N results on WIPDATAVALUE and not the SLOT that is why I get the wrong output. I have also tried to use the WITH Statement and it works well but unfortunately, our system cant accept subquery factoring.
insert into ashok_temp11 values('A1','1001'); insert into ashok_temp11 values('A2','1001'); insert into ashok_temp11 values('A3','1002'); insert into ashok_temp11 values('A4','1003');
[Code]...
I need the duplicate values in the table. That means
col1 col2 a1 1001 a2 1001 a6 1001 a3 1002 a7 1002
I tried the following query and its not fetching me any records.
SELECT col1, col2 FROM ashok_temp11 GROUP BY col1, col2 HAVING COUNT(col2) > 1 ORDER BY col2
I will be duplicating my production database back to a few weeks ago on my test server, to retrieve certain data. I am running 11g standard edition, not using a recovery catalog.
Below are the basic steps I plan to take in a nutshell.
1. Copy the backup files to the test system
2. In the rman run block (on the test server) A. Set newname for each of the datafiles and tempfiles (don't have many files) B. Duplicate command to point in time, specifying backup location and no filename check.
Trying to delete duplicate rows from a table. The problem is, they aren't exactly duplicate rows. Let me explain.
I am migrating data from a Oracle 8.1.7 db to a 10.2.1 db. In the older db, this certain table does not have a PK/Unique Index, but in the new db there is a unique index. The fields that the index is unique on are:
In the old db, when I run this query I get 1229 rows. With a count of 2 each.
select SUBSCR_NO, SUBSCR_NO_RESETS, EXTERNAL_ID, EXTERNAL_ID_TYPE, ACTIVE_DATE, count(*) from customer_id_equip_map group by SUBSCR_NO, SUBSCR_NO_RESETS, EXTERNAL_ID, EXTERNAL_ID_TYPE, ACTIVE_DATE having count(*)>1;
They are duplicates on those fields, but they are not totally duplicate rows because there is a field called is_current that has 0 in one row and has 1 in the other. What I need to do, is delete the 1229 rows with is_current=0.
how can i get distinct records through this coding, when i add select distinct col1, col2, col3 from tablename where RECD_ON between :control. REC_ FROM and :control.REC_TO; in 1st qry after begin, this form not retrive any data from database, then how i get distinct rows through this coding. is there any option in property plattee to get distinct rows.
declare qry varchar2(5000); n number; alert number; Begin [code]....
i have table with name, count, flag with dublicate records
example
with swayam name , counts are 3, 4 with ramana name, counts are 5,5 with reddy name, counts are 1,2,3
i want to update the flag
if count are same then update one of record (flag='A') and other should be flag='R' if count are different then update the max count (flag='A') and other should be reject remaing (flag='R'). use below quires
CREATE TABLE TEST_DUB ( NAME VARCHAR2(99), V_COUNT NUMBER, FLAG VARCHAR2(1));
Insert into TEST_DUB (NAME, V_COUNT) Values ('SWAYAM', 3); Insert into TEST_DUB (NAME, V_COUNT) Values