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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:16:59+00:00 2026-05-23T12:16:59+00:00

In PL/SQL, I can use a trick like this one here to find out

  • 0

In PL/SQL, I can use a trick like this one here to find out name/value pairs for every column in a row from a REF CURSOR:

TO_CHAR of an Oracle PL/SQL TABLE type

That’s an awesome trick. But it doesn’t work when the REF CURSOR is empty, such as this one here (that’s just an example. The real cursor doesn’t select from DUAL):

OPEN cursor FOR SELECT 1 FROM DUAL WHERE 1 = 0;

Does an empty REF CURSOR even have column name/type information?

  • 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-23T12:16:59+00:00Added an answer on May 23, 2026 at 12:16 pm

    Yes, I’ve tried that solution without rows, and you’re right.
    From my limited point of view, I think here we need two different methods to retrieve columns’ names and values.

    1) Dbms_sql package to retrieve the columns’ names.

    2) The tbone method to retrieve the data.


    Procedure

    create or replace procedure demo(sqlText in varchar2) is
        refCur sys_refcursor;
        curId  integer;
        cnt    number;
        ret    dbms_sql.desc_tab;
        recTab dbms_sql.desc_tab;
        FORMAT_STRING constant pls_integer := 20;
    
        procedure printDescTab(desctab in sys.dbms_sql.desc_tab) is
        begin
            -- do what you want with the columns
            for i in 1 .. desctab.count
            loop
                dbms_output.put(lpad(desctab(i).col_name, FORMAT_STRING));
            end loop;
            dbms_output.new_line;
        end printDescTab;
    
        procedure PrintCur(cv in sys_refcursor) is
        begin
            for c in ( --select t2.COLUMN_VALUE.getrootelement() name,
                      select EXTRACTVALUE(t2.COLUMN_VALUE, 'node()') value
                      from   table(XMLSEQUENCE(cv)) t
                             ,table(XMLSEQUENCE(EXTRACT(COLUMN_VALUE, '/ROW/node()'))) t2)
            loop
                DBMS_OUTPUT.put(lpad(c.VALUE, FORMAT_STRING));
            end loop;
            dbms_output.new_line;
            dbms_output.new_line;
        end;
    
    begin
        dbms_output.put_line('dynamic sql: ' || sqlText);
        curId := dbms_sql.open_cursor();
        --  checks for sql injection to do...
        dbms_sql.parse(curId, sqlText, dbms_sql.native);
        dbms_sql.describe_columns(curId, cnt, recTab);
        printDescTab(recTab);
        dbms_sql.close_cursor(curId);
    
        open refCur for sqlText;
        PrintCur(refCur);
        close refCur;
    exception
        when others then
            if dbms_sql.is_open(curId) then
               dbms_sql.close_cursor(curId);
            end if;
            if refCur%isopen then
                close RefCur;
            end if;
            dbms_output.put_line(sqlcode || ' - ' || sqlerrm);
    end demo;
    

    Test

    declare
        sqlText varchar2(2000);
    begin
        sqlText := 'select 1 as one, 2 as two  from  dual where 1=0';
        demo(sqlText);
        sqlText   := 'select name, type || chr(13) type' -- chr(13) specific ASCII Carriage return
                    ||' from   user_plsql_object_settings'
                    ||' where name not like ''%$%'' and  rownum <= 10';      
        demo(sqlText);   
        sqlText := 'select 1 as one, 2 as two  from  dual ';                  
        demo(sqlText);
    
    exception
        when others then
            dbms_output.put_line(sqlcode || ' - ' || sqlerrm);
    end;
    

    Result

    dynamic sql: select 1 as one, 2 as two  from  dual where 1=0
                     ONE                 TWO
    
    
    dynamic sql: select name, type || chr(13) type from   user_plsql_object_settings where name not like '%$%' and  rownum <= 10
                    NAME                TYPE
         ADD_JOB_HISTORY          PROCEDURE
        AFT_INS_TEST_TRG            TRIGGER
        BEF_DEL_TEST_TRG            TRIGGER
        BEF_INS_TEST_TRG            TRIGGER
                BETWNSTR           FUNCTION
                    BOOL           FUNCTION
        CACHED_FIBONACCI           FUNCTION
                   DEBUG            PACKAGE
                   DEBUG       PACKAGE BODY
              DEBUG_TEST          PROCEDURE
    
    
    dynamic sql: select 1 as one, 2 as two  from  dual 
                     ONE                 TWO
                       1                   2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQL Server you can use the IsNull() function to check if a value
You can use the Filter property of a BindingSource to do SQL like filtering.
In SQL Server 2017, you can use this syntax, but not in earlier versions:
In SQL you can use SELECT * FROM INFORMATION_SCHEMA.TABLES etc to get information about
In SQL server you can use the DATENAME function to get the day of
In SQL Server you can use an XML datatype and map it to relational
I can use the sql server management studio to open a sqlserver 2000 database,
I am wondering if you can use Linq to SQL using a .mdf file
i am using sql server 2000 can i use full text search on the
Anyone have a PL-SQL statement that i can use to generate database & tables

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.