# 映射

mapping 前缀用于创建映射表，例如，此映射表在脚本运行期间可用于替换字段值和字段名。

语法：

Mapping( loadstatement | selectstatement )

该 mapping 前缀可置于 LOAD 或 SELECT 语句之前，并将正在加载的语句的结果存储为映射表。映射提供了一种有效的途径在脚本执行过程中替代字段值，例如：将 US、U.S. 或 America 替换为 USA。映射表必须有两个字段，第一个字段包含比较值，第二个字段包含所需的映射值。映射表暂时存储在内存中，执行脚本后将自动删除。或者，您可在脚本执行的更早阶段删除映射表，方法是使用 [Drop table](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/drop-table.htm) 语句的 Drop mapping table 变体。

使用 Map … Using 语句、Rename Field 语句、Applymap() 函数或 Mapsubstring() 函数可访问映射表的内容。

示例：

在此例中，我们加载了销售人员和国家代码（表示销售人员所居住的国家）的列表。我们使用表格将国家代码映射到国家，以便将国家代码替换为国家名称。在映射表中仅定义了三个国家，其他国家代码已映射到'Rest of the world'。

```
// Load mapping table of country codes:
map1:
mapping LOAD * 
Inline [
CCode, Country
Sw, Sweden
Dk, Denmark
No, Norway
] ;
// Load list of salesmen, mapping country code to country
// If the country code is not in the mapping table, put Rest of the world
Salespersons:
LOAD *, 
ApplyMap('map1', CCode,'Rest of the world') As Country 
Inline [
CCode, Salesperson 
Sw, John
Sw, Mary
Sw, Per 
Dk, Preben
Dk, Olle
No, Ole 
Sf, Risttu] ;
// We don't need the CCode anymore
Drop Field 'CCode';
```

最终生成的表格如下所示：

Mapping table

| Salesperson | Country |
| --- | --- |
| John | Sweden |
| Mary | Sweden |
| Per | Sweden |
| Preben | Denmark |
| Olle | Denmark |
| Ole | Norway |
| Risttu | Rest of the world |

## 了解详情

* [Load](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Load.htm)
* [Select](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Select.htm)
* [Map](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Map.htm)
* [Unmap](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Unmap.htm)
* [ApplyMap 脚本函数](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/MappingFunctions/ApplyMap.htm)
* [MapSubstring 脚本函数](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/MappingFunctions/MapSubstring.htm)
* [映射函数](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/MappingFunctions/mapping-functions.htm)
* [Drop table](https://help.qlik.com/zh-CN/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/drop-table.htm)