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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:39:00+00:00 2026-06-02T17:39:00+00:00

My situation: I have a table named Table1. It has lots of columns, one

  • 0

My situation:

  • I have a table named Table1. It has lots of columns, one of them is Column1. I don’t know the other columns, they may even change sometimes.
  • There is a strongly typed ref cursor type which returns Table1%rowtype, named cur_Table1.
  • I have a stored procedure named SP1 which has an out parameter of type cur_Table1. I’m calling this SP1 stored procedure from another database that only sees this stored procedure, but not the table or the type itself.

How do I select only Column1 from the returned cursor?

I know I can fetch into a record or as many variables as the cursor has columns, but I only know of one column’s existence so I can’t declare the complete record or correct number of variables.

  • 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-06-02T17:39:01+00:00Added an answer on June 2, 2026 at 5:39 pm

    You can do this with DBMS_SQL, but it ain’t pretty.

    Table and sample data (COLUMN1 has the numbers 1 – 10):

    create table table1(column1 number, column2 date, column3 varchar2(1000), column4 clob);
    
    insert into table1
    select level, sysdate, level, level from dual connect by level <= 10;
    commit;
    

    Package with a procedure that opens a ref cursor and selects everything:

    create or replace package test_pkg is
        type cur_Table1 is ref cursor return table1%rowtype;
        procedure sp1(p_cursor in out cur_table1);
    end;
    /
    
    create or replace package body test_pkg is
        procedure sp1(p_cursor in out cur_table1) is
        begin
            open p_cursor for select column1, column2, column3, column4 from table1;
        end;
    end;
    /
    

    PL/SQL block that reads COLUMN1 data from the ref cursor:

    --Basic steps are: call procedure, convert cursor, describe and find columns,
    --then fetch rows and retrieve column values.
    --
    --Each possible data type for COLUMN1 needs to be added here.
    --Currently only NUMBER is supported.
    declare
        v_cursor sys_refcursor;
        v_cursor_number number;
    
        v_columns number;
        v_desc_tab dbms_sql.desc_tab;
        v_position number;
        v_typecode number;
        v_number_value number;
    begin
        --Call procedure to open cursor
        test_pkg.sp1(v_cursor);
        --Convert cursor to DBMS_SQL cursor
        v_cursor_number := dbms_sql.to_cursor_number(rc => v_cursor);
        --Get information on the columns
        dbms_sql.describe_columns(v_cursor_number, v_columns, v_desc_tab);
    
        --Loop through all the columns, find COLUMN1 position and type
        for i in 1 .. v_desc_tab.count loop
            if v_desc_tab(i).col_name = 'COLUMN1' then
                v_position := i;
                v_typecode := v_desc_tab(i).col_type;
    
                --Pick COLUMN1 to be selected.
                if v_typecode = dbms_types.typecode_number then
                    dbms_sql.define_column(v_cursor_number, i, v_number_value);
                --...repeat for every possible type.
                end if;
            end if;
        end loop;
    
        --Fetch all the rows, then get the relevant column value and print it
        while dbms_sql.fetch_rows(v_cursor_number) > 0 loop
            if v_typecode = dbms_types.typecode_number then
                dbms_sql.column_value(v_cursor_number, v_position, v_number_value);
                dbms_output.put_line('Value: '||v_number_value);
            --...repeat for every possible type
            end if;
        end loop;   
    end;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation: I have one table that contains a list of drugs
Okay, here's the situation: We have a table of about 50 columns (created by
I have the following situation: An Conversations entity/table which has multiple Tags associated to
I have a situation where I have a table that has a soft foreign
I have a common database joining situation involving three tables. One table, A, is
Situation I have 5 Access DB files, each one has 10 tables, 40 queries
Situation: I have two tables, say 'master' and 'detail', where 'master' has two columns
I have a very typical situation. We have a table called Users which has
I have a table named Orders that has a column named OrderCode that stores
Consider the below situation I have a database table as below user_id user_rank ------------------

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.