SELECT returns no records when Forms executes the query in a function
714253Aug 27 2009 — edited Aug 27 2009I'm trouble-shooting an issue with some client code in Forms 10.1.2.0 running against an Oracle 10g database. The problematic code is a query which SELECTs data from 1 table (TABLE_X). Performed by itself, either in Toad or SQL*Plus, the query returns over 500,000 records so I know it is well-constructed. The query is located within a procedure in a DB package and defined as an explicit cursor based on a strongly-typed cursor variable, whose definition is also in the same package.
The flow goes something like this:
1. User clicks button on the form
2. Forms program unit
<li> declares instance of a cursor variable (the REF CURSOR type defined in the database package)</li>
<li> calls the query procedure from the database package, storing result in the cursor var.</li>
3. DB PROCEDURE for the query
<li> declares local instance of cursor variable</li>
<li> opens cursor, defining the SELECT query</li>
<li> has EXCEPTION WHEN OTHERS block, to handle any possible problems with opening the cursor</li>
<li> RETURNs the cursor variable</li>
4. Forms program unit
<li> sets up a loop to use the cursor variable, defined to EXIT WHEN cur_var%NOTFOUND</li>
<li> FETCHes the next record from the cursor</li>
<li> writes the current record to an output file</li>
<li> closes the cursor after exiting the loop</li>
What happens is the call to the procedure works fine, but the loop following it is never executed, as it exits on the first check of EXIT WHEN..NOTFOUND. However, since an exception was never raised it has been a bugger to troubleshoot. According to the DB admin, there were also no errors in the system or session logs during my tests. I have done extensive testing on this for over a week now, making many stripped-down versions of this code.
The two tests that have been my best clues so far:
1. The only way I can make this query work from Forms is to NOT define it within a function or procedure, whether in the database or in a Forms function. The moment I take the query definition out of the function and place it inline in the Forms code, the query returns the results expected.
2. I made a version of the function which, instead of using an explicit cursor, it does a SELECT ... INTO variable_x, where "variable_x" is of TABLE_X%ROWTYPE. It then RETURNs the variable_x. During runtime, when control is passed to this function and the query is attempted, the NO_DATA_FOUND exception is raised ("ORA-01403: no data found").
It seems that the choke-point is when Forms tries to perform the query that's within a function, whether that function is stored in the form itself, or in the database. The only possibilities that occur to me are potential permission problems, or some Forms property that's limiting the ability to run the query. On this last point: there are many other queries run from within the same form which have no problems. I am such a Forms newbie though, that I get lost in all the properties and may be overlooking an important one. However, I truly think this tends more towards a permissions problem.
Any ideas, fellow Forms / SQL developers?