執行以下query
SELECT ENAME , SAL , COMM
FROM EMP;
ENAME | SAL | COMM |
---|---|---|
KING | 5000 | - |
BLAKE | 2850 | - |
CLARK | 2450 | - |
JONES | 2975 | - |
SCOTT | 3000 | - |
FORD | 3000 | - |
SMITH | 800 | - |
ALLEN | 1600 | 300 |
WARD | 1250 | 500 |
MARTIN | 1250 | 1400 |
但看ENAME , SAL , COMM 不夠直觀,
可以改成以下query:
SELECT ENAME EMPLOYEENAME, SAL SALARY, COMM COMMISSION
FROM EMP;
EMPLOYEENAME | SALARY | COMMISSION |
---|---|---|
KING | 5000 | - |
BLAKE | 2850 | - |
CLARK | 2450 | - |
JONES | 2975 | - |
SCOTT | 3000 | - |
FORD | 3000 | - |
SMITH | 800 | - |
ALLEN | 1600 | 300 |
WARD | 1250 | 500 |
MARTIN | 1250 | 1400 |
這樣看欄位名稱比較容易看懂
另外這樣子的寫法中間不允許空格
SELECT ENAME EMPLOYEE NAME, SAL SALARY, COMM COMMISSION
FROM EMP;
Oracle會直接報錯誤
如果想要讓欄位呈現中間是空格的話要修改成這樣:
SELECT ENAME "EMPLOYEE NAME", SAL SALARY, COMM COMMISSION
FROM EMP;
EMPLOYEE NAME | SALARY | COMMISSION |
---|---|---|
KING | 5000 | - |
BLAKE | 2850 | - |
CLARK | 2450 | - |
JONES | 2975 | - |
SCOTT | 3000 | - |
FORD | 3000 | - |
SMITH | 800 | - |
ALLEN | 1600 | 300 |
WARD | 1250 | 500 |
MARTIN | 1250 | 1400 |
這樣就看的到差異了
此外也可以使用AS
SELECT
ENAME AS "EMPLOYEE NAME",
SAL AS SALARY,
COMM COMMISSION
FROM EMP;
會得到一樣的結果
EMPLOYEE NAME | SALARY | COMMISSION |
---|
也可以加入字串
如以下query
SELECT 'hello my name is ' || ename as "concatenated value"
FROM EMP
WHERE job = 'MANAGER'
concatenated value |
---|
hello my name is BLAKE |
hello my name is CLARK |
hello my name is JONES |
修改一下query
SELECT 'Hello, I am ' || ename || ' , I make $' || sal || ' per month' as "employee income"
FROM EMP
employee income |
---|
Hello, I am KING , I make $5000 per month |
Hello, I am BLAKE , I make $2850 per month |
Hello, I am CLARK , I make $2450 per month |
Hello, I am JONES , I make $2975 per month |
Hello, I am SCOTT , I make $3000 per month |
Hello, I am FORD , I make $3000 per month |
Hello, I am SMITH , I make $800 per month |
Hello, I am ALLEN , I make $1600 per month |
Hello, I am WARD , I make $1250 per month |
Hello, I am MARTIN , I make $1250 per month |
0 Comments:
張貼留言