ref cursor is slower than issuing the same query directly
533958May 16 2007 — edited May 17 2007We are building SQL dynamically in PL/SQL procedure. SQL is complex enough (pivoting, UNIONS, spatial operations, complex underlying view joining many tables). Then we are opening ref cursor output parameter using the following syntax:
OPEN p_cursor FOR v_sql using p_param1, p_param2;
Then client code iterates through the rows of the cursor. It takes about a minute. If we run the SQL stored in v_sql variable directly in SQL Plus (replacing bind variables with values of course), we get 4 seconds response time.
QUESTION: what makes ref cursor being so slow comparing with direct execution of the same query?