0

I have only one column roll number in my oracle table. Lots of data are there in one column.

   roll number  

  -------------

      1 
      2
      3
      4
      5
      .
      .
      .

When i want to delete some roll numbers out of this table then i am writing:

delete from table name where roll number='2'; // 1 row deleted.

if i want to delete 5 from table then

delete from table name where roll number='5'; // 1 row deleted.   

Similarly when i want to delete 100 records like this then i have to replace roll number field and it is quite time taking. Is there any quick method how can i delete selective rows from the table?

1
  • you can use OR in your delete statement. Can you explain what really you want to achieve? Commented Apr 28, 2012 at 9:42

3 Answers 3

7

If the ids to delete are consecutive you could use BETWEEN:

DELETE FROM your_table WHERE roll_number BETWEEN 5 AND 104

If not, you could use IN:

DELETE FROM your_table WHERE roll_number IN (5, 9, 110, ... )
Sign up to request clarification or add additional context in comments.

1 Comment

+1. I'd lose the quotes if these are really numbers (I know the original question has them, too, but if the data really is in a text column, BETWEEN won't work so well).
1

You can get the list of number from another query and put it in a IN condition, so for example :

delete from table name where roll number IN (select roll number from table WHERE somecondition);

2 Comments

+1 but your example is a bit strange. You could just do DELETE FROM table WHERE somecondition instead.
Yes but maybe he could get the interested ids from another table, is only an example, i don't know the relations of the entire database ...
0

If u already know the range u can use Between else if u know the total numbers to be deleted then u can use IN like....

delete from table where roll number BETWEEN ....;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.