Oracle database: how to select all but return certain columns first?

好久不见. 提交于 2019-12-05 16:46:52

There is no nice and easy way to do this, other than specifying each column.

But if you don't mind the duplicates and you don't care about the column names, you could alias those columns:

Select 
  ColumnC as ColumnC1, 
  ColumnJ as ColumnJ1, 
  ColumnF as ColumnF1,
  t.* 
from 
  Table1 as t

Just for demonstration, I aliased Table1 as well. You may omit the as keyword, but I feel it makes it a little more readable.

Do note that while these extra columns are not at all difficult for Oracle to query, they do generate extra traffic. For testing, this solution is fine, but in production code, I would opt to only select the columns you need, and only select them once. It's only a little extra work. After all, how many columns do you have? :)

You can work around the problem, however, by aliasing the columns that you are specifically selecting. For example

SELECT columnC new_columnC, columnJ new_columnJ, columnF new_columnF, t.*
  FROM table1 t

to ensure that there are no identically named columns.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!