How to rename a column in a query in ORACLE

2019-09-15 18:48发布

问题:

Is this query right for changing the name of a column in the employees table:

select first_name, rename_column('first_name' to 'empName') from employees;

回答1:

there are two ways 1) give alias name to the column

 SELECT first_name AS emp_name 
 FROM employee;

2) change column name

   alter table employee
rename first_name  to emp_name ;


回答2:

To set an alias for a field use the following:

SELECT first_name AS "empName", hire_date AS "Tenure On December 31 2014"
FROM employees;


回答3:

If you are going to change the name just in your current result-set, you can do following:

select first_name AS emp_name from employees;

if you are going to change the name permanently, you have to work with ALTER TABLE:

ALTER TABLE employees CHANGE first_name emp_name VARCHAR2(255);


标签: sql oracle10g