?
Solved

How to exclude one column from select statement?

Posted on 2011-02-18
14
Medium Priority
?
1,622 Views
Last Modified: 2012-05-11
Have a table with 100 columns and want to show 99 columns. Easy way is
select col1, col2, ...col99
from t1;
That will be multiple pages only for select part. but if doing the following
select * from t1;
That will show everything.
Gurus, Is there any easy way to solve my issue?


0
Comment
Question by:jl66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +2
14 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1040 total points
ID: 34927472
In sqlplus it's pretty easy:

column col100 noprint

Where are you running the query?
0
 
LVL 14

Expert Comment

by:VBClassicGuy
ID: 34929314
You could either:

1. Select all fields and just ignore the unwanted one in code.

2. Build a view which selects all columns except the unwanted one, and then select from the view rather than the table.
0
 

Author Comment

by:jl66
ID: 34929340
Thank you so much. The point should be awarded to you now. However, the purpose for it is as follows:

create table t2 as
select * from t1;

in t2 it only needs col1....col99. Is there any way to deal with it?
If you need a new ticket, I can open a new one. Sorry for that.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jl66
ID: 34929363
=>Is there any way to deal with it?  It means that "Don't list everything col1,..col99 in select part".
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1040 total points
ID: 34929380
Selecting in code and create table as select are really two different things.

I don't know of an easy way to do this.

You never did respond to my question:
Where are you running the query?

You can likely 'build' the query dynamically but we need to know your exact requirements.
0
 
LVL 14

Expert Comment

by:VBClassicGuy
ID: 34929435
If you create the view I mentioned, you can use:

CREATE TABLE t2 SELECT * FROM vwT1

(assuming you name your view vwT1)
0
 
LVL 14

Assisted Solution

by:VBClassicGuy
VBClassicGuy earned 400 total points
ID: 34929464
Or, go ahead and use your statement of:

CREATE TABLE t2 AS SELECT * FROM t1

then follow it with this statement:

ALTER TABLE t2 DROP COLUMN MyUndesiredField
0
 

Author Comment

by:jl66
ID: 34931265
If the table has over 100 Millions rows, adding one column and dropping it would be costly. Is there any better way to deal with it
0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34931830
hi

no need to drop the column.
use the UNUSED command

alter table alter column set unused.

this is a Datadict command and works immediatly no overhead.
0
 
LVL 15

Assisted Solution

by:Aaron Shilo
Aaron Shilo earned 560 total points
ID: 34931834
^

just a fix for the command

ALTER TABLE table_name SET UNUSED (column_name);
0
 
LVL 15

Assisted Solution

by:Aaron Shilo
Aaron Shilo earned 560 total points
ID: 34931836
hi

there is another way.

you could generate a dynamic query using  DBA_TAB_COLUMNS
and select the first 99 columns for the dynamic query.
0
 
LVL 1

Expert Comment

by:maheshchari
ID: 34933789
select * from tablename where rownum>=1 and rownum<=99;
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34934337
What are you wanting to do?

Are you wanting to select columns or remove the column permanently from the table?

ashilo,

I already mentioned dynamic sql but thanks for providing the view.
0
 

Author Closing Comment

by:jl66
ID: 34934876
Thank for everyone. Dynamically build the query may be the practical way to work out the issue. Special thanks to slightwv and ashilo. It does not seem matter. I can use dba_tab_columns or user_..., depending on the user privilege logged in to form the query.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question