Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle how to add generated column to a select *

Tags:

sql

oracle

In Oracle, how do I add a generated column to my result-set? In other words, how do I do the following in Oracle:

SELECT (col4 * (col1+col2+col3) + 13) as gen1, *
  FROM table1
  WHERE col3 > 123
    AND col4 = 5
  ORDER BY col1, col2

This query works in MySQL and MSSQL. But for some reason, I can't get it to work with Oracle! Please help! Thanks

like image 457
Mohamed Nuur Avatar asked Dec 16 '22 11:12

Mohamed Nuur


1 Answers

It should work if you qualify the * with the table name (or the alias name if you use one)

SELECT (col4 * (col1+col2+col3) + 13) as gen1, table1.*
  FROM table1
  WHERE col3 > 123
    AND col4 = 5
  ORDER BY col1, col2
like image 110
Justin Cave Avatar answered Dec 19 '22 06:12

Justin Cave