Replace characters in column during SELECT SQL

0

I have a column in my database that goes something like this:

 -----------------
|     nombre      |
 -----------------
|   225/65/17  etc|
|  225/55C R17 etc|
|   xxx225/65 r16 |
|   235/65  17 etc|
|   etc 215/65 R17|
 -------------

And I need to do select searching by name in which the search parameter is for example 2256517 , that is, I need to replace the / with a "nothing" ''

EDIT:

I've realized that not everything is separated by a bar / , in some there is a space with a R in others the second "field" ends in a letter, space + another letter ...

    
asked by Pavlo B. 15.02.2018 в 10:57
source

2 answers

1

You can use replace Replace

 select * from Tabla 
  where replace(Campo,'/','') = '2256517'
    
answered by 15.02.2018 / 16:12
source
2

You can use the feature REPLACE

If you want to filter the search you should include it in the WHERE as follows:

SELECT columna
FROM nombre_tabla
WHERE REPLACE(nombre,'/','')='2256517';

In case you want to filter the output you should include the function in the SELECT:

SELECT REPLACE(columna,'/','') "Columna"
FROM nombre_tabla;

In case they contain other characters you should change the query and therefore replace or in case they all start with 2 which is the feeling that you have given me you can use RTRIM and LTRIM to delete the characters from the left and the right that does not interest you. In your case it would be something like this:

SELECT columna
FROM nombre_tabla
WHERE LTRIM(RTRIM(REPLACE(nombre,'/',''), 'r Rx'), 'r Rx')='2256517';

This would eliminate the characters to the left and right that are in quotation marks each one separately, and it would only be necessary to play with the REPLACE, RTRIM and LTRIM until coming up with the combination depending on the tuples to be obtained.

    
answered by 15.02.2018 в 17:18