Question

I have a problem with my Oracle SQL query. It requires naming a column "PRINT" to override a value that was selected by selecting ' * '.

'TRUE' AS "PRINT"

The column should override the oririnal content of the "PRINT" colum that is included in

select *

Unfortunately, "PRINT" is recognised as a keyword (either by Oracle or my DBMS) and so in the resulting output table there is the original "PRINT" column, which is still 'FALSE', and a new column named "PRINT_1" which is the selected constant 'TRUE'.

As you can see, I already used "as" and double quotes in order to try to escape the keyword but somehow it's not working as I thought it would. So how do I do that?

As requested the query:

SELECT H.*
, 'TRUE' as "PRINT"
FROM TABLE H
Était-ce utile?

La solution

The problem has nothing to do with print being a keyword (it isn't, by the way, though it is a SQL*Plus command). The problem is that adding an additional column to your projection (the set of columns in your SELECT list) will never "overwrite" another column in the projection even if you try to name them the same. If you want to force the value of PRINT to be 'TRUE', you'd need to explicitly list the columns that you want (other than PRINT) and then add your computed PRINT column.

In other words

SELECT h.col1, h.col2, h.col3, ... h.colN,
       'TRUE' as print
  FROM table_name h

where col1 - colN omits the PRINT column

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top