First, select basic syntax:
SELECT *| {[DISTINCT] column|expression [alias],...} fromtable;
Select identifies which columns are selected.
From identifies the table from which to select.
1. Remove all columns from the table
SELECT * from EMP;
Connected to Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 Connected as c##[email protected]sql> Selec T * from EMP; EMPNO ename JOB MGR hiredate SAL COMM DEPTNO---------------------------------------------- ------------------7369 SMITH Clerk 7902 1980/12/17 800.00 7499 ALLEN salesman 769 8 1981/2/20 1600.00 300.00 7521 WARD salesman 7698 1981/2/22 1250.00 500.00-7566 JONES MANAGER 7839 1981/4/2 2975.00 7654 MARTIN salesman 7698 1981/9/28 1250.00 1400. 7698 BLAKE Manager 7839 1981/5/1 2850.00 7782 CLARK manager 7839 1981/6/9 2450.00 7788 SCOTT ANALYST 7566 1987/1/24 3000.00 7839 KING presi DENT 1981/11/17 5000.00 7844 TURNER salesman 7698 1981/9/8 1500.00 0.00 30 7 876 ADAMS Clerk 7788 1987/4/2 1100.00 7900 JAMES clerk 7698 1981/12/3 950.00 7902 FORD ANALYST 7566 1981/12/3 3000.00 7934 MILLER clerk 7782 1982/1/23 1300.00 1014 Rows selected
2. Remove specific columns from the table
SQL>SELECT from EMP; ename JOB-------------------SMITH clerkallen salesmanward Salesmanjones managermartin salesmanblake managerclark managerscott analystking Presidentturner salesmanadams clerkjames clerkford analystmiller clerk14 rows selected
Second, use arithmetic operators
1. Remove the employee's annual salary from the EMP table
Sql> SELECT Ename,sal*12,sal*12+comm from EMP; ename sal*12 sal*12+comm-------------------------------SMITH 9600 ALLEN 19200 19500WARD 15000 15500JONES 35700 MARTIN 15000 16400BLAKE 34200 CLARK 29400 SCOTT 36000 KING 60000 TURNER 18000 18000ADAMS 13200 JAMES 11400 FORD 36000 MILLER 15600 rows Selected
Third, alias of the column
Select column [As] "Alias" fromtable;
As keywords can omit the double quotation mark of the alias or double quotation marks can be omitted mainly to prevent the alias contains spaces or special symbols
Sql> SELECTEname as"Name", SAL Payroll fromEMP; name Salary---------- ---------SMITH800.00ALLEN1600.00WARD1250.00JONES2975.00MARTIN1250.00BLAKE2850.00CLARK2450.00SCOTT3000.00KING5000.00TURNER1500.00ADAMS1100.00JAMES950.00FORD3000.00MILLER1300.00 -Rows selected
Iv. Using Connectors | | Merge columns
Sql> SELECTEname|| ''s work is' ||JOB fromEMP; Ename||''s work is'||JOB-------------------------------Smith's job is Clerkallen's job is Salesmanward job is salesmanjones job is managermartin work is salesmanblake work is managerclark work is Managerscot The work of T is analystking work is presidentturner work is salesmanadams work is clerkjames work is clerkford work is analystmiller work is clerk -Rows selected
V. Removal of duplicate rows DISTINCT
SQL>SELECT from EMP; JOB--------- Clerksalesmansalesmanmanagersalesmanmanagermanageranalystpresidentsalesmanclerkclerkanalystclerk14 rows selectedsql>SELECTDISTINCT from EMP; JOB---------clerksalesmanpresidentmanageranalyst
Oracle Second, basic SELECT statement