1

How can I sort SQL results by the titles of the columns ?
Yes, the horizontal way and without entering every single column name manually.

Id, Name, Forename, Department -> Department, Forename, Id, Name

Or can PL/SQL return groups of values ? Like:

select GetAllColumnsSortedByName(1) from table_name

(I can imagine this is a strange question, but it would help me, I have tons of columns in every table, actually, sorry, but how about the PL/SQL aspect ?)

Community
  • 1
  • 1
Bitterblue
  • 13,162
  • 17
  • 86
  • 124
  • 1
    Form the `select` statement accordingly, like `select department, forename, id, name from TABLE....` or create a view with columns in desired order and query the view. – AllTooSir Jul 25 '14 at 06:30
  • @TheNewIdiot I have tons of columns and entering every column name by hand is painful because I also have to look them all up. – Bitterblue Jul 25 '14 at 06:34
  • What RDBMS are you using? – keltar Jul 25 '14 at 06:34
  • 1
    On the sql side you can either specify the order of the columns in select statement (manually) or define your table columns in the desired order (which is not the best IDea). If you use your data in a programming language there should definitely be a way to do that automatically based on some rules (column name or column name length, etc) – B0Andrew Jul 25 '14 at 06:34

1 Answers1

2
  1. You can construct select query manually.

In Oracle you can obtain columns in alphabetical order like that:

select T.COLUMN_NAME 
  from all_tab_columns t 
 where T.TABLE_NAME = ? and T.OWNER= ? order by 1
  1. I think MULTISET operator is what you need. It relates to collections, but I doubt it can be done in 8i. Anyway, mb this link will help Oracle Doc
Slava Lenskyy
  • 426
  • 2
  • 10