[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1754
  • Last Modified:

How to exclude one column from select statement?

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
jl66
Asked:
jl66
  • 4
  • 3
  • 3
  • +2
5 Solutions
 
slightwv (䄆 Netminder) Commented:
In sqlplus it's pretty easy:

column col100 noprint

Where are you running the query?
0
 
VBClassicGuyCommented:
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
 
jl66Author Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jl66Author Commented:
=>Is there any way to deal with it?  It means that "Don't list everything col1,..col99 in select part".
0
 
slightwv (䄆 Netminder) Commented:
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
 
VBClassicGuyCommented:
If you create the view I mentioned, you can use:

CREATE TABLE t2 SELECT * FROM vwT1

(assuming you name your view vwT1)
0
 
VBClassicGuyCommented:
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
 
jl66Author Commented:
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
 
Aaron ShiloCommented:
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
 
Aaron ShiloCommented:
^

just a fix for the command

ALTER TABLE table_name SET UNUSED (column_name);
0
 
Aaron ShiloCommented:
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
 
maheshchariCommented:
select * from tablename where rownum>=1 and rownum<=99;
0
 
slightwv (䄆 Netminder) Commented:
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
 
jl66Author Commented:
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now