Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem accessing TABLE fields in SELECT statement

quingrouApr 25 2007

Hi,

We are currently using Oracle Database 10.2.0.2.0.

In the following code, using a function to access TABLE fields works, but not when accessing the table fields directly (in the latter case, I get a no data found exception).

Why is that?

Thanks for your help.

Olivier
PS: I do have a lengthy explanation of why we would want to do that as well as the full packages, etc... But I didn't want to bore you to no end.
I'll post it if required.

CREATE OR REPLACE PACKAGE PA_TEST_DEVTBL AS
   TYPE TBL_ROLCODE IS TABLE OF LANROLE.ROLCODE%TYPE INDEX BY BINARY_INTEGER;
   TYPE TBL_ROLLABEL IS TABLE OF LANROLE.ROLLABEL%TYPE INDEX BY BINARY_INTEGER;
end PA_TEST_DEVTBL;
/
 

CREATE OR REPLACE PACKAGE BODY PA_TEST AS
   -- Array containing the selected data
   TblRolCode PA_TEST_DEVTBL.TBL_ROLCODE;
   TblRolLabel PA_TEST_DEVTBL.TBL_ROLLABEL; 
   
   -- Functions created to retrieve each array data
   FUNCTION F_GET_ROLCODE( nIndex NUMBER ) RETURN LANROLE.ROLCODE%TYPE IS
   BEGIN
      RETURN TblRolCode( nIndex );
   END F_GET_ROLCODE;
 
   FUNCTION F_GET_ROLLABEL( nIndex NUMBER ) RETURN LANROLE.ROLLABEL%TYPE IS
   BEGIN
      RETURN TblRolLABEL( nIndex );
   END F_GET_ROLLABEL;
 
   PROCEDURE S_TEST (
...
 
-- THIS DOESN'T WORK (ORA-01403: no data found)
OPEN cReturn FOR
SELECT TblRolCode( ROWNUM ),
TblRolLabel( ROWNUM )
FROM TABLE( CAST( tblRows AS T_TBL_NUMBER ) );

 -- BUT THIS WORKS !!!
OPEN cReturn FOR
SELECT F_GET_ROLCODE( ROWNUM ) AS ROLCODE,
F_GET_ROLLABEL( ROWNUM ) AS ROLLABEL
FROM TABLE( CAST( tblRows AS T_TBL_NUMBER ) );

.. 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 23 2007
Added on Apr 25 2007
0 comments
312 views