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 947363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:04:18+00:00 2026-05-15T23:04:18+00:00

I have a procedure that is using a temp table. I want to get

  • 0

I have a procedure that is using a temp table. I want to get rid of the temp table and use a collection to remove I/O. it has about 5000 records.

I want to insert data into this collection then I want to access the collection like:

select * from table(my_type_for_gtt)

I could not find an example of this. I’m confused, do I have to first create a record type and then create as table of?

can someone please show a quick small example?

  • 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-15T23:04:19+00:00Added an answer on May 15, 2026 at 11:04 pm

    You are heading in the right direction – first create your types

    CREATE TYPE myEntry
    AS
    OBJECT
      (attr1 NUMBER,
       attr2 VARCHAR2(20)
      );
    
    CREATE TYPE myCollection AS TABLE OF myEntry;
    

    Next some example functions returning ‘rows’ of your collection

    CREATE OR REPLACE FUNCTION ExampleMyCollection1
    RETURN myCollection  
    IS
       lCol myCollection := myCollection(); /* Must initialise empty collection */
    BEGIN
        lCol.EXTEND(1000);
        /* Populate the collection entries with objects */
        FOR i IN 1..1000 LOOP
            lCol(i) := myEntry(i,'An entry for '||i);
        END LOOP;
        RETURN lCol;
    END ExampleMyCollection1;
    
    SELECT * FROM TABLE(ExampleMyCollection1);
    

    Variation – this time we use pipelining, so that the results are returned to the query as they are created. Note that despite being a function, there is no end RETURN for a PIPELINED function.

    CREATE OR REPLACE FUNCTION ExampleMyCollection2
    RETURN myCollection PIPELINED
    IS
    BEGIN
        FOR i IN 1..1000 LOOP
            PIPE ROW(myEntry(i,'An entry for '||i));
        END LOOP;
    END ExampleMyCollection2;
    
    SELECT * FROM TABLE(ExampleMyCollection2);
    

    To replace your temp table with purely in-memory data, you will need something to store your collection in – i.e. a package with state.

    CREATE OR REPLACE PACKAGE pMyCollection
    AS
       PROCEDURE AddEntry(entry IN myEntry);
    
       FUNCTION fCurrentCollection RETURN myCollection;
    
       PROCEDURE ClearEntries;
    
    END pMyCollection;
    
    CREATE OR REPLACE PACKAGE BODY pMyCollection
    AS
       /* Stateful variable to hold the collection */
       pCollection myCollection := myCollection();
    
       PROCEDURE AddEntry(entry IN myEntry)
       IS
       BEGIN
          pCollection.EXTEND;
          pCollection(pCollection.LAST) := entry;
       END;
    
       PROCEDURE ClearEntries 
       IS
       BEGIN
          pCollection.DELETE;
       END ClearEntries;
    
       FUNCTION fCurrentCollection
       RETURN myCollection
       IS
       BEGIN
          /* Return whole collection - we could use pipelining and parameters to return partial elements */
          RETURN pCollection;
       END fCurrentCollection;
    
    END pMyCollection;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.