Solved

How to exclude one column from select statement?

Posted on 2011-02-18
14
1,566 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 260 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 

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 260 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 100 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 140 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 140 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

717 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