如何在字段数据oracle中分割字符串

问题描述 投票:0回答:1

在示例中的语言环境(id-id)

我要更新此语言环境的查询

我如何分割字符串连字符应更改为下划线,后两位数字应为大写

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;

请帮助我..!

enter image description here

php mysql sql oracle11g phpmyadmin
1个回答
0
投票

这里是一个选项:

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    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+') ||
           upper(regexp_substr(locale, '-\w+$'));
© www.soinside.com 2019 - 2024. All rights reserved.