Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3853212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:26:05+00:00 2026-05-19T17:26:05+00:00

I am using Oracle 11g, and I have a lot of stored procedure code

  • 0

I am using Oracle 11g, and I have a lot of stored procedure code that use the same SELECT statement (but a complex one), just a different input in a where clause:

select ... where ancestor = X

That SELECT statement right now is copied / pasted on hundreds of these, and I need to refactor so they use the same SELECT statement construction. Because all these stored procs already exist, the refactoring must work nicely with the current code, which looks like this:

create or replace procedure Foo
begin
  select quantity, amount from TBRawData, (select ... where ancestor = X) temp, where TBRAWData.StoreID = temp.StoreID;
end;

In a nutshell, I need a PL/SQL means of standardizing a SELECT, but a ref cursor, array types, collections, and such will not work because they are not treated like a table (thus cannot be inner joined to TBRAWData). Would a global temporary table work here, or something else?

Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:26:06+00:00Added an answer on May 19, 2026 at 5:26 pm

    View is good answer(thanks to Gary), but there is another possibility.

    You can create object type in database schema and table type referenced it:

    create or replace type TFooDataRecord as object (
       quantity number,
       amount number
    );
    
    create or replace type TFooDataList as table of TFooDataRecord;
    

    then, declare function returning required results:

    create or replace function GetFoo(pAncestor in number) return TFooDataList
    as 
      vResult TFooDataList;
    begin
    
      select TFooDataRecord(quantity, amount)
      bulk collect into vResult
      from TBRawData, (select ... where ancestor = pAncestor) temp, 
      where TBRAWData.StoreID = temp.StoreID;
    
      return vResult;
    
    end;
    

    then, you can use function in select statements and joins:

    select foo_func.amount 
    from 
      table( GetFoo(123) ) foo_func,
      some_another_table   foo2
    where 
      foo_func.quantity < foo2.quantity 
    

    Of course, you can place function into the package.
    But not object and table type declarations.

    This solution applicable if number of rows returned by function is not too big (depends on server hardware, but generally not more than 1000-2000 records).

    It better than use of view because Oracle would maintain single compiled and cached plan for parametrized query and don’t rebuild it for each query as in case of solution with view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using oracle 11g and have written a stored procedure which stores values
I am using Oracle 11g r2 . I have a table that stores images
On an Oracle 11g engine using PL/SQL I have logic that runs like this
I'm using oracle 11g sql developer I have a varchar2 column with dates as
I'm using Oracle 11g Schema I want to select the month and day from
Using .Net and Oracle 11g - I've been returning dataTables from a procedure inside
I am using oracle 11g and have a table with an XMLType. There are
Using Oracle 11g release 2, the following query gives an ORA-01790: expression must have
I have a select statement that I am trying to loop over and increment
I am developing an application using oracle 11g, Java(struts2) and Hibernate. I have table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.