Mihee
Mihee

Reputation: 25

How to truncate a row based on column data?

For example if characterid = null I want the entire row removed: example of what I want removed:

http://puu.sh/mhveP/b2df36f6cc.png

but if characterid has a value then I want to keep the entire row: example of row I want to keep:

enter image description here

Obviously I can remove the rows myself manually but it would take way to long to do them all.

Upvotes: 0

Views: 6617

Answers (2)

Zanub
Zanub

Reputation: 29

If your question is about PLSQL then I think you can use:

 Select characterid
   into //any variable//
   from //tablename
    where //condition
 then you will check 
   if(anyvariable is null)
   then 
      Delete from //tablename
     where //condition

Upvotes: 0

Clay
Clay

Reputation: 4760

A delete query is pretty similar to a select query except that it says DELETE FROM instead of SELECT * FROM. You would run your delete like so:

DELETE FROM table WHERE characterid IS NULL

Before running the delete query, you can run this to make sure it matches the criteria of the data you want removed:

SELECT * FROM table WHERE characterid IS NULL

Also, always make sure you make a backup especially when a query like this can affect large sets of data.

Upvotes: 4

Related Questions