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

Why do we need a foreign key?

551


Can a foreign key have a different name?

513


What is the use of sql trace?

481


What are sql*plus environment variables?

559


how to get @@error and @@rowcount at the same time? : Sql dba

529






Why is sql important?

579


what are the authentication modes in sql server? : Sql dba

535


What is a nested table in word?

534


What is the maximum rows in csv?

485


What is package in pl sql?

579


Enlist the advantages of sql.

571


What is the sql case statement?

579


Why we use joins in sql?

540


How can you get sql*loader to commit only at the end of the load file? : aql loader

554


What are sql injection vulnerabilities?

500