Syntax: DECODE
SQL>
SQL> CREATE TABLE myCar
2 (
3 MAKER VARCHAR (25),
4 MODEL VARCHAR (25),
5 PRICE NUMERIC
6 );
Table created.
SQL>
SQL> INSERT INTO myCar VALUES('CHRYSLER','CROSSFIRE',33620);
1 row created.
SQL> INSERT INTO myCar VALUES('CHRYSLER','300M',29185);
1 row created.
SQL> INSERT INTO myCar VALUES('HONDA','CIVIC',15610);
1 row created.
SQL> INSERT INTO myCar VALUES('HONDA','ACCORD',19300);
1 row created.
SQL>
SQL> INSERT INTO myCar VALUES('FORD','MUSTANG',15610);
1 row created.
SQL> INSERT INTO myCar VALUES('FORD','LATESTnGREATEST',NULL);
1 row created.
SQL> INSERT INTO myCar VALUES('FORD','FOCUS',13005);
1 row created.
SQL>
SQL> SELECT * FROM myCar;
MAKER MODEL PRICE
------------------------- ------------------------- ----------
CHRYSLER CROSSFIRE 33620
CHRYSLER 300M 29185
HONDA CIVIC 15610
HONDA ACCORD 19300
FORD MUSTANG 15610
FORD LATESTnGREATEST
FORD FOCUS 13005
7 rows selected.
SQL>
SQL> SELECT
2 model,
3 DECODE(maker, 'CHRYSLER','DOMESTIC'
4 ,'FORD','DOMESTIC'
5 ,'FOREIGN')
6 FROM myCar;
MODEL DECODE(M
------------------------- --------
CROSSFIRE DOMESTIC
300M DOMESTIC
CIVIC FOREIGN
ACCORD FOREIGN
MUSTANG DOMESTIC
LATESTnGREATEST DOMESTIC
FOCUS DOMESTIC
7 rows selected.
SQL>
SQL>
SQL> drop table myCar;
Table dropped.
Related examples in the same category