在 oracle SP 中删除“-”的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1041288/
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-18 18:28:01  来源:igfitidea点击:

best way to remove '-' in oracle SP

oracle

提问by Adrian Lynch

I have an Oracle stored procedure, that has as one of its parameters a Social Security Number (SSN) in the hyphenated format xxx-xx-xxxx. What is the best way to remove the hyphens, so that I transform the SSN to a xxxxxxxxx format?

我有一个 Oracle 存储过程,它的参数之一是带连字符格式 xxx-xx-xxxx 的社会安全号码 (SSN)。删除连字符的最佳方法是什么,以便我将 SSN 转换为 xxxxxxxxx 格式?

回答by Adrian Lynch

REPLACE('xxx-xx-xxxx', '-', '')

Or as @jitter mentions, the third argument defaults to '', so:

或者正如@jitter 提到的,第三个参数默认为'',所以:

REPLACE('xxx-xx-xxxx', '-')

回答by Adrian Lynch

To answer your second question, if you already have the xxx-xx-xxxx version, don't overwrite it and you'll have both.

回答你的第二个问题,如果你已经有 xxx-xx-xxxx 版本,不要覆盖它,你会同时拥有。

If you're expecting xxxxxxxxx and you want xxx-xx-xxxx, piece it together using:

如果您期待 xxxxxxxxx 并且您想要 xxx-xx-xxxx,请使用以下方法将其拼凑:

SUBSTR('xxxxxxxxx', 0, 3) || '-' || SUBSTR('xxxxxxxxx', 3, 2) || '-' || SUBSTR('xxxxxxxxx', 5, 4)

回答by Priyank

mystring := v_mySSN; select substr(mystring, 0, 3)||'-'||substr(mystring, 3, 2)||'-'||substr(mystring, 5, 4) into varialble from some_table;

mystring := v_mySSN; 从 some_table 中选择 substr(mystring, 0, 3)||'-'||substr(mystring, 3, 2)||'-'||substr(mystring, 5, 4) 到变量中;

This would work inside a procedure to select your value in a variable correctly.

这将在一个过程中起作用,以正确选择变量中的值。