Well if you use Oracle I see at least two alternatives to your question. You use Regular Expression and another solution would be to use the "substr" function to fetch the numbers and then sort them. Here’s an example.
CREATE TABLE tab_notas(identificador VARCHAR(10) NOT NULL) -- Tabela exemplo
-- Registros de exemplo
BEGIN
INSERT INTO tab_notas(identificador) VALUES('XYNDY00001');
INSERT INTO tab_notas(identificador) VALUES('ZYNDY00011');
INSERT INTO tab_notas(identificador) VALUES('XYXDY00104');
INSERT INTO tab_notas(identificador) VALUES('VYNDY00206');
INSERT INTO tab_notas(identificador) VALUES('PYNDY00020');
INSERT INTO tab_notas(identificador) VALUES('MYODY02301');
INSERT INTO tab_notas(identificador) VALUES('HYNDZ00701');
INSERT INTO tab_notas(identificador) VALUES('KINDY00801');
INSERT INTO tab_notas(identificador) VALUES('NYNDY00301');
INSERT INTO tab_notas(identificador) VALUES('KYNDY00111');
INSERT INTO tab_notas(identificador) VALUES('BYMDP00211');
INSERT INTO tab_notas(identificador) VALUES('PYNDY00806');
INSERT INTO tab_notas(identificador) VALUES('TYNDE00653');
INSERT INTO tab_notas(identificador) VALUES('AINDY00207');
INSERT INTO tab_notas(identificador) VALUES('RYNDM00511');
END;
-- 1: Primeira Solução
select regexp_replace(n.identificador, '[^0-9]') identificador_numero_1,
to_number(regexp_replace(n.identificador, '[^0-9]')) identificador_numero_2,
n.identificador
from tab_notas n
order by to_number(regexp_replace(n.identificador, '[^0-9]'));
-- 2: Segunda Solução
select substr(n.identificador, 6, 5) identificador_numero_1,
to_number(substr(n.identificador, 6, 5)) identificador_numero_2,
n.identificador
from tab_notas n
order by to_number(substr(n.identificador, 6, 5));
You want to sort as another list, would that?
– rbz
Solve what? That’s right. The first 5 characters are equal, the 5th. is different one of them is "1", the other is "2", the 2 comes after the 1, is normal. If you wanted it to be numeric you should use number or keep the number of digits equal. If one of them was " xyz0002" it would be right.
– Maniero
Yes, the ordering is correct because it is dealing with alphanumerics. If the column
Campo
always has this format, can solve it. Has?– João Martins
It will always have this format. Actually it’s more like xyz1,,, xyz11
– gabrielfalieri
@Maniero the easiest solution for me was to equal the same fields
– gabrielfalieri