Currency Codes

Description


You are developing an application for working with different currencies. You’ve decided to represent each currency using three letter codes from ISO 4217.

You’ve parsed some data that you found on the Internet and stored it in a currencies table, which has the following structure:

  • code: the unique code of the currency;
  • country: the name of the country in which this currency is used.

Unfortunately, your parser didn’t check the length of the codes and some erroneous data got into the table by mistake.

Your task is to delete all rows from the currencies table in which code is not exactly three letters long.

Example

For the following table currencies

code country
AD Andorra
AUD Australia
BRL Brazil
MXN Mexico
RUB Russia
RUR Russia
SEKR Sweden
USD USA

should become

code country
AUD Australia
BRL Brazil
MXN Mexico
RUB Russia
RUR Russia
USD USA
  • [execution time limit] 10 seconds (mysql)

Solution


1
2
3
4
5
6
7
CREATE PROCEDURE currencyCodes()
BEGIN
    DELETE FROM currencies
        WHERE CHAR_LENGTH(code) <> 3;

    SELECT * FROM currencies ORDER BY code;
END