oracle sql and dba tutorial logo

Tutorial for Oracle DBA


Oracle DBA Interview Questions

Most asked Oracle DBA Interview Questions.

60 Technical Questions

42 Backup & Recovery Questions

Unix For Oracle DBA 20 Questions


 

Oracle SQL Tutorial Contents

Introduction to Databases

CODD'S Rules

Datatypes and Create Table

Oracle SELECT Statement

Formatting in SQL*Plus

UNION, INTERSECT, MINUS Operators and Sorting Query Result

 

Oracle ALTER TABLE ADD COLUMN

Oracle ALTER TABLE MODIFY COLUMN

Oracle SQL Functions

Oracle NVL() Function with Examples

Oracle SUBSTR() function with Examples

Oracle TO_DATE() with complete examples

Oracle DECODE function

Oracle INSTR() function with examples

Oracle TO_CHAR() function

Oracle TO_TIMESTAMP

Number Functions (Math Functions)

Character Functions

Miscellaneous Functions

Aggregate Functions

Date and Time Functions

Oracle Join Queries

GROUP BY Queries, SUB Queries

CUBE, ROLLUP Functions

Oracle DML (INSERT, UPDATE, DELETE...)

Oracle DDL (CREATE, ALTER, DROP...)

COMMIT, ROLLBACK,SAVEPOINT

Data Control Language (GRANT, REVOKE)

 

 

Integrity Constraints (PRIMARY KEY, NOT NULL...)

DEFAULT Values

Dropping Constraints

Disabling and Enabling

Differing Constraints Check

View Info about Constraints

Working with Dates

Oracle Views

Oracle Sequences

Oracle Synonyms

Indexes and Clusters

Table Partitioning

Altering Partition Tables

Dropping Partitions

Merging Partitions

Splitting Partitions

Coalescing Partitions

Oracle Objects and Object Types

 

 

 

 

 

 

 

 

 

Oracle SQL SELECT Statement

SQL Queries, SELECT Statement

Use a SELECT statement or subquery to retrieve data from one or more tables, object tables, views, object views, or materialized views

For example to retrieve all rows from emp table.

SQL> select  empno, ename, sal  from emp;

          Or (if you want to see all the columns values

You can also give * which means all columns)

SQL> select * from emp;

If you want to see only employee names and their salaries then you can type the following statement

SQL> select name, sal from emp;

Filtering Information using Where Conditions

            You can filter information using where conditions like suppose you want to see only those employees whose salary is above 5000 then you can type the following query with where condition

SQL>select * from emp where sal > 5000;

To see those employees whose salary is less than 5000 then the query will be

SQL> select * from emp where sal < 5000;

Logical Conditions

A logical condition combines the results of two component conditions to produce a single result based on them or to invert the result of a single condition. Table below lists logical conditions.

Condition  Operation  Example 
NOT   Returns TRUE if the following condition is FALSE. Returns FALSE if it is TRUE. If it is UNKNOWN, it remains UNKNOWN.  SELECT * FROM emp WHERE NOT (sal IS NULL);

SELECT * FROM emp WHERE NOT (salary BETWEEN  1000 AND 2000);  
AND   Returns TRUE if both component conditions are TRUE. Returns FALSE if either is FALSE. Otherwise returns UNKNOWN.  SELECT * FROM employees WHERE ename ='SAMI' AND sal=3000;  
OR   Returns TRUE if either component condition is TRUE. Returns FALSE if both are FALSE. Otherwise returns UNKNOWN.  SELECT * FROM emp WHERE ename = 'SAMI' OR sal >= 1000;  

 Membership Conditions

A membership condition tests for membership in a list or subquery

The following table lists the membership conditions.

Condition 

Operation 

Example 

IN "Equal to any member of" test. Equivalent to "= ANY".  SELECT * FROM emp WHERE deptno IN (10,20);

SELECT * FROM emp   WHERE deptno IN (SELECT deptno FROM dept WHERE city=’HYD’)
NOT IN Equivalent to "!=ALL". Evaluates to FALSE if any member of the set is NULL.  SELECT * FROM emp  WHERE ename NOT IN  ('SCOTT', 'SMITH');

Null Conditions

A NULL condition tests for nulls.

What is null?

If a column is empty or no value has been inserted in it then it is called null. Remember 0 is not null and blank string ‘ ’ is also not null.

The following example lists the null conditions.

Condition 

Operation 

Example 

IS [NOT]

NULL

 

Tests for nulls. This is the only condition that you should use to test for nulls.

 

 

 

SELECT ename  FROM emp  WHERE deptno  IS NULL; 

SELECT * FROM emp WHERE ename IS NOT NULL;

 

 

EXISTS Conditions

An EXISTS condition tests for existence of rows in a subquery.

The following example shows the EXISTS condition.

Condition 

Operation 

Example 

EXISTS

 

TRUE if a subquery returns at least one row. 


SELECT deptno   FROM dept d  WHERE EXISTS
    (SELECT * FROM emp e
          WHERE d.deptno = e.deptno);

  

LIKE Conditions

The LIKE conditions specify a test involving pattern matching. Whereas the equality operator (=) exactly matches one character value to another, the LIKE conditions match a portion of one character value to another by searching the first value for the pattern specified by the second. LIKE calculates strings using characters as defined by the input character set.

For example you want to see all employees whose name starts with S char. Then you can use LIKE condition as follows

SQL> select * from emp where ename like ‘S%’ ;

Similarly you want to see all employees whose name ends with “d”

SQL>select * from emp where ename like ‘%d’;

You want to see all employees whose name starts with ‘A’ and ends with ‘d’ like ‘Abid’, ’Alfred’, ’Arnold’.

SQL>select * from emp where ename like ‘A%d’;

You want to see those employees whose name contains character ‘a’ anywhere in the string.

SQL> select * from emp where ename like ‘%a%’;

To see those employees whose name contains ‘a’ in second position.

SQL>select * from emp where ename like ‘_a%’;

To see those employees whose name contains ‘a’ as last second character.

SQL>select * from emp where ename like ‘%a_’;

To see those employees whose name contain ‘%’ sign.  i.e. ‘%’ sign has to be used as literal not as wild char.

SQL> select * from emp where ename like ‘%\%%’ escape ‘\’;

 

 


HomeContact Us

Data Loader

Data Loader is a simple yet powerful tool to
export and import Data between many common database formats


Forms Data Loader

Tool to load data into Oracle E-Business Suite R12 / Oracle Apps using Macros and Forms Record and Playback

Interface Computers Academy © 2007-2017 All Rights Reserved