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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:56:36+00:00 2026-06-10T11:56:36+00:00

I want an approach/code snippet to extract column names and the corresponding table name

  • 0

I want an approach/code snippet to extract column names and the corresponding table name from an oracle query. The queries and consequently the columns and table names change at run time and some of the column names usually are calculated meaning they are wrapped in a function and aliased. I tried different string tokenizing techniques using regexp to separate this out as per the expeted output, but so far, no luck !
Eg:

select mandate_name, investment_sub_team_name,
fn_sum(REG_INV_CMP_AUM) REG_INV_CMP_AUM, 
fn_sum(NON_REG_INV_CMP_AUM) NON_REG_INV_CMP_AUM
from DM_SAI_VALUATIONS_STEP3
where position_interval_type = 'E'
and position_type = 'T'
group by mandate_name, investment_sub_team_name;

I want the output for the columns as:

mandate_name
investment_sub_team_name
fn_sum(REG_INV_CMP_AUM)
fn_sum(NON_REG_INV_CMP_AUM)

Note above: I want the columns with the function and not the alias

I want the output for the table name as: DM_SAI_VALUATIONS_STEP3 against all the columns that I listed above

I cannot edit the queries as they are part of an xml output. So, i cannot change the alias. The second point is to just extract the table name from the query. Please consider the fact that nothing can be hard coded like position of the string token etc as the queries containing the columns and the table would be different. I am looking for a generic approach to tokenize them. So, against the column output that I expect, i just need the table name as well..Its always going to only one table in the from clause, so extracting that would not be an issue.

Expected output:

Column Name                          Table Name
-----------                          ----------
mandate_name                         DM_SAI_VALUATIONS_STEP3
investment_sub_team_name             DM_SAI_VALUATIONS_STEP3
fn_sum(REG_INV_CMP_AUM)              DM_SAI_VALUATIONS_STEP3
fn_sum(NON_REG_INV_CMP_AUM)          DM_SAI_VALUATIONS_STEP3

Any help pr pointers would be much appreciated.

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

    If you know that the structure of your query strings will not change much, you can do something like this:

    set serveroutput on
    set termout on
    clear
    declare
      v_str varchar2(500) := 'select mandate_name, investment_sub_team_name,
    fn_sum(REG_INV_CMP_AUM) REG_INV_CMP_AUM, 
    fn_sum(NON_REG_INV_CMP_AUM) NON_REG_INV_CMP_AUM
    from DM_SAI_VALUATIONS_STEP3
    where position_interval_type = ''E''
    and position_type = ''T''
    group by mandate_name, investment_sub_team_name;';
      v_tmp varchar2(500);
      v_cols varchar2(500);
      v_table varchar2(500);
    begin
      v_tmp := replace( v_str, 'select ','');
      v_tmp := substr( v_tmp, 1, instr(v_tmp, 'where')-1);
    
      dbms_output.put_line('original query: '||v_str);  
    
      v_cols := substr (v_tmp, 1, instr(v_tmp, 'from')-1);
      dbms_output.put_line('column names: '||v_cols);
    
    
      v_table := substr(v_tmp, instr(v_tmp, 'from ')+4, 500);
      dbms_output.put_line('table name: '||v_table);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use resource bundle in login page using tag <spring:message code=login.name />
With this approach. I have a line plot graph. I want to plot 'two'
I'm after some guidance on how to approach coding a problem, I don't want
First of all I don't know if this is the right approach. I want
Want to run javascript function from parent window in child window Example I have
Want to open firefox from terminal at linux with firebug enabled // Terminal $
Want the function to sort the table by HP but if duplicate HPs then
I want to learn about Code First development in EF4 and after googling about
My app allows to upload csv file with some data. I want to extract
I'm using EF4 CTP5 code first approach but am having trouble getting it to

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.