PL/SQL Select

Oracle PL/SQL SELECT is a statement that queries a table or multiple tables. Oracle PL/SQL Select can be used to query any type of data from a table, including text, numbers, and dates. The syntax is:

Syntax:

select * from table;
select column_name1, column_name2 from table_name;
select column_name1, column_name2 from table_name where condition;

Oracle PL/SQL also supports wildcards, which can be used to select all rows from a table. To select all rows from a table, you would use the following query:

SELECT * FROM table_name;

Oracle PL/SQL Select can also be used to select specific columns from a table.
For example, to select the first and last name of all employees from the employee table, you would use the following query:

SELECT first_name, last_name 
FROM employees; 

Oracle PL/SQL also supports operators, which can be used to compare values in a column.
For example, the following query would select all employees whose last name is Smith:

SELECT * 
FROM employee 
WHERE last_name = 'Smith';

Oracle PL/SQL also supports the use of ORDER BY to sort the results of a query.
For example, the following query would select all employees whose last name is Smith and who have a salary greater than $5,000 and would order the results by last name:

SELECT * 
FROM employee 
WHERE last_name = 'Smith' 
AND salary > 5000 
ORDER BY last_name; 

Oracle PL/SQL also supports the use of GROUP BY to group the results of a query.
For example, the following query would select all employees whose last name is Smith and who have a salary greater than $5,000 and would group the results by last name:

SELECT * 
FROM employee 
WHERE last_name = 'Smith' 
AND salary > 5000 
GROUP BY last_name;

Oracle PL/SQL also supports the use of HAVING to filter the results of a query.
For example, the following query would select all employees whose last name is Smith and who have a salary greater than $5,000 and would only return results for employees whose last name is Smith:

SELECT * 
FROM employee 
WHERE last_name = 'Smith' 
AND salary > 5000 
HAVING last_name = 'Smith'; 

Oracle PL/SQL also supports the use of DISTINCT to select only unique values from a table. For example, the following query would select all employees who have a salary greater than $5,000 and would only return unique values for last name:

SELECT DISTINCT last_name 
FROM employee 
WHERE salary > 5000; 

Examples:

select * from employees;
select * from employees where dep_id=10;
select name, salary from employees where dep_id=10;