We can DELETE multiple rows in Oracle by using the rowid.
Steps1:Lets Create a Table named DELETE_MULTIPLE
CREATE TABLE DELETE_MULTIPLE
(
EMP_ID NUMBER NOT NULL
, EMP_NAME VARCHAR2(20 BYTE)
, SALARY NUMBER
);
Table DELETE_MULTIPLE created.
Step2:Insert data into table DELETE_MULTIPLE (insert duplicate values too)
insert into DELETE_MULTIPLE values(1311,'John',25411);
insert into DELETE_MULTIPLE values(1313,'Perk',46456);
insert into DELETE_MULTIPLE values(1315,'Adam',46654);
insert into DELETE_MULTIPLE values(1317,'Gill',45454);
insert into DELETE_MULTIPLE values(1311,'John',25411);
insert into DELETE_MULTIPLE values(1313,'Perk',46456);
insert into DELETE_MULTIPLE values(1315,'Adam',46654);
insert into DELETE_MULTIPLE values(1317,'Gill',45454);
Here is the DELETE_MULTIPLE Table data.
Step3:Now query to delete the multiple rows.
delete from delete_multiple where rowid not in (select max(rowid) from delete_multiple group by emp_id);
4 rows deleted(there was 4 duplicate rows.)
Now give a try,And if you like this post please do share and like.
Steps1:Lets Create a Table named DELETE_MULTIPLE
CREATE TABLE DELETE_MULTIPLE
(
EMP_ID NUMBER NOT NULL
, EMP_NAME VARCHAR2(20 BYTE)
, SALARY NUMBER
);
Table DELETE_MULTIPLE created.
Step2:Insert data into table DELETE_MULTIPLE (insert duplicate values too)
insert into DELETE_MULTIPLE values(1311,'John',25411);
insert into DELETE_MULTIPLE values(1313,'Perk',46456);
insert into DELETE_MULTIPLE values(1315,'Adam',46654);
insert into DELETE_MULTIPLE values(1317,'Gill',45454);
insert into DELETE_MULTIPLE values(1311,'John',25411);
insert into DELETE_MULTIPLE values(1313,'Perk',46456);
insert into DELETE_MULTIPLE values(1315,'Adam',46654);
insert into DELETE_MULTIPLE values(1317,'Gill',45454);
Here is the DELETE_MULTIPLE Table data.
Step3:Now query to delete the multiple rows.
delete from delete_multiple where rowid not in (select max(rowid) from delete_multiple group by emp_id);
4 rows deleted(there was 4 duplicate rows.)
Now give a try,And if you like this post please do share and like.
