++ for the good answer but just to add to it, use set based logic rather than procedural row by row processing;Use the server resources rather that the client's. Furthermore even opening just firehose cursors for fetching that amount of rows will place loads of stress over the connection line if not optimised for batch fetching