1

Lets suppose I created one table--

Create table t1 (aa varchar2(5),bb varchar2(5),cc varchar2(5));

Inserted values in it--

insert into T1 values ('a','b','c');
commit;

Now in one scenario, if i wanted to update all columns with same value then I am doing by this way--

UPDATE T1 SET AA='x',BB='x',CC='x';

Is there any another way by which this update task can be accomplished considering in real time there may be quite large number of columns and all has to be updated with same value in one go?

I am using Oracle 11.2.0.1.0 - 64bit Production

Note: Usually there are very less any scenarios where same values are being updated for all columns. But for example consider a school database and a good student scores 10/10 marks in all subjects. :-)

Thanks.

1
  • 3
    No, and why should there? You only build the query once. Commented Sep 8, 2015 at 10:07

2 Answers 2

3

There is no way to do it in pure SQL. You must list down all the columns explicitly in the UPDATE statement.

And, believe me it is not a difficult task using a good text editor. Using the metadata you could get the list of column names in few seconds, all you need to do is prepare the SQL statement as per the syntax.

If you really want to do it dynamically, then you need to do it in PL/SQL and (ab)use EXECUTE IMMEDIATE. I would personally not suggest it unless you are just doing it for learning purpose.

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

Comments

0

You could try this:

UPDATE T1 SET AA='x',BB=AA,CC=AA;

1 Comment

Welcome to Stack Overflow! Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you've made.

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.