1
我正在创建一个mysql函数,它接受一个varchar并将其更改为基于映射表的int。mysql存储过程是否支持像数组,哈希等数据类型?
select name, convert_to_code(country) from users where sex = 'male'
在此,convert_to_code()
函数采用一个国家名称(例如日本,芬兰..)并且将其更改为国家代码是基于映射表称为country_maping
的整数(例如1001,2310 ..)如下所示:
country_name (varchar) | country_code (int)
Japan | 1001
Finland | 2310
Canada | 8756
当前,存储的函数需要select country_code from country_mapping where country_name = country_name
并返回查询结果。是否可以在SP中创建一个散列数据结构来优化该过程,以便它不需要为每行匹配where
子句执行查询。
在此先感谢!