Skip to main content

WHERE clause in ORACLE


  • This clause is used to provide comparison of data, which restricts the rows from a table.
  • A WHERE clause contains a condition that must be met and should directly follow the from clause.
  • Comparison to date type data is not case sensitive.
  • Character values are case sensate and Date values are format Sensitive (DD-MON-YY).
  • The WHERE clause can compares..
          Ø  Values in columns
          Ã˜  Literal Values
          Ã˜  Arithmetic Expressions
          Ã˜  Function
    Examples :-

    Display all those employees, who are working as CLERK.

    Ans : Select * from emp where job = ‘CLERK’;

    Display all those employees, who are working in deptno 20.

    Ans : Select * from emp where deptno=20;

    Display all those employees, who have been hired on 3rd-dec-81.

    Ans : Select * from emp where hiredate=’3rd-dec-81’;

    Display empno,ename,job,sal,deptno for all those employees who are working in deptno 20 and as CLERK.

    Ans : Select empno, ename, job, sal, deptno from emp
    Where deptno=20 AND job=’CLERK’;

    Display ename,job,salary,deptno for all those employees who are not working as MANAGER.

    Ans : Select ename, job, sal, deptno from emp
              Where job !=’MANAGER’;

    Display ename, job, salary, deptno for all those employees whose salary is >=2000.

    Ans : Select ename, job, sal, deptno from emp
              Where sal>=2000;

    Display ename, job, salary for all those employees whose salary is >=1000 and <= 3000.

    Ans : Select ename, job, sal from emp
              Where sal>=1000 AND sal<=3000;

    (OR) sal BETWEEN 1000 AND 3000;

    Display ename, job, salary, deptno, hiredate fro all those employees who have been hired between 01-jan-81 and 31-dec-81 and they are working as clerk, salesman and salary between 1000 and 3000;

    Ans : Select ename, job, sal, deptno, hiredate
              From emp
              Where hiredate BETWEEN ’01-JAN-81’ AND ’31-DEC-81’
              AND
              Job IN (‘CLERK’ , ‘SALESMAN’)
              AND
              Sal BETWEEN 1000 AND 3000;

    Display ename, job for all those employees who are not working as clerk, analyst.

    Ans : select ename, job from emp
              Where job NOT IN (‘CLERK’ , ‘ANALYST’);

                                 

Comments

Popular posts from this blog

Oracle Object Oriented Concepts

An Object is a reusable application component that developers need to be aware of, rather than how it works. Object are basic entities in a system. They could represent a person, place, bank account, or any item that is handled by program. Every object consists of an attribute and one or more methods. An attribute could be any property of the object. Class:           It is a collection of attributes and functions (method) to plan the object. Object Table : ·    Object table are created by using the user defined data types. ·        In an object table each row or record is treated as an object. ·        Each row in an object table has an object Identified (OID), which is unique through out       the   database. ·       The rows or objects of an object table can be referenced by other objects with in the  database. ·    ...

Filtering and Sorting data using SQL statements

  Filtering & Sorting Data using SQL     Once you know the basics ( SELECT , FROM , WHERE ), filtering and sorting helps you get the exact rows from tables .   1. Filtering with Conditions ( AND , OR , NOT )  - Use WHERE to filter rows. - Combine with logical operators :     • AND: all conditions true      • OR: any condition true      • NOT: negate condition   - - All conditions true (AND) SELECT *  FROM employees WHERE department = 'Sales'    AND salary > 50000; -- Any condition true (OR) SELECT *  FROM employees WHERE department = 'Sales'     OR department = 'Marketing'; -- Negate condition (NOT) SELECT *  FROM employees WHERE NOT department = 'HR';   2. Pattern Matching with LIKE   - % = any sequence, _ = single char     • Names starting with 'J'      • Names with 4 letters starting with 'J'   - - N...

About Oracle Buffer

About Oracle Buffer :- All Commands of SQL are typed at the SQL prompt. Only one SQL statement is managed in the SQL buffer. The current SQL statement replaces the previous SQL statement in the buffer. The SQL statements can be divided into different lines within the SQL buffer. Only one line i.e, the current line can be active at a time in the SQL buffer. At SQL prompt, editing is possible only in the current SQL buffer line. Every statement of SQL should be terminated using semi colon " ; ". One sql statement can contain only one semi colon. To run the previous or current SQL statement in the bufer type " / " at SQL prompt. To open the SQL editor type " ED " at SQL prompt.