I would like know, how can we re-order the columns in ascending or descending order, while retrieving the data.
Suppose the table contains the data as below with no primary key/unique key constraints:
Col1 Col2 Col3 Col4 ---- ---- ---- ---- B D C A C Y M T 3 5 2 4 5 2 10 7
I want the output in below format: Each row data should be in ascending order, Whether it's Varchar or Numeric. That I guess could be done by taking ascii value of the value set? Is it achievable, if not why?
ColA ColB ColC ColD ---- ---- ---- ---- A B C D C M T Y 2 3 4 5 2 5 7 10
Please try to provide a solution, which can be generic for any number of columns.
Every row should be re-arranged in ascending order, while we are retrieving the data. I am trying to do something like order by, but not based on column, but row. Is it achievable. It was an interview question for me by Amazon. I tried pivot and unpivot, but haven't been able to achieve this.
- All column datatypes are
- No specific order/pattern for the values.
- The column names does not need to be same, while retrieving the data. Column names can be aliased or can be taken as per your preference. The data retrieved should be in the ascending order by row.
- No primary key/unique key constraints.
I would like to understand, if such a solution is achievable, whether inefficient or not. Looking for answers using Oracle 11g or higher.