Example of How to Rename a column in PL/SQL
Example 1: Rename a column, Ename to Empname in EMP table in PL/SQL
Step 1: Create a table in PL/SQL. (Example: emp )
Step 2: Retrieve the table data before altering the column name in a table using the below syntax.
Select * from table_name;
Example:
Step 3: You can use the ALTER TABLE statement to altering the ENAME column to the EMPNAME by using the below syntax.
ALTER TABLE table_name
RENAME COLUMN old_column_name TO new_column_name;
Example:
Step 4: After altering, we query the emp table again to verifying the column name has been changed or not. The output will show the altered column ENAME to EMPNAME.
Output:
Example 2: Rename a column, Sal to Salary in the EMP table in PL/SQL
Step 1: Create a table in PL/SQL. (Example: emp)
Step 2: Retrieve the table data before altering the column name in a table using the below syntax.
Select * from table_name;
Example:
Step 3: You can use the ALTER TABLE statement to rename the Sal column to the Salary by using the below syntax.
ALTER TABLE table_name
RENAME COLUMN old_column_name TO new_column_name;
Example:
Step 4: After altering, we query the emp table again to verifying the column name has been changed or not. The output will show the altered column SAL to SALARY.
Output:
How to Rename a Column in PL/SQL?
In PL/SQL, renaming the column name plays a crucial role in the database management. It is performed the enhance clarity, maintain consistency, or accommodate evolving the requirements of the data.
Database administrators can ensure the data integrity and process of streamlining data manipulation by altering the column names. PL/SQL can provide the direct syntax for executing the renaming of the column operations within the Oracle database.