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!

Cursors, unions and ORA-22902

450281Nov 17 2005 — edited Nov 17 2005

I am currently toying with a union query whose members contain a cursor, and I get an ORA-22902 error.

Here is the query :

 select owner "obj_owner"
          ,table_name "obj_name"
	  ,'TABLE' "obj_type"
	  ,cursor(select owner
                     from all_synonyms
                     where table_owner like all_tables.owner
                     and table_name like all_tables.table_name
                 ) "syn_owner"
 from all_tables 
 where owner in ('USERA','USERB','USERC')
 union
 select owner "obj_owner"
          ,object_name "obj_name"
	  ,'PACKAGE' "obj_type"
	  ,cursor(select owner
                     from all_synonyms
                     where table_owner like all_objects.owner
                        and table_name like all_objects.object_name
                 ) "syn_owner"
 from all_objects
 where owner in ('USERA','USERB','USERC')
   and object_type like 'PACKAGE'
 order by "obj_owner" asc, "obj_name" asc
 ;

And here is the detailed error message :

ORA-22902 CURSOR expression not allowed
Cause: CURSOR on a subquery is allowed only in the top-level SELECT list of a query.
Action: Remove the CURSOR expression and retry the operation.

Now, I could easily get similar results otherwise, but I am curious as to why this query is erroneous, and I would like to know if it is possible to edit it to avoid this error.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2005
Added on Nov 17 2005
4 comments
1,297 views