In Oracle, the SELECT statement is used to get the data from the tables, views, etc. The following is the syntax of the SQL SELECT statement:
Oracle SELECT Statement Syntax
[ with_clause ] SELECT [ hint ] [ { { DISTINCT | UNIQUE } | ALL } ] select_list FROM { table_reference | join_clause | ( join_clause ) | inline_analytic_view } [ , { table_reference | join_clause | (join_clause) | inline_analytic_view} ] ... [ where_clause ] [ hierarchical_query_clause ] [ group_by_clause ] [ model_clause ]
Below is the simple version of the SELECT statement syntax:
SELECT COLUMN1, COLUMN2, COLUMN3 FROM TABLE1 WHERE COLUMN1 = 123 ORDER BY COLUMN1, COLUMN2;
SELECT Statement Examples
Suppose you want to fetch all columns and all rows of EMP table, then you would simply execute the following Oracle SELECT statement:
Example-1:
SELECT * FROM EMP;
And if you want to fetch only a few specific columns then your SQL query would be as follows:
Example-2:
SELECT EMPNO, ENAME, SAL, HIREDATE FROM EMP;
The following is an example to fetch the data from the EMP table for department number 10 only.
Example-3:
SELECT EMPNO, ENAME, SAL FROM EMP WHERE DEPTNO = 10;
To sort the result order by employee name:
Example-4:
SELECT EMPNO, ENAME, SAL, COMM FROM EMP WHERE DEPTNO = 10 ORDER BY ENAME;
Resource: Oracle SELECT Statement – Oracle Docs
Leave a comment