Callum Wilson
Callum Wilson

Reputation: 1

Sql Error Newbie

I am trying to update the number stored in a field,this is the code I have used

Select * 
From MEDICATION
UPDATE medication
set seq_number = 2
where pet_id = "PO145" 
   AND vet_id = "V01" 
   AND MEDICINE ='Soothing Cream';

The error returned states

ORA-00933: SQL command not properly ended

Upvotes: 0

Views: 43

Answers (2)

Utsav
Utsav

Reputation: 8093

As @Tim mentioned, select and update should be different. So run them individually.

Also the strings should be enclosed in single quotes, not double. Although this is not the reason for error, but it will not work for you with double quotes. Double quotes should be used for object/column names.

Also it is a good practice to run the where clause used in update or delete, with select first, as it will let you see what rows are returned, which will be updated or deleted.

UPDATE medication
set seq_number = 2
where pet_id = 'PO145' 
   AND vet_id = 'V01' 
   AND MEDICINE ='Soothing Cream';

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520878

It looks like you're trying to do a SELECT and an UPDATE at the same time. You can't do that. For the update, just use the latter part of your query by itself:

UPDATE medication
SET seq_number = 2
WHERE pet_id = "PO145" AND
      vet_id = "V01"   AND
      MEDICINE = 'Soothing Cream';

After the update, if you want to do a SELECT * FROM medication then this should be no problem.

Upvotes: 0

Related Questions