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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:12:58+00:00 2026-05-25T18:12:58+00:00

I’m emulating the DESCRIBE tablename available in Sqlplus to make similiar functionality available via

  • 0

I’m emulating the DESCRIBE tablename available in Sqlplus to make similiar functionality available via regular sql.

I have the objects/function listed below, and it works – except for the order_param clause. It’s basically ignored. I can call the function via:

select * from table(describe('my_table',1));

or

select * from table(describe('my_table',2));

and it results in the same ordering.

If I replace order by order_param with either order by 1 or order by 2 in the sql clause in the function, it works as expected.

There must be a better way to get this to work other than to use dynamic sql (or have the function actually choose between 2 sql clauses).

CREATE OR REPLACE TYPE table_description as object (
  column_name varchar2(30),
  column_id   number, 
  data_type   varchar2(30),
  nullable    varchar2(1)
);

CREATE OR REPLACE TYPE table_description_type as table of table_description;

CREATE OR REPLACE FUNCTION describe (tname IN VARCHAR2, order_param in NUMBER default 2) RETURN table_description_type AS
-- function to describe a table
-- eg. use via select * from table(describe('table_name'));

  v_ret table_description_type;

BEGIN

 select cast(multiset(
    select column_name, data_type || data_suff "Data Type", nullable from (
      select column_name, column_id, data_type, 
      case when data_type = 'DATE' then '' else '(' ||  
        case when data_type in ('CHAR','VARCHAR2','NCHAR','NVARCHAR') 
        then to_char(char_length) else data_precision || ', ' || data_scale end || ')'
      end data_suff, 
      nullable, data_default, num_nulls, last_analyzed, avg_col_len 
      from all_tab_columns where table_name = upper(tname)
      order by order_param
    )
 ) as table_description_type) into v_ret from dual;

 return v_ret;

END;
/
  • 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-25T18:12:59+00:00Added an answer on May 25, 2026 at 6:12 pm

    You can’t do this the way you’re attempting to. In order for the order clause to interpret a numeric value as a column reference, the number has to be there when the query is parsed. Since you’re binding the variable in, it will always interpret your parameter as a value, not a column reference. To fix this, you’ll want to change the order by clause logically to select a column based on the value:

    order by case order_param 
             when 1 then column_name 
             else data_type || data_suff
             end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT

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.