Removing comma from the pl sql column

Asked

Viewed 116 times

1

Good afternoon, I have a table that has names. In some lines the name is separated by comma. Ex: Alberto, Luiz

I want to change these lines to stay Luiz Alberto

DECLARE
  final VARCHAR(50);
  inicio VARCHAR(50);
  string_pronta VARCHAR(110);
BEGIN
  SELECT substr(NOME, instr(NOME, ',') + 1) into final FROM participantes;
  SELECT substr(NOME, 1, instr(NOME, ',') - 1) into inicio FROM participantes;
  string_pronta := inicio || ' ' || final;
  UPDATE participantes
   SET NOME := string_pronta;
END;

1 answer

0


This way below you will get the expected result. Possibly there is another even more elegant way to be done, but this one works.. :)

Table participants: Constante, Filipe | de Tal, Fulano

UPDATE participantes SET nome = LTRIM(REPLACE(REGEXP_SUBSTR(nome, ',[^,]+'), ',') || ' ' || REGEXP_SUBSTR(nome, '[^,]+'));

Participants table (RESULT): Filipe Constante | So-and-so

If you have another need, explain better in the question that I adjust the answer.

I hope I’ve helped.

The reference for this reply was: https://www.techonthenet.com/oracle/functions/replace.php

  • Sorry, I typed wrong. Besides removing the comma I need to invert the name of Constant, Felipe the result would be: Felipe Constante

  • I adjusted the update that will solve your problem.

  • Give feedback if it worked for you.

  • It worked, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.