Home
Column aliases should be defined using AS
Description
The rule "Column aliases should be defined using AS" in PL/SQL code states that when creating a column alias, the keyword "AS" should be used. This is done to make the code easier to read and understand. For example, if you wanted to create an alias for a column called "FirstName" in a table called "Employees", you would write the following code:
SELECT FirstName AS "Employee Name" FROM Employees;
By using the keyword "AS", it is easier to distinguish between the original column name and the alias. This rule is important to follow when writing PL/SQL code, as it helps to make the code more readable and understandable.
Key Benefits
- Ease of Use: Defining column aliases using the AS rule makes it easier to read and understand SQL queries.
- Improved Performance: Using column aliases can improve query performance by reducing the amount of data that needs to be processed.
- Simplified Syntax: Using column aliases can simplify the syntax of SQL queries, making them easier to write and maintain.
Non-compliant Code Example
SELECT Id,
DECODE (statecode, 101, 'New York',
201, 'New Jersey',
301, 'Seattle',
401, 'San Francisco',
'Unknown')
"Service Center Location" --Non compliant code (Column aliases defined without using AS)
FROM cars
WHERE cars.Id < 1775
Compliant Code Example
SELECT Id,
DECODE (statecode, 101, 'New York',
201, 'New Jersey',
301, 'Seattle',
401, 'San Francisco',
'Unknown') As
"Service Center Location" --Compliant code(Column aliases defined using AS)
FROM cars
WHERE cars.Id < 1775