如何将记录从字母数字更新为仅数字?

时间:2013-05-04 15:49:51

标签: sql oracle

主题:数据清理 - 检查异常值 - 超出模式

我正在尝试从值'A123'更新custID到'123','22A4'到'224'我只想在custID中保留整数,我不希望custID包含任何非整数字符(A到Z和a到z)

CREATE TABLE customer (
custID VARCHAR2(10) PRIMARY KEY,
custName VARCHAR2(30)
);
INSERT INTO customer(custID,custName) VALUES ('A123','Angel');
INSERT INTO customer(custID,custName) VALUES ('22A4','Chris');
INSERT INTO customer(custID,custName) VALUES ('2333','Chris');

UPDATE customer
SET custID =            -- I want to change 'A123' to '123', '22A4' to '224'
WHERE         ;

2 个答案:

答案 0 :(得分:2)

使用此...

UPDATE customer
SET custID = REGEXP_REPLACE(custID, '[^0-9]+', '')
WHERE         ;

或试试这个......

UPDATE customer
SET custID = REGEXP_REPLACE(custID, '[^[:digit:]]+', '')
WHERE         ;

答案 1 :(得分:0)

UPDATE customer SET custid = REGEXP_SUBSTR ( custid , '[0-9]*' ) WHERE

REGEXP_SUBSTR Oracle documentation