0
I need to hit the SQL below for the database Oracle.
The idea is to retrieve the code from the table Produto associated with the table code Matriz.
In this structure, the Matriz is related to at least one Filial and this contains the link to Produto. But a Filial may have a Filial, that may have a Filial, etc..
That is, to access the related codes in the tables Produto and Matriz, I need a backward propagation of existing information in the relational table Filial, which I resolved with the START WITH and CONNECT BY PRIOR.
I succeeded by testing the sub-select below separately with an example record. But I can’t extract all the records.
I tried to do it this way (I hope you’re not confused), but subselect doesn’t see the external table.
select produto.nome, produto.qtde, tabelaAux.codigo from produto
left join (select * from
(select matriz.codigo as codMatriz, matriz.codFilial as codFilial
from matriz
left join filial on filial.codC = matriz.codigo
start with filial.codA = produto.codigo --falha aqui
connect by prior filial.codigoPai = filial.codigo)
where codMatriz is not null)
tabelaAUX on tabelaAUX.codFilial = produto.codFilial;

I recommend you use the site http://sqlfiddle.com, put the base structure with some data, we can help you
– Tiedt Tech
I do not understand because in general CONNECT BY is used for SQL S recursives , a classic example is the functio (matricula,nome,matricula_do_superior) https://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm
– Motta