0

I have a table with almost 27 columns(all of integer datatype) with first column being ID(PK). I wish to update all the values to some value say 500. is there any query to update without typing all the 27 column names like this.

UPDATE tbl_name SET a=500,b=500,c=500.....z=500 where ID = 1

Or else can i make any PL/SQL function which will fetch next next column by itself without providing the column name and set the value ?

7
  • AFAIK this is the only option, unless you want to use dynamic SQL. If so, then you might be able to loop over all columns and assign 500 to each one. Commented Feb 27, 2017 at 9:31
  • But as a side note, 27 columns sounds a bit on the large side. You might want to restructure your database. Commented Feb 27, 2017 at 9:33
  • by dynamic SQL, yu mean PL/SQL ? Commented Feb 27, 2017 at 9:34
  • I don't think this is possible in a single query. You need to specify column names in UPDATE Commented Feb 27, 2017 at 9:34
  • Possible duplicate of How to UPDATE all columns of a record without having to list every column Commented Feb 27, 2017 at 9:34

2 Answers 2

2

It is not possible in any db's. You need to mention the column names. Check the update specifications for most common db's mentioned in the below thread

How to UPDATE all columns of a record without having to list every column

Sign up to request clarification or add additional context in comments.

Comments

1

You cannot do this. You always have to specify the column names while updating. If it is a proccess You will be reapeating You can write stored procedure doing it.

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.