오라클에서 중복 기록 삭제하는 방법

PDF 다운로드PDF 다운로드

오라클에서 작업할 때, 중복된 기록이 있을 수 있다. 중복 기록을 식별하거나 RowID를 쓰거나 열 주소로 중복된 열을 삭제할 수 있다. 시작하기 전에, 기록을 삭제하고 참고할 경우에 대비해 백업 테이블을 만들어야 한다.

방법 1
방법 1 의 4:

중복된 기록 식별하기

PDF 다운로드
  1. How.com.vn 한국어: Step 1 중복 기록을 식별한다.
    이 경우 예시로 "Alan"과 같은 중복 기록이 있는지 확인한다. 삭제하고자 하는 기록이 실제로 중복인지 밑에 있는 SQL에 입력해서 확인해야 한다.
  2. Step 2 "Names"라는 행에서 식별한다.
    행 이름이 "Names"인 경우, "column_name" 에 Nmaes를 넣는다.
  3. How.com.vn 한국어: Step 3 다른 행에서 식별한다.
    다른 행에서 중복 기록을 식별하려고 하는 경우, 예를 들어 이름 Alan이 아닌 Alan의 age에서 식별한다면, "column_name"에 "Ages"를 입력하는 식으로 하면 된다.
    select column_name, count(column_name) from table group by column_namehaving count (column_name) > 1;
    광고
방법 2
방법 2 의 4:

중복 기록 하나 삭제하기

PDF 다운로드
  1. Step 1 "name from names"을 선택한다.
    구조적 쿼리 언어를 뜻하는 "SQL" 다음에 "select name from names"를 입력한다.
  2. How.com.vn 한국어: Step 2 중복되는 이름이 있는 모든 열을 지운다.
    "SQL" 다음에 "delete from names where name='Alan';."을 입력한다. 여기서 대문자에 주의해야 한다. 이렇게 하면 "Alan"이라는 열이 모두 삭제된다. "SQL" 다음에 "commit"을 입력한다.[1]
  3. How.com.vn 한국어: Step 3 중복 기록이 없는 열을 다시 입력한다.
    이제 "Alan"이라는 이름이 있는 열을 모두 삭제했으니, "insert into name values ('Alan');."을 입력하여 하나를 다시 넣을 수 있다. "SQL" 뒤에 "commit" 을 입력하여 새로운 열을 만들 수 있다.
  4. How.com.vn 한국어: Step 4 새로운 목록을 확인한다.
    위의 단계를 따라 했다면 "select * from names"을 입력하여 중복된 기록이 더이상 없는지 확인할 수 있다.
    SQL > select name from names;NAME------------------------------AlanCarrieTomAlanrows selected.SQL > delete from names where name='Alan';rows deleted.SQL > commit;Commit complete.SQL > insert into names values ('Alan');row created.SQL > commit;Commit complete.SQL > select * from names;NAME------------------------------AlanCarrieTomrows selected.
    광고
방법 3
방법 3 의 4:

여러 가지 중복기록 삭제하기

PDF 다운로드
  1. How.com.vn 한국어: Step 1 삭제하고자 하는 RowID를 선택한다.
    "SQL" 뒤에 "select rowid, name from names;."를 입력한다.
  2. How.com.vn 한국어: Step 2 중복 기록을 삭제한다.
    "SQL" 뒤에 "delete from names a where rowid > (select min(rowid) from names b where b.name=a.name);"을 입력하여 중복된 기록을 삭제한다.[2]
  3. How.com.vn 한국어: Step 3 중복 기록이 있는지 확인한다.
    위의 단계가 끝나면 "select rowid,name from names;"을 입력하고 "commit" 을 입력하여 중복 기록이 있는지 명령어로 확인한다.
    SQL > select rowid,name from names;ROWID              NAME------------------ ------------------------------AABJnsAAGAAAdfOAAA AlanAABJnsAAGAAAdfOAAB AlanAABJnsAAGAAAdfOAAC CarrieAABJnsAAGAAAdfOAAD TomAABJnsAAGAAAdfOAAF Alanrows selected.SQL > delete from names awhere rowid > (select min(rowid) from names bwhere b.name=a.name);rows deleted.SQL > select rowid,name from names;ROWID              NAME------------------ ------------------------------AABJnsAAGAAAdfOAAA AlanAABJnsAAGAAAdfOAAC CarrieAABJnsAAGAAAdfOAAD Tomrows selected.SQL > commit;Commit complete.
    광고
방법 4
방법 4 의 4:

행으로 열을 삭제하기

PDF 다운로드
  1. How.com.vn 한국어: Step 1 열을 선택한다.
    "SQL" 다음에 "select * from names;" 를 입력하여 열을 확인한다.
  2. How.com.vn 한국어: Step 2 행을 식별하여 중복된 열을 삭제한다.
    "SQL'" 다음에 "delete from names a where rowid > (select min(rowid) from names b where b.name=a.name and b.age=a.age);" 를 입력하여 중복된 기록을 삭제한다.[3]
  3. How.com.vn 한국어: Step 3 중복 기록을 확인한다.
    위의 단계가 끝나면 "select * from names;" 그리고 "commit" 을 순서대로 입력하여 중복 기록이 확실히 지워졌는지 확인한다.
    SQL > select * from names;NAME                                  AGE------------------------------ ----------Alan                                   50Carrie                                 51Tom                                    52Alan                                   50rows selected.SQL > delete from names awhere rowid > (select min(rowid) from names bwhere b.name=a.nameand b.age=a.age);row deleted.SQL > select * from names;NAME                                  AGE------------------------------ ----------Alan                                   50Carrie                                 51Tom                                    52rows selected.SQL > commit;Commit complete.
    광고

경고

  • 로그인을 해야 볼 수 있는 백업 테이블을 만들어서 지우기 전에 뭐가 있었는지 확인할 수 있도록 한다(의문이 생기는 경우에 대비해서)
    SQL > create table alan.names_backup as select * from names;Table created.
광고

이 위키하우에 대하여

How.com.vn 한국어: 위키하우 직원
공동 작성자 :
위키하우 소속 작가
이 글은 위키하우 편집팀과 전문 조사원이 공동 작성하였으며 정확성 검토가 완료 되었습니다.

위키하우 콘텐츠 관리팀은 작성된 모든 글이 위키하우 글 작성 규정을 준수하는지 꾸준히 검토합니다. 조회수 2,365회
글 카테고리: 소프트웨어
이 문서는 2,365 번 조회 되었습니다.

이 글이 도움이 되었나요?

⚠️ Disclaimer:

Content from Wiki How 한국어 language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

Notices:
  • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
  • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
  • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
  • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

광고