Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL select all fields except [duplicate]

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 515
Steve Avatar asked Jun 25 '26 04:06

Steve


2 Answers

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

like image 189
Yahia Avatar answered Jun 27 '26 18:06

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 40
Michael Fredrickson Avatar answered Jun 27 '26 19:06

Michael Fredrickson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!