在sql查询中,合理的使用别名有很多好处
一:使用别名的好处
1)简化SQL语句的书写,特别是多表关联查询且表名较长时
2)增强SQL语句的可读性,特别是当查询出来的列字段较为复杂时效果更为明显
二.别名使用的注意事项
1.可以使用as 也可以不使用
2.不能使用单引号
3.可以使用双引号或者不使用
4.但是当别名中有特殊字符的时候,必须使用双引号
5.当别名是关键字的时候,也需要用双引号,比如示例中的
CUSTOMER-ID
DATE
附一ocp考题
Examine the description of the transactions table:
Examine the description of the transactions table:
Name NULL? TYPE
TRANSACTION_ID NOT NULL VARCHAR2(6)
TRANSACTION_DATE DATE
AMOUNT NUMBER(10,2)
CUSTOMER_ID VARCHAR2(6)
Which two SQL statements execute successfully?
A. SELECT customer_id AS "CUSTOMER-ID", transaction_date AS DATE, amount+100 "DUES" from transactions;
B. SELECT customer_id AS 'CUSTOMER-ID',transaction_date AS DATE, amount+100 'DUES' from transactions;
C. SELECT customer_id CUSTID, transaction_date TRANS_DATE,amount+100 DUES FROM transactions;
D. SELECT customer_id AS "CUSTOMER-ID", transaction_date AS "DATE", amount+100 DUES FROM transactions;
E. SELECT customer id AS CUSTOMER-ID, transaction_date AS TRANS_DATE, amount+100 "DUES AMOUNT"
FROM transactions;