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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:39:07+00:00 2026-06-06T11:39:07+00:00

W.r.t code below I can not declare the type of fetch-into-variable as the underlying

  • 0

W.r.t code below I can not declare the type of fetch-into-variable as the underlying table’s %ROWTYPE because the SYS_REFCURSOR is on a select that joins two tables and also selects a few functions called on the attributes of the underlying two tables; i.e I can’t declare as L_RECORD T%ROWTYPE

---
DECLARE
  P_RS SYS_REFCURSOR;
  L_RECORD P_RS%ROWTYPE;
BEGIN
  CAPITALEXTRACT(
    P_RS => P_RS
  );
    OPEN P_RS;
    LOOP
      BEGIN
        FETCH P_RS INTO L_RECORD;
        EXIT WHEN P_RS%NOTFOUND;
        ...
      EXCEPTION
        WHEN OTHERS THEN
        ...
      END;
    END LOOP;
    CLOSE P_RS;
END;
--------
CREATE or REPLACE PROCEDURE CAPITALEXTRACT
(
    p_rs OUT SYS_REFCURSOR
) AS
BEGIN
  OPEN p_rs for 
     select t.*,tminusone.*, f(t.cash), g(t.cash) FROM T t, TMINUSONE tminusone
    where t.ticket=tminusone.ticket;
END CAPITALEXTRACT;

Of course I don’t want to define a static table R with columns as returned in the SYS_REFCURSOR and then declare as L_RECORD R%ROWTYPE.

And hence the question:
how to declare %ROWTYPE of a variable that is a weakly typed SYS_REFCURSOR ?

  • 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-06T11:39:10+00:00Added an answer on June 6, 2026 at 11:39 am

    The short answer is, you can’t. You’d need to define a variable for each column that wil be returned.

    DECLARE
        P_RS SYS_REFCURSOR;
        L_T_COL1 T.COL1%TYPE;
        L_T_COL1 T.COL2%TYPE;
        ...
    

    And then fetch into the list of columns:

    FETCH P_RS INTO L_T_COL1, L_T_COL2, ... ;
    

    This is painful but manageable as long as you know what you’re expecting in the ref cursor. Using T.* in your procedure makes this fragile though, as adding a column to the table would break the code that thinks it knows what columns there are and what order they’re in. (You can also break it between environments if the tables aren’t built consistently – I’ve seen places where column ordering is different in different environments). You’ll probably want to make sure you’re only selecting the columns you really care about anyway, to avoid having to define variables for things you’ll never read.

    From 11g you can use the DBMS_SQL package to convert your sys_refcursor into a DBMS_SQL cursor, and you can interrogate that to determine the columns. Just as an example of what you can do, this will print out the value of every column in every row, with the column name:

    DECLARE
        P_RS SYS_REFCURSOR;
        L_COLS NUMBER;
        L_DESC DBMS_SQL.DESC_TAB;
        L_CURS INTEGER;
        L_VARCHAR VARCHAR2(4000);
    BEGIN
        CAPITALEXTRACT(P_RS => P_RS);
        L_CURS := DBMS_SQL.TO_CURSOR_NUMBER(P_RS);
        DBMS_SQL.DESCRIBE_COLUMNS(C => L_CURS, COL_CNT => L_COLS,
            DESC_T => L_DESC);
    
        FOR i IN 1..L_COLS LOOP
            DBMS_SQL.DEFINE_COLUMN(L_CURS, i, L_VARCHAR, 4000);
        END LOOP;
    
        WHILE DBMS_SQL.FETCH_ROWS(L_CURS) > 0 LOOP
            FOR i IN 1..L_COLS LOOP
                DBMS_SQL.COLUMN_VALUE(L_CURS, i, L_VARCHAR);
                DBMS_OUTPUT.PUT_LINE('Row ' || DBMS_SQL.LAST_ROW_COUNT
                    || ': ' || l_desc(i).col_name
                    || ' = ' || L_VARCHAR);
            END LOOP;
        END LOOP;
    
        DBMS_SQL.CLOSE_CURSOR(L_CURS);
    END;
    /
    

    That’s not of much practical use, and for brevity I’m treating every value as a string since I just want to print it anyway. Look at the docs and search for examples for more practical applications.

    If you only want a few columns from your ref cursor you could, I suppose, loop around l_desc and record the position where column_name is whatever you’re interested in, as a numeric variable; you could then refer to the column by that variable later where you would normally use the name in a cursor loop. Depends what you’re doing with the data.

    But unless you’re expecting to not know the column order you’re getting back, which is unlikely since you seem to control the procedure – and assuming you get rid of the .*s – you’re probably much better off reducing the returned columns to the minimum you need and just declaring them all individually.

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

Sidebar

Related Questions

I have been trying to access the below code DECLARE N_DEPTNO DEPT.DEPTNO %TYPE :=&DEPT_NUM;
It is a compiler error or runtime error? The code below can be compiled!
The simple code block below can be served up in a static HTML page
In past, I am using Listview and using below code can show a particular
I can't get the code below to compile (see errors). Advice on correction would
The code below working for only first div. I can't display other divs when
How can this code compile? The code below in the operator int CAN access
Below I have a jquery code which includes a textbox where the user can
See the code below. The drive() is in the scope , I can drive
The vb6 code I am using can inject an application into a running process.

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.