Spatial query for delete duplicates of geometry

Hello,
I have a table so done:
link table
id  type  geometry
1  4110 SDO_GEOMETRY(2002, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(8.817363, 45.2586799, 8.8175389, 45.2586922))
2  4110 SDO_GEOMETRY(2002, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(9.673168, 45.9441037, 9.6737121, 45.9439068, 9.6743082, 45.9437246, 9.6744819, 45.9437006, 9.6745598, 45.9436942))
3  4120 SDO_GEOMETRY(2002, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(9.0274561, 45.5738369, 9.0274676, 45.5737538))
4  4110 SDO_GEOMETRY(2002, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(8.8630649, 45.804841, 8.8632493, 45.804992, 8.8633701, 45.805095, 8.8637156, 45.8053738))
5  4110 SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(10.2349279, 45.5008616, NULL), NULL, NULL)
6  4120 SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(10.2591062, 45.501003, NULL), NULL, NULL)
7  4120 SDO_GEOMETRY(2002, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(10.0924794, 45.1855654, 10.0927326, 45.1854935))
...I think that the geometry of the rows with feattyp=4120 are all included (or are equal) into geometry of rows with feattyp=4110. In this case I can delete all rows with feattyp=4120.
I'm thinking to use SDO_ANYINTERACT function but I don't know how do the query.
Can you help me?
Thank you in advance.

I have done so:
SET SERVEROUTPUT ON
DECLARE 
  CURSOR cur IS SELECT * FROM link WHERE FEATTYP=4110;
  rec cur%ROWTYPE;
num_tot_not_intersections NUMBER(20);
num_not_intersections NUMBER(20);
BEGIN
num_not_intersections := 0;
num_tot_not_intersections := 0;
  OPEN cur;
  LOOP
  FETCH cur INTO rec;  
    EXIT WHEN cur%NOTFOUND;
    SELECT count(ID) INTO num_not_intersections FROM link2 WHERE NOT EXISTS (SELECT count(st2.ID) from link2 st2 WHERE st2.FEATTYP=4120 AND SDO_ANYINTERACT(st2.geometry, rec.geometry)='TRUE'); 
    num_tot_not_intersections := num_tot_not_intersections + num_not_intersections;
  END LOOP; 
  DBMS_OUTPUT.PUT_LINE('Totally '||num_not_intersections||' rows with feattyp=4120 without intersection with feattyp=4110');
  CLOSE cur;
END;
/What do you think?
thanks

Similar Messages

  • Query for deleting the minimum updated record.

    Hello Everybody,
    I have table USER_RECENT_PROJECTS which has SIX columns USER_NAME,PROJECT_ID,CREATED_BY,CREATED_ON,UPDATED_BY
    and UPDATED_ON.The purpose of having this table to get 5 recent PROJECTS
    on which user has worked on.
    I have trigger called RECENT_PRJ_TRIGG which IS FIRED when the data is inserted or updated on PROJECT table.After this trigger calls procedure PROC_USER_RECENT_PRJ and that procedure puts the data in this table.
    It is inserting the data upto 5 records when the six records comes it deleting the record which is least UPDATED_ON from the table USER_RECENT_PROJECTS but the problem is it is deleting
    the record from other user that i don't want.I want to delete the the record which is
    least UPDATED_ON from particular user.
    Please help me on this issue.
    Here is the trigger
    CREATE TRIGGER RECENT_PRJ_TRIGG
    AFTER INSERT OR UPDATE ON PROJECT
    FOR EACH ROW
    DECLARE
    NUMBER_OF_PROJECTS NUMBER:=0;
    EXISTING_PROJECT_ID NUMBER:=0;
    BEGIN
    SELECT COUNT(*) INTO NUMBER_OF_PROJECTS FROM USER_RECENT_PROJECTS WHERE USER_NAME=:NEW.UPDATED_BY;
    SELECT PROJECT_ID INTO EXISTING_PROJECT_ID FROM USER_RECENT_PROJECTS WHERE PROJECT_ID=:NEW.PROJECT_ID AND USER_NAME=:NEW.UPDATED_BY;
    NVLX.PROC_USER_RECENT_PRJ(NUMBER_OF_PROJECTS,:NEW.PROJECT_ID,EXISTING_PROJECT_ID,:NEW.UPDATED_BY,:NEW.CREATED_BY,:NEW.CREATED_ON);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NVLX.PROC_USER_RECENT_PRJ(NUMBER_OF_PROJECTS,:NEW.PROJECT_ID,0,:NEW.UPDATED_BY,:NEW.CREATED_BY,:NEW.CREATED_ON);
    END;
    And this is the procedure which is inserting the data
    CREATE OR REPLACE PROCEDURE PROC_USER_RECENT_PRJ (
                   NUMBER_OF_PROJECTS IN NUMBER,
                   NEW_PROJECT_ID IN PROJECT.PROJECT_ID%TYPE,
                   EXISTING_PROJECT_ID IN USER_RECENT_PROJECTS.PROJECT_ID%TYPE,
                   USER_NAME IN CONTENT_USER.USER_NAME%TYPE,
                        CREATED_BY IN PROJECT.CREATED_BY%TYPE,
                        CREATED_ON IN PROJECT.CREATED_ON%TYPE)
              IS
                                  MAX_RECENT_PROJECTS NUMBER := 5;
              BEGIN
                        IF NUMBER_OF_PROJECTS<=MAX_RECENT_PROJECTS AND EXISTING_PROJECT_ID=NEW_PROJECT_ID THEN
                             UPDATE USER_RECENT_PROJECTS SET USER_RECENT_PROJECTS.UPDATED_ON=SYSDATE,USER_RECENT_PROJECTS.UPDATED_BY=USER_NAME WHERE PROJECT_ID=EXISTING_PROJECT_ID
                             AND USER_RECENT_PROJECTS.USER_NAME=USER_NAME;
                        ELSE IF NUMBER_OF_PROJECTS<MAX_RECENT_PROJECTS AND EXISTING_PROJECT_ID!= NEW_PROJECT_ID THEN
                        INSERT INTO USER_RECENT_PROJECTS VALUES (USER_NAME,NEW_PROJECT_ID,CREATED_BY,CREATED_ON,USER_NAME,SYSDATE);
                        ELSE IF NUMBER_OF_PROJECTS=MAX_RECENT_PROJECTS AND EXISTING_PROJECT_ID!= NEW_PROJECT_ID THEN
                        DELETE FROM USER_RECENT_PROJECTS WHERE USER_RECENT_PROJECTS.PROJECT_ID IN(
                                       SELECT PROJECT_ID FROM USER_RECENT_PROJECTS
                                                 WHERE UPDATED_ON=(SELECT MIN(UPDATED_ON) FROM USER_RECENT_PROJECTS
                                  WHERE USER_RECENT_PROJECTS.USER_NAME=USER_NAME));
                   INSERT INTO USER_RECENT_PROJECTS VALUES (USER_NAME,NEW_PROJECT_ID,CREATED_BY,CREATED_ON,USER_NAME,SYSDATE);
                        END IF;
                        END IF;
                        END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NVLX.PROC_USER_RECENT_PRJ(NUMBER_OF_PROJECTS,NEW_PROJECT_ID,0,USER_NAME,CREATED_BY,CREATED_ON);
    END PROC_USER_RECENT_PRJ;
    Please help me on this issue.
    Thanks in advance.....

    Thanks for your suggestion....
    I am using the trigger for populating the data in USER_RECENT_PROJECTS.This
    trigger is fired when data is INSERTED or UPDATED in PROJECT table.And that trigger will call the procedure PROC_USER_RECENT_PRJ.This is used
    to put data in USER_RECENT_PROJECTS table.I am getting the problem in procedure the problem is upto five records it is inserting the record when i go for insert sixth record it should delete least UPDATED_ON and insert new record.But it is deleting the record from other user that i don't want.I want to delete the record from the paarticular user.I am using this query for deleting the record..
                   DELETE FROM USER_RECENT_PROJECTS WHERE USER_RECENT_PROJECTS.PROJECT_ID=(
         SELECT PROJECT_ID FROM USER_RECENT_PROJECTS
                        WHERE UPDATED_ON=(SELECT MIN(UPDATED_ON) FROM USER_RECENT_PROJECTS WHERE USER_RECENT_PROJECTS.USER_NAME=USER_NAME)
                             AND USER_RECENT_PROJECTS.USER_NAME=USER_NAME
                   ) AND USER_RECENT_PROJECTS.USER_NAME=USER_NAME;
    when i fire this query individually it is deleting the proper record,but when i use it
    inside procedure it is creating the problem it is deleting the record from other user.
    Please suggest me other query for deletion.
    Thanks in advance.......

  • Query for deletion

    Hi to all.........
          Plz tell me the ABAP query for how to delete the duplicate posting months from dfkkop & after  
          then the query to count the no of rows of dfkkop ??
    Thanks & Regards........
    Rajeev Shrivastava

    hi check this..
    tables:marc .
    data: it_marc like marc occurs 0.
    select-options:s_matnr for marc-matnr .
    data: v_count type i .
    select matnr
            werks
             from
               marc into table it_marc
               where matnr in s_matnr .
    delete adjacent duplicates from it_marc comparing werks .
    describe table it_marc lines v_count .

  • Query for deleting rows older than 25?

    Am trying to delete rows older than 25... How would the query for this be like? I tried this "DELETE FROM DB LIMIT 25,100" But getting errors...

    what is older than 25? Does it mean with id greater then 25?
    then you should have a query like
    DELETE FROM tableName WHERE id > 25

  • Any apps for deleting duplicate mail?

    I was thinking this was built in to Mail, but looking for a script or app that will help me find and eliminate duplicate emails in my mailboxes.

    Here is a script to remove duplicate messages from Mail.app

  • Dynamic query for delete statement

    Hi friends,
    I have a table hierarchy where suppose i have tables with following hierarchy
    Level1
    level2 (child of level1)
    level3 (child of level2)
    level4 (child of level3)
    Now i want to delete data from lowest level table depending on level one table value which is provided to me.
    I have a requirement where i want to create this delete query dynamically.
    Any help in this concern...
    Thanks,
    Sachin

    Yon can use on delete cascade as satyaki suggested like
    SQL> select * from level1;
            ID DESCRIPTION
             1 L1_1
             2 L1_2
             4 L1_3
             5 L1_4
    4 rows selected.
    SQL> select * from level2;
            ID DESCRIPTION                                                                                           L1_FK
             1 L2_1                                                                                                  1
             2 L2_2                                                                                                  1
             4 L2_3                                                                                                  2
             5 L2_4                                                                                                  2
    4 rows selected.
    SQL> delete from level1 where id =1;
    1 row deleted.
    SQL> select * from level1;
            ID DESCRIPTION
             2 L1_2
             4 L1_3
             5 L1_4
    3 rows selected.
    SQL> select * from level2;
            ID DESCRIPTION                                                                                           L1_FK
             4 L2_3                                                                                                  2
             5 L2_4                                                                                                  2
    2 rows selected.
    SQL>

  • Can I use iPhoto library manager for deleting duplicate photos?

    I would like to find a way to delete hundreds of duplicate photos that exist in my iPhoto library. Any ideas?

    to your headline - yes
    but the bigger question is why do you have duplicates?  what recently chnaged that you have them?
    LN

  • The best app for deleting duplicate photos in iPhoto 9

    Hi, I have stumbled upon many duplicates /triplicate photos in my iphoto library. I was wondering what is the best app/program to use to eliminate the photos to free up space on my macbook.
    I have seen a few posts suggesting apps but many had just as many cons for the pros....I have no problem paying for an app but do have a problem if I can not be reimbursed in the event the app doeesnt work.....
    I do have all my pictures saved to the main "photos" section of the library as well as in seperate folders in "events"
    To clarify, it is while looking at the main photo library is where im finding the duplicate and triplicate photos.
    Macbook pro
    OSX 10.7.5
    iPhoto 9  8.1.2
    Thanks in advance, Dawn

    That sounds like an issue with iPhoto.  To make sure it's not the applicaiton create a new test library, import a number  photos and import half of them again.  Then try the iPhoto Dupoicate Cleaner again.
    The only aspect of the app that I don't like is that it doesn't let you mark the files as duplicates instead of moving them to the Trash.  iPhoto LIbrary Manages has several options:
    But Duplicate Cleaner for iPhoto found all of my duplicates in my test library. Just be careful to not empty the iPhoto Trash bin until you've previewed the selection.

  • Deleting Duplicate Records -EIM  Import Account & Contact

    Hi,
    Can anyone give me the query to delete duplicate records both from legacy as well as from the tables imported.

    Try this..
    DELETE
    FROM table
    WHERE ROWID NOT IN(SELECT MAX(ROWID)
    FROM table
    GROUP BY column)
    For which column u have duplicate rows that column u have to give in group by clause so except max of rowid it will delete all records.

  • How to delete duplicate rows in oracle and retaining last duplicate rows

    Hi,
    I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
    I just want to delete duplicate rows but also want to retain the last duplicate row.
    For eg if one record is found three times ,i want to delete first and second record and retain
    the third one i.e the last inserted one.
    Regards
    Paramdeep Singh

    user13310594 wrote:
    Hi,
    I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
    I just want to delete duplicate rows but also want to retain the last duplicate row.
    For eg if one record is found three times ,i want to delete first and second record and retain
    the third one i.e the last inserted one.Hi Paramdeep,
    To start with, since you do not wish to keep multiple rows with same values, why allow them to get inserted in the first place?
    Wouldn't it be easier to block duplicate rows from inserting by creating a Unique constraint on Column(s) that define a row as duplicate, then rather deleting duplicate rows periodically?
    For deleting duplicate rows, there are N number of techniques available. Always remember, you need to have a rigid criteria that marks row as duplicate.
    [url http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15258974323143]this is one recomended by tom for large tables.
    Vivek L

  • Deleting duplicate photos

    I am still using Aperture 2, on a Macbook Pro running snow leopard. I generally only look at and examine my projects (with folders and albums contained in them). The other day I took a look at my All Photos (in the library) and found that I had lots and lots of duplicates, and many triplicates of my photos (which don't show up in my albums). I have no idea how I got so many of them, but they must add up to hundreds if not a thousand or so.
    I have started deleting the extras. Then I noticed that many of them are the original photo next to its edited photo. Is that normal? I thought that the originals were hidden somewhere and only the edited versions were in the library. Is this wrong? Should both of them be in the library? And, if I have deleted many of the unedited photos, have I eliminated the masters? Will my versions still be accessible, or am I ruining their presence by deleting the master (if indeed they are the masters). I realize that there are programs for deleting duplicates, but they are kind of expensive, except for Duplicate Annihilator, which won't run on Aperture 2.)
    Please advise. Thanks for any help.
    Nancy

    take a look at this article http://www.macosxhints.com/article.php?story=20060624112253828

  • Delete duplicate entriess from the internal table its urgent pls help.

    Hi friends,
    Hope everybody is doing good,Here is m query on delete duplicate data from the intenal table.
    I have an internal table which contain data in the following format.
    Doc No Comp Cod Vendor Assignment
    1500000009 JM11 00000000
    1500000008 JM11 20070212(Repeating)
    1500000007 JM11 20070212
    1500000006 JM11 00000000
    1500000005 JM11 00000000
    1500000004 JM11 00000000(Repeating)
    1500000003 JM11 00000000 (Repeating)
    1500000002 JM11 00000000
    1500000001 JM11 20050302
    1500000000 JM11 00000000
    1500000003 JM11 10000088
    1500000001 JM11 10000088
    1500000030 JM11 10006260
    1500000010 JM11 10006269
    1500000008 JM11 10006269
    1500000006 JM11 10006269
    1500000004 JM11 10006269
    if you see the document numbers,there are some document number which are repeating here,there are some document numer which contain vendor number but not the assignments,some of the document numbers contain the assignments but not the vendors.
    If my internal table contain this kind of data with repeted document numbers than i want the document number which contains only the vendor number.
    Pls help me with the appropriate logic,its urgent.
    Thanks a lot
    mrutyun^

    Hi,
    <u><b>Deleting Adjacent Duplicate Entries</b></u>
    To delete adjacent duplicate entries use the following statement:
    DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
    [COMPARING <f1> <f2> ...
    |ALL FIELDS].
    The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are
    duplicate if they fulfill one of the following compare criteria:
      Without the COMPARING addition, the contents of the key fields of the table must be
    identical in both lines.
      If you use the addition COMPARING <f1> <f2> ... the contents of the specified fields <f1>
    <f2> ... must be identical in both lines. You can also specify a field <fi> dynamically as
    the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is
    executed, it is ignored. You can restrict the search to partial fields by
    specifying offset and length.
      If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines
    must be identical.
    You can use this statement to delete all duplicate entries from an internal table if the table is
    sorted by the specified compare criterion.
    If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.
    Examples
    DATA: BEGIN OF LINE,
    COL1 TYPE I,
    COL2 TYPE I,
    END OF LINE.
    DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
    DO 4 TIMES.
    LINE-COL1 = SY-INDEX.
    LINE-COL2 = SY-INDEX ** 2.
    INSERT LINE INTO TABLE ITAB.
    ENDDO.
    LINE-COL1 = 1.
    DELETE TABLE ITAB: FROM LINE,
    WITH TABLE KEY COL1 = 3.
    LOOP AT ITAB INTO LINE.
    WRITE: / LINE-COL1, LINE-COL2.
    ENDLOOP.
    The output is:
    2    4
    4   16
    The program fills a hashed table with a list of square numbers. The DELETE
    statement delete the lines from the table where the key field COL1 has the contents 1 or 3.
    Regards,
    Bhaskar

  • How to delete duplicate record in Query report

    Hi Experts,
    I had created an infoset and query in my sap, but I want to delete some duplicate records before the list out put.Please can we add some further codes in the Extras code to delete duplicates? And how do it? Would you please give me a simple brief.
    Joe

    Hi,
    You can try to restrict in the filter area in query designer with the values for characteristic which gives correct
    result.
    But still i would suggest that in the cube you keep not the duplicate records as this is not your requirement and giving
    you wrong result.
    So you can reload the correct records in the cube inorder to avoid such problems even in future.
    Regards,
    Amit

  • Query for spatial data with a GeometryCollection fails

    There are exact 538 CurvePolygons (only exterior rings at this
    sample). All of them are valid geometries and equal in dimension
    and so on. Now I connect them to a GeometryCollection and query
    for other relating spatial data in some tables. It seems that
    the use of around (not exact!) 200 CurvePolygon in one
    GeometryCollection works fine but the adding of more
    CurvePolygon result in an error with the Spatial Index (I could
    add the ORA- error numbers if I have some data in my test tables
    again next days).
    Is there anybody else having trouble with these mysterious
    problem? Maybe there is a border by the number of points in
    GeometryCollection?
    (More details, programming code could be delivered)
    (working with Java 1.3.1, oracle.sdoapi.*, Oracle 8.1.7.)

    Hi Lutz,
    Could you provide more info or samples of what is going wrong?
    Also, could you try making sure the geometry you are passing in
    as the query window is valid (i.e. instead of passing it in as a
    query window, pass it into sdo_geom.validate_geometry).
    Thanks,
    Dan

  • Generalise Delete Duplicate Rows Query work in any Database

    Hello Friends,
    I need generalize SQL Query for removal of duplicate data from a table.
    Condition: It will work in both the database Oracle as well as SQL Server 2005.
    Waiting for your valuable response on the above issue.
    Thanks/Regards,
    Bhavin Patel
    Please reply to this post...

    Thanks, Nimish for your reply..._
    I know how to delete duplicate values entry from Oracle database.
    I'm using below method quite often when to delete duplicate value from the Oracle database.::
    SELECT * FROM dept do
    WHERE do.ROWID NOT IN (SELECT MIN(di.ROWID) FROM dept di WHERE di.deptno = do.deptno)
    WITH T1 AS
    (SELECT dept.*,ROW_NUMBER() OVER(PARTITION BY deptno,dname ORDER BY deptno) RNUM FROM dept)
    SELECT * FROM T1 WHERE RNUM > 1
    Actually in interview this question asked to me, I've given Oracle process, but unable to give solution for SQL Server or DB2

Maybe you are looking for

  • How can i export a 24bit avi file from photoshop for mac?

    how can i export a 24bit avi file from photoshop for mac? i have a client that specificly needs the files to be avi and in 24bit what are the settings that i need to use to export the video using photoshop on a mac?

  • I WOULD LIKE TO DELETE MY ACCOUNT OR SOLVE THIS TROUBLE PLEASE SEE THIS

    VERY URGENT (MY EMAIL IS PLENTY OF THESE QUESTIONS This is for the administrator(s) I Am receiving from your forum site many of THESE: aemme, You are watching the category "System Management and Integration", which was updated Nov 11, 2010 4:32:18 AM

  • Error configuring Microsoft SQLSERVER 2005 with OIM 9.1.0.1

    Hi All, I was trying to Configure Microsoft SQLSERVER 2005 as a IT Resource with OIM 9.1.0.1. However after completing all the configuration, When I tried assigning the configured SQLSERVER IT Resource to a User, following error is thrown: Response:

  • Why won't may computer recognize my IPad

    When I plug my IPad into my computer it doesn't pull up to sync no more? Why? I use to br able to do it. Please help.

  • MICR Font for printing payroll checks

    We are in the process of changing banks. The new bank has rejected our sample checks because the spacing is too wide. We are supposed to be using MICR font E-13B. How do I find out what font we're using? And, how do I change the font?