Note that there are some explanatory texts on larger screens.

plurals
  1. PODealing with recursion (oracle)
    text
    copied!<p>I'm a having some problems trying to do some business logic for a client (web trading):</p> <p>My client has a table (simplified) like this one:</p> <pre><code>|| ID || OFFERED_PRODUCT_ID || DEMANDED_PRODUCT_ID || || 01 || 34 || 45 || || 01 || 34 || 16 || || 01 || 45 || 57 || || 01 || 47 || 57 || || 01 || 57 || 63 || || 01 || 16 || 20 || </code></pre> <p>Now, the app must show the largest trade chain, a trade chain is defined as the relation within offered and demanded products.</p> <p>This are trade chains: </p> <p>&lt; 34, 45, 57, 63> &lt;34, 16, 20> &lt;45, 57, 63> &lt;47, 57, 63> &lt;57, 63> &lt;16, 20></p> <p>I try to use C# to solve this, but given the volume of data it became impossible. A coworker of mine told recommends me to use recursion. I try to understand what he means, but I'm a client side developer, with no much knowledge of SQL.</p> <p>I did these:</p> <pre><code> select o.OFFERED_PRODUCT_ID, o.DEMANDED_PRODUCT_ID from TRADES o start with o.DEMANDED_PRODUCT_ID = (SELECT MIN(o.DEMANDED_PRODUCT_ID) from TRADES) connect by NOCYCLE prior o.DEMANDED_PRODUCT_ID = o.OFFERED_PRODUCT_ID; </code></pre> <p>I'm trying to start the recursion with the oldest product on the system (with the min identifiers). But It doesn't work. It gave me all the trade chains. I need just the largest one.</p> <p>Heres an output example:</p> <pre><code>OFFERED_PRODUCT_ID DEMANDED_PRODUCT_ID 9920896475501851 59587794888502550724 59587794888502550724 13197303523502765990 13197303523502765990 54010274740204405159 54010274740204405159 14505831337880766413 14505831337880766413 89607128670993987443 89607128670993987443 8802863939059413452 8802863939059413452 7779127922701247342 7779127922701247342 3810800421539873909 3810800421539873909 12423373218147473557 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload