Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you SELECT everything, but 1 or 2 fields, without writer's cramp?

Tags:

oracle

plsql

Is it possible, in PLSQL, to select all of the fields in a table except for 1 or 2, without having to specify the fields you want?

Example, the employee table has the fields:

  • id
  • firstname
  • lastname
  • hobbies

Is it still possible to write a query similar to

select * from employee 

while leaving the field hobbies without with having to write something like this?

select id, firstname, lastname from employee 
like image 635
Steve Avatar asked Feb 03 '12 17:02

Steve


People also ask

How do I select all rows except one in SQL?

The SQL EXCEPT operator is used to return all rows in the first SELECT statement that are not returned by the second SELECT statement. Each SELECT statement will define a dataset. The EXCEPT operator will retrieve all records from the first dataset and then remove from the results all records from the second dataset.


2 Answers

No - you either get all fields (*) OR specify the fields you want.

like image 179
Yahia Avatar answered Oct 11 '22 02:10

Yahia


If you want to avoid the writer's cramp, you can use SQL Developer and have it generate the column list for you:

select column_name||',' from all_tab_columns where table_name = 'YourTableName' 

And then just take out the one or two columns that you don't want.

You can also use

SELECT listagg(column_name, ',') within group (order by column_name) columns FROM all_tab_columns WHERE table_name = 'TABLE_NAME' GROUP BY table_name; 
like image 34
Michael Fredrickson Avatar answered Oct 11 '22 03:10

Michael Fredrickson