I was tidying up some old E-mails recently and found this example from 2008. I think it may have been from a Spanish student who needed help with his homework. He had a table called COCHES. It contained details of car manufacturers (in the column called TIPO). Each one made cars with 3 or 5 doors. He needed to update the table with one SQL statement and change the values in the doors (PUERTAS) column from 3 to 5 and vice versa. I suggested he could do it with decode as shown below:
SQL> select * from coches;
TIPO PUERTAS
---------- ----------
Austin 5
Morris 3
SQL> update coches set puertas = decode (puertas,3,5,5,3);
2 rows updated.
SQL> select * from coches;
TIPO PUERTAS
---------- ----------
Austin 3
Morris 5
SQL>
No comments:
Post a Comment