Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Update value of table row which could contain href without target

Imagine you have table called Information which could have two columns id and text_with_hrefs_with_or_without_target_blank, which we want to update

So for example one of many rows could have stored this value in the column text_with_href....

first href with target blank before

<a target="_blank" href="http://link1.com">Link1</a>

maybe another text and link with target

<a href="http://www.link2.com">Link2</a>

and last href link with target blank after href

<a href="http://www.link3.com" target="_blank">Link3</a>

I would like to update all similiar rows in table Information to add target=_blank to hrefs in those parts of rows which havent one

so the result for this row I mentioned would look like

first href with target blank before

<a target="_blank" href="http://link1.com">Link1</a>

maybe another text and link with target

<a href="http://www.link2.com" target="_blank">Link2</a>

and last href link with target blank after href

<a href="http://www.link3.com" target="_blank">Link3</a>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As pointed out in comments you better off doing it in your client/presentation code.

Now if you absolutely need to do this in the database, especially if it's just a one time thing, and assuming that you have one and only one link <a></a> per row you can do something as simple as this

UPDATE information
   SET text_with_hrefs_with_or_without_target_blank = 
           replace(text_with_hrefs_with_or_without_target_blank, '<a ', '<a target="_blank" ')
 WHERE text_with_hrefs_with_or_without_target_blank NOT LIKE '%target="_blank"%'

SQLFiddle

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda