跳到主要内容 跳到补充内容

Mapping

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

语法:  

Mapping( loadstatement | selectstatement )

 

mapping 前缀可置于 LOADSELECT 语句之前,并将正在加载的语句的结果存储为映射表。映射提供了一种有效的途径在脚本执行过程中替代字段值,例如:将 US、U.S. 或替换为 USA。映射表必须有两个字段,第一个字段包含比较值,第二个字段包含所需的映射值。映射表暂时存储在内存中,执行脚本后将自动删除。

使用 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

本页面有帮助吗?

如果您发现此页面或其内容有任何问题 – 打字错误、遗漏步骤或技术错误 – 请告诉我们如何改进!