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
If you want to avoid the writer's cramp, you can use SQL Developer and have it generate the column list for you:
And then just take out the one or two columns that you don't want.
You can also use
No - you either get all fields (
*
) OR specify the fields you want.What the OP was looking for was something like:
The best thing to do to avoid a lot of typing (and get all the column names correct) is to open the table description and cut and paste all the column names and delete the ones you don't want, comma separate the remaining ones and put them on a singe line or two.
It is easy, fast, accurate and you won't confuse the next person who has to work on your code.
query_generator
is a PL/SQL function that returns a select string for a table (1st parameter) but excluding some columns (2nd parameter).stringlist
andputil.join
are from PL/SQL Commons.stringlist
is a simple list of strings:create type StringList as table of varchar2(32767);
andputil.join
is just a normal join function.Usage example:
here is the solutions... i need all columns except password
(select column_name ||',' from user_tab_columns where table_name ='USERS' and column_name <>'PASSWORD')
Here is another option to get a list of the fields that allows you to specify the delimiter: