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