以语言环境为例(id-id)
我想要更新此区域设置的查询
我需要如何拆分字符串连字符应更改为下划线,最后 2 位数字应为大写
o/p 应该是:id_ID
我已经尝试过这个查询
UPDATE substring_index(locale,'-',1)=substring_index(locale,'-',1),
locale=REPLACE(locale,'-','_'),
substring_index(locale,'-',-1)=UPPER(substring_index(locale,'-',-1))
jlg_language_code_mapping;
请大家帮帮我..!
最佳答案
这里有一个选项:
SQL> with test (id, locale) as
2 (select 'arabic', 'ar' from dual union all
3 select 'indonesian', 'id-id' from dual union all
4 select 'malay', 'ms-my' from dual union all
5 select 'bulgarian', 'bg' from dual union all
6 select 'chinese (simplified)', 'zh-cn' from dual
7 )
8 select id, locale,
9 regexp_substr(locale, '^\w+') ||
10 replace(upper(regexp_substr(locale, '-\w+$')), '-', '_') new_locale
11 from test;
ID LOCALE NEW_LOCALE
-------------------- ------------------------- -------------------------
arabic ar ar
indonesian id-id id_ID
malay ms-my ms_MY
bulgarian bg bg
chinese (simplified) zh-cn zh_CN
SQL>
更新:
update your_table set
locale = regexp_substr(locale, '^\w+') ||
replace(upper(regexp_substr(locale, '-\w+$')), '-', '_');
关于mysql - MySQL如何拆分字段数据中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58437752/