SQL Oracle:从字符串中删除前 4 个字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20828865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:34:52  来源:igfitidea点击:

Oracle: remove first 4 characters from a string

sqlstringoracle

提问by Gamidron

So I want to remove the first 4 characters from a string in oracle. Those characters can be different every time. In my case I need to take away the first 4 characters of an IBAN and put them at the end of the string. I got the part of putting them to the end of the string but I can't get the first 4 characters to be removed. Every solution I find on the internet removes specified characters, not characters from a certain position in the string (1 to 4). I used the code below to get the first 4 characters to the end of the string and wanted to try something similar for removing them at the front but without success.

所以我想从 oracle 中的字符串中删除前 4 个字符。这些角色每次都可能不同。就我而言,我需要去掉 IBAN 的前 4 个字符并将它们放在字符串的末尾。我得到了将它们放在字符串末尾的部分,但我无法删除前 4 个字符。我在互联网上找到的每个解决方案都会删除指定的字符,而不是字符串中某个位置(1 到 4)的字符。我使用下面的代码将前 4 个字符移到字符串的末尾,并想尝试类似的方法将它们从前面删除,但没有成功。

SELECT SUBSTR(iban_nummer, 1, 4) INTO iban_substring FROM dual;
iban_nummer := iban_nummer || iban_substring;

回答by Guntram Blohm supports Monica

See the docs:

查看文档

substring_length ... When you do not specify a value for this argument, then the function returns all characters to the end of string. When you specify a value that is less than 1, the function returns NA.

substring_length ... 如果您没有为此参数指定值,则该函数将返回到字符串末尾的所有字符。当您指定一个小于 1 的值时,该函数返回 NA。

So iban_nummer := substr(iban_nummer, 5) || substr(iban_nummer, 1,4)should work. The first part selects all characters beginning from the 5th, the second character numbers 1..4.

所以iban_nummer := substr(iban_nummer, 5) || substr(iban_nummer, 1,4)应该工作。第一部分选择从第 5 个开始的所有字符,第二个字符编号为 1..4。

回答by Sai

update table_name set col_name=substr(col_name,5);

回答by ElvisZhu

try regexp, like:

尝试regexp,例如:

SELECT regexp_replace(t.iban_nummer,'(.{4})(.*)','') FROM t;