I have a table with a string and several fields separated by | (pipe)
I need to bring each field into a column. I even got a way, the problem is that when a record does not have the field filled in the string brings ||.
Detail, I can not change the original string.
Would anyone have a solution in Oracle SQL ??
I did this:
CREATE TABLE t_1 ( strings varchar2(4000));
/
INSERT INTO t_1
VALUES ('99|1500001|JOANA PRADO |08227525490|BRA|0||');
INSERT INTO t_1
VALUES ('99|1500002|LUCIANA XIMENES SILVA||BRA|0||');
INSERT INTO t_1
VALUES ('99|1500003|JULIA ROBERTS|44303539805|USA|0||');
COMMIT;
SELECT regexp_substr(strings,'[^|]+',1,1) identificador,
regexp_substr(strings,'[^|]+',1,2) id,
regexp_substr(strings,'[^|]+',1,3) nome,
regexp_substr(strings,'[^|]+',1,4) cpf,
regexp_substr(strings,'[^|]+',1,5) pais,
regexp_substr(strings,'[^|]+',1,6) tipo
FROM t_1
Note that registration id 1500002 does not have cpf and there the parent field ends up occupying the space of the CPF.