Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何拆分字段数据MySQL中的字符串_Mysql_Sql_Sql Update - Fatal编程技术网

如何拆分字段数据MySQL中的字符串

如何拆分字段数据MySQL中的字符串,mysql,sql,sql-update,Mysql,Sql,Sql Update,示例的区域设置(id) 我需要此区域设置的更新查询 我需要如何拆分字符串连字符应改为下划线,最后2位应为大写 o/p应为:id\U id 我试过这个问题 UPDATE substring_index(locale,'-',1)=substring_index(locale,'-',1), locale=REPLACE(locale,'-','_'), substring_index(locale,'-',-1)=UPPER(substring_index(locale,'-',-1)) jlg

示例的区域设置(id)

我需要此区域设置的更新查询

我需要如何拆分字符串连字符应改为下划线,最后2位应为大写

o/p应为:id\U 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+$')), '-', '_');
这里有一个选择:

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+$')), '-', '_');

谢谢兄弟。。但我想更新我上面所做的查询。你能做些改变吗?当然,我刚做了。看一看。它只更新了一个单词作为一个示例(id),它应该更新为id\u id,你可以看到上面的图片,而不是连字符(-),应该加下划线(\u),最后两个字母应该是大写。对不起,必须脱机。抱歉#2,忘记了用下划线替换连字符-现已修复。但是,从小写到大写,就像你说的那样。。。至少,这就是我的例子,不是吗?谢谢兄弟。。但我想更新我上面所做的查询。你能做些改变吗?当然,我刚做了。看一看。它只更新了一个单词作为一个示例(id),它应该更新为id\u id,你可以看到上面的图片,而不是连字符(-),应该加下划线(\u),最后两个字母应该是大写。对不起,必须脱机。抱歉#2,忘记了用下划线替换连字符-现已修复。但是,从小写到大写,就像你说的那样。。。至少,这是我的示例所显示的,不是吗?您应该问一个与MySQL DB相关的问题,但不是Oracle,它没有函数
substring\u index()
,但MySQL有。因此,我将从标题和标记区域删除Oracle。@BarbarosÖzhan至少我在MySQL中尝试过,但希望在Oracle中得到答案。你应该问一个与MySQL数据库相关的问题,但Oracle没有函数
substring_index()
,但MySQL有。所以,我正在将Oracle从标题和标记区域中删除。@BarbarosÖzhan至少我已经在MySQL中试用过,但希望在Oracle bro中得到答案