Using Column Aliases


As you ve seen, when you select a column from a table, Oracle uses the uppercase version of the column name as the header for the column. For example, when you select the price column, the header in the resulting output is PRICE . When you use an expression, Oracle strips out the spaces, and uses the expression as the header. You aren t limited to using the header generated by Oracle: you can provide your own using an alias . In the following example, the expression price * 2 is given the alias DOUBLE_PRICE :

  SELECT price * 2 DOUBLE_PRICE   FROM products;  DOUBLE_PRICE ------------  39.9  60  51.98  27.9  99.98  29.9  26.98  25.98  21.98  31.98  29.98  26.98 

If you want to use spaces and preserve the case of your alias text, you must place the text within double quotation marks ():

  SELECT price * 2 "Double Price"   FROM products;  Double Price ------------  39.9 

You can also use the optional AS keyword before the alias, as shown in the following example:

  SELECT 10 * (12 / 3 - 1) AS "Computation"   FROM dual;  Computation -----------  30 



Oracle Database 10g SQL
Oracle Database 10g SQL (Osborne ORACLE Press Series)
ISBN: 0072229810
EAN: 2147483647
Year: 2004
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net