On this page

Countries by ISO code

H2Read onlyScripts Gallery

A list parameter in practice: pass several codes at once, each sent to the database as its own typed value.

Verification status. The output below was captured with this query on the WORLD sample database, as shown in List parameters. The header lines added here do not change the result.

When to use it

  • Look up a list of keys from a ticket in one call.
  • See how LIST OF TEXT becomes IN (?, ?, ?).

The Script

Download world-countries-by-codes.sql

-- @description: Countries by ISO code
-- @tags: world, sample, geo, list
-- @status: stable
-- @access: read
-- @dialect: H2
-- @param codes LIST OF TEXT "Three-letter country codes"
SELECT CODE, NAME FROM COUNTRY WHERE CODE IN (${codes}) ORDER BY CODE;

Parameters

ParameterTypeDefaultMeaning
codesLIST OF TEXTRequiredThree-letter country codes

Install and run it

  1. Save the file in your Scripts Library folder (scripts in the installation folder by default), for example as gallery/world-countries-by-codes.sql.
  2. Open the sample database: CONNECT WORLD;.
  3. Check what it declares: LIB SHOW gallery/world-countries-by-codes.sql;
  4. Run it: @gallery/world-countries-by-codes.sql codes=('FRA', 'DEU', 'ITA');

What you get

One row per code found, with the country name, sorted by code.

@countries/by-codes.sql codes=('FRA', 'DEU', 'ITA');
SELECT CODE, NAME FROM COUNTRY WHERE CODE IN (${codes}) ORDER BY CODE
-- codes = ('FRA', 'DEU', 'ITA')
|----|----------------------------------------------------|
|CODE|NAME                                                |
|----|----------------------------------------------------|
|DEU |Germany                                             |
|FRA |France                                              |
|ITA |Italy                                               |
|----|----------------------------------------------------|

3 rows fetched in 0 ms.
Running the Script with three codes

Limits

  • A list holds 1 to 1000 values, without NULL.
  • One value is still written as a list: codes=('FRA').

Found something wrong or unclear on this page? , with the page address.