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

The Archive Base Latest Questions

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

I have written 2 separate queries 1) SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME =

  • 0

I have written 2 separate queries

1)


SELECT COLUMN_NAME
  FROM ALL_TAB_COLUMNS
 WHERE TABLE_NAME =
       (SELECT DISTINCT UT.TABLE_NAME
          FROM USER_TABLES UT
         WHERE UT.TABLE_NAME = 'MY_TABLE')
   AND COLUMN_NAME NOT IN ('AVOID_COLUMN')

2)


    SELECT *
      FROM MY_TABLE MT
     WHERE MT.COL1 = '1'
   

The 1st query returns the names of all the columns except the one I want to avoid. The 2nd one returns data of all the columns from the table.
Is there some way to merge these queries so that only those column's data is selected from the 2nd query, which are returned from the 1st query?

Thanks in advance

  • 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-06T16:13:09+00:00Added an answer on June 6, 2026 at 4:13 pm

    You’ll have to use dynamic SQL for this (BTW, I got rid of the subselect for the USER_TABLES query – it’s unnecessary):

    var  cur refcursor
    /
    declare
      v_stmt varchar2(4000);
    begin
      v_stmt := 'SELECT ';  
      for cur in (
        SELECT COLUMN_NAME
        FROM ALL_TAB_COLUMNS
        WHERE TABLE_NAME =
           'MY_TABLE'
        AND COLUMN_NAME NOT IN ('AVOID_COLUMN')
      ) 
      loop
        v_stmt := v_stmt || cur.column_name || ',';
      end loop;
      -- get rid of trailing ','
      v_stmt := regexp_replace(v_stmt, ',$', '');
    
      v_stmt := v_stmt || ' from my_table MT WHERE MT.COL1 = ''1''';
      dbms_output.put_line(v_stmt);
      open :cur for v_stmt;
    end; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an app which fetches data from a server. I am not
I have written this code inside a servlet to delete certain records from three
I have written a function that extract the domain from hostname. e.g. www.domain.com ->
I have written a simple feedback application in django. It's not particulairly complex, basically
I have written an application (using Delphi 2009) that allows a user to select
I have written a Chat application using C#. The project is a separate Windows
I have written a gateway to get a result set from my database. How
I'm developing a python framework that would have addons written as separate packages. I.e.:
I have written a server and a client both as separate apps. They communicate
I have written an application that is able to write posts from the command

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.