oracle - SQL how to check whether a variable contrains non-integer character and remov the non-integer character -


i trying check whether variable 'prodno' contains non-integer character. if does, remove non-integer character.

-- expected output:  prodno a18 prodno k67   drop table ass3_product cascade constraints; create table ass3_product ( prodno varchar2(30) primary key, prodname varchar2(30), purchasecost number(6,2) ); insert ass3_product values ('23','prod one', 10); insert ass3_product values ('54','prod two', 50); insert ass3_product values ('a18','prod three', 35); insert ass3_product values ('9','prod four', 4); insert ass3_product values ('k67','prod five', 15);  select prodno ass3_product prodno '%[abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz]%'; 

like not support ranges seem think - supports wildcard search using % , _. need use regular expressions this

to remove non-integer value use regexp_replace:

select regexp_replace(prodno, '\d', '') ass3_product 

to test condition, compare result of replace original value:

select regexp_replace(prodno, '\d', '') ass3_product prodno <> regexp_replace(prodno, '\d', ''); 

another possibility use regexp_like. following select rows prodno not start digit:

select regexp_replace(prodno, '\d', '') ass3_product regexp_like(prodno, '^[^0-9]+') 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -