How to rename a column in a query in ORACLE

我怕爱的太早我们不能终老 提交于 2019-12-11 14:43:14

问题


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);


来源:https://stackoverflow.com/questions/25732615/how-to-rename-a-column-in-a-query-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!