Site icon TestingDocs.com

Oracle SQL SELECT Statement

Overview

We can use Oracle SQL SELECT Statement to retrieve data from one or database tables, views, etc. There are many options available for the SELECT  command.

Example – All rows and columns

To retrieve all rows and columns of a table:

SELECT * FROM table_name;

For example, to get all the rows and columns of dept table.

SELECT * FROM dept;

The * represents all columns in the table in the SQL query. In the next example, we will see how to retrieve only some columns in the table.

Example – Select some columns

In this example, we will only retrieve some columns of the table. For example, we are not interested in the department locations. We are only interested in the department number and the department name of the dept table. We can specify the column names comma separated in the SELECT command.

SQL> SELECT deptno, dname FROM dept;

Notice that only deptno and dname columns are displayed in the query result.

Example – WHERE clause

We can use the WHERE clause in the SELECT statement to filter rows or retrieve only some rows from the table.

The following query will only retrieves rows that satisfies the condition deptno > 2000. The table has four rows, but only two rows have deptno > 2000.

SQL> SELECT * FROM dept WHERE deptno > 2000;

DEPTNO DNAME LOC
———- ——————– ——————–
3000 SALES CHICAGO
4000 OPERATIONS BOSTON

Oracle Database Tutorials on this website:

https://www.testingdocs.com/oracle-database-tutorials-for-beginners/

More information about Oracle Database:

https://www.oracle.com/database/

Exit mobile version