[英]How to remove part of string in a column based on content of another column in Oracle
I have database tables that look like this:我有如下所示的数据库表:
Class | ClassNumber
S | S3
T | T37
T | T50
S | SS07
S | S4
S | SG27
ClassNumber
contains the value of Class
and another identifier. ClassNumber
包含Class
的值和另一个标识符。 So meaning that if the Class
is S
, then it means ClassNumber
must begin with S
and followed by another identifier.这意味着如果
Class
是S
,则意味着ClassNumber
必须以S
开头,后跟另一个标识符。
I would like to extract the identifier in ClassNumber
.我想提取
ClassNumber
的标识符。
If I use the REPLACE
function, it will replace all characters that match.如果我使用
REPLACE
函数,它将替换所有匹配的字符。 But I only want the prefix to be removed.但我只想删除前缀。
SELECT REPLACE(ClassNumber, Class, '') FROM MY_TABLE
This will make SS07
to be 07
instead.这将使
SS07
改为07
。 But I want it to return S07
.但我希望它返回
S07
。
How do I do this?我该怎么做呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.