there are 2 variables called x and y ,x contains 1,2 and y
contains 3,4 we have to swap the values from x to y and y
to x with out using dummy variables and it can be done only
by using a single statement ? how?

Answer Posted / nanne saheb c

Assume that the sample table is as below
X Y
------------
1 3
2 4

Update sample set
X=decode(X,1,3,2,4),
Y=decode(Y,3,1,4,2);

(OR)
Update sample set
X = (case when 1 then 3
when 2 then 4
end),
Y = (case when 3 then 1
when 4 then 2
end);

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is application trigger?

733


what is the difference between nested subquery and correlated subquery?

744


What is sql clause?

740


What is the primary key?

700


Can we insert delete data in view?

726






When should I use nosql database?

727


Which is faster joins or subqueries?

715


Can triggers stop a dml statement from executing on a table?

805


What is flag in sql?

738


What is synonyms?

771


What is the use of function in sql?

728


What is pls_integer in pl sql?

753


Explain commit, rollback and savepoint.

766


What are the string functions in sql?

720


What is secondary key?

670