T
T
Timur_gis_882020-12-18 11:04:28
PostgreSQL
Timur_gis_88, 2020-12-18 11:04:28

How to write a replace function instead of a set of replaces in sql?

select 
replace(replace(replace(replace(replace(name
,'олег','О')
,'Олег','О')
,'виктор','В')																												
,'саша','С')																									
,'лена','Л')	
from
table1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail E, 2020-12-18
@Timur_gis_88

What is the task? judging by the request code, you are trying to replace the name with an initial ... if so, then probably like this:

Select 
      case when <условие при котором надо брать 2 символа> then
           UPPER(Left(name, 2))
     else 
           UPPER(Left(name, 1))
      end
from
table1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question