Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change column name in Oracle in SELECT statement

In MSSQL I can select a column and change the column header by doing:

SELECT mycolumn as 'MyNewColumnName' from MyTable 

This doesn't work in Oracle. How do I perform the same thing in Oracle?

like image 822
CathalMF Avatar asked Jul 30 '13 10:07

CathalMF


People also ask

How do I rename a column in SQL query?

To change a column name, enter the following statement in your MySQL shell: ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name; Replace table_name , old_column_name , and new_column_name with your table and column names.

How do I change column headings in Oracle?

To change a column heading to two or more words, enclose the new heading in single or double quotation marks when you enter the COLUMN command. To display a column heading on more than one line, use a vertical bar (|) where you want to begin a new line.

How do I rename a column in Oracle 12c?

ALTER TABLE table_name RENAME TO new_table_name; Columns can be also be given new name with the use of ALTER TABLE. QUERY: Change the name of column NAME to FIRST_NAME in table Student.

Can we rename multiple columns in Oracle?

Unfortunately, as rp0428 already mentioned, there is no way to rename more than one column in a single ALTER statement.


1 Answers

  1. Remove single quotation marks

    SELECT mycolumn as MyNewColumnName    from MyTable 
  2. Enclose alias in double quotation marks

    SELECT mycolumn as "MyNewColumnName"    from MyTable 
like image 73
Nick Krasnov Avatar answered Sep 28 '22 08:09

Nick Krasnov