Operators 1

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 25

Data Base Management System & Oracle

Paper V
PGDCS&A

By Rupa Patel
Lecturer, MCA dept.
GHRIIT, Nagpur.
UNIT III -SQL
CODD’s Rules, oracle database objects, Sub Languages of SQL,
data Types, Operators.
DDL Statements : Creating tables, Deriving Table from Existing
table, Altering, Dropping Tables, Integrity
Constraints,Specifying Names for the constraints,Viewing
Integrity constraints,adding & Dropping Constraints.
DML Statements : SELECT statement,Insert,update,Delete,&
Synonyms.
Functions : Arithmetic,Date,Character,Cobnversions.Single
row,Aggregate,Decode,Joins,Set operators & Sub queries.
DCL & TCL Statements : Grant,Revoke,Commit,Rollback &
Savepoints.

Feb 12, 2024 PGDCS&A Unit III 2


Operators
 Operators are used in expressions or conditional
statements.
 An operator manipulates individual data items and
returns a result.
 The data items are called operands or arguments.
 Operators are represented by special characters or
by keywords.
 For example, the multiplication operator is
represented by an asterisk (*) and the operator that
tests for nulls is represented by the keywords IS
NULL.

Feb 12, 2024 PGDCS&A Unit III 3


Operators
 Arithmetic operators
 Comparison operators
 Logical operators
 Set operators
 Concatenation operators
 Assignment Operators
 Date Operators
 Other Built in operators
 User defined operators

Feb 12, 2024 PGDCS&A Unit III 4


1. Arithmetic Operators
Operator Description operation Example

+ Addition <numeric_value> + <numeric_value> SELECT 100 + 10 FROM dual;

- Subtraction <numeric_value> - <numeric_value> SELECT 100 - 10 FROM dual;

* Multiplicatio <numeric_value> * <numeric_value> SELECT 100 * 10 FROM dual;


n
/ Division <numeric_value> / <numeric_value> SELECT 100 / 10 FROM dual;

** Exponentiatio <numeric_value> ** set serveroutput on


n <numeric_value> ;
BEGIN
dbms_output.put_line('2 to the
5th is ' || TO_CHAR(2**5));
END;
/
() Enclosed
operation

Feb 12, 2024 PGDCS&A Unit III 5


Arithmetic Operator

Feb 12, 2024 PGDCS&A Unit III 6


2.Comparison operators
!= Not Equal

Feb 12, 2024 PGDCS&A Unit III 7


Other Comparison Operators

Feb 12, 2024 PGDCS&A Unit III 8


Comparison operators

 SELECT * FROM emp WHERE sal = 1500;


 SELECT * FROM emp WHERE sal != 1500;
 SELECT * FROM emp WHERE sal > 1500;
 SELECT * FROM emp WHERE sal < 1500;
 SELECT * FROM emp WHERE sal >= 1500;
 SELECT * FROM emp WHERE sal <= 1500;

Feb 12, 2024 PGDCS&A Unit III 9


Comparison operators : Between

Feb 12, 2024 PGDCS&A Unit III 10


Comparison operators :IN

Feb 12, 2024 PGDCS&A Unit III 11


Comparison operators : Like
Wildcard Characters
 Single Character :- _ (underscore)
 Multiple Characters :- *
 CREATE TABLE wildcard (test VARCHAR2(25));
INSERT INTO wildcard VALUES ('2345');
INSERT INTO wildcard VALUES ('2365');
INSERT INTO wildcard VALUES ('Daniel Morgan');
INSERT INTO wildcard VALUES ('Washington');
COMMIT;

Single Character
SELECT * FROM wildcard WHERE test LIKE '23_5';

Feb 12, 2024 PGDCS&A Unit III 12


Comparison operators: IS NULL

Feb 12, 2024 PGDCS&A Unit III 13


Comparison operators : Like

Feb 12, 2024 PGDCS&A Unit III 14


Wildcard Characters

 Multiple Characters :
';
SELECT * FROM wildcard WHERE test LIKE '2%5

 Mixed Single And Multiple Characters


SELECT *FROM wildcardWHERE test LIKE '_3%5';

 Complex Statement
SELECT * FROM wildcard WHERE test LIKE '%a%a %';

Feb 12, 2024 PGDCS&A Unit III 15


3. Logical Operators

Feb 12, 2024 PGDCS&A Unit III 16


Logical Operators : OR ,NOT

Feb 12, 2024 PGDCS&A Unit III 17


4.Concatenation Operator

Feb 12, 2024 PGDCS&A Unit III 18


5.Set Operators
Operator Returns

UNION All rows selected BY either


Query

UNION ALL All rows selected BY either


Query, including duplicates

INTERSECT ALL distinct rows selected


by both queries

MINUS ALL distinct rows selected


by first query but not by
second

Feb 12, 2024 PGDCS&A Unit III 19


6.Assignment Operator
 <variable> := <value>
set serveroutput on

DECLARE
x VARCHAR2(1) := 'A';
BEGIN
dbms_output.put_line(x);

x := 'B';
dbms_output.put_line(x);
END;
/

Feb 12, 2024 PGDCS&A Unit III 20


7.Date Operators

 Addition
SELECT <date_value> + <numeric_value>

SELECT SYSDATE + 10 FROM dual;

Subtraction
SELECT <date_value> - <date_value>

SELECT SYSDATE - 10 FROM dual;

Feb 12, 2024 PGDCS&A Unit III 21


8.Other Built-In Operators
 Operator : +
 Purpose : Indicates that the preceding column is the outer
join column in a join.
 Example
SELECT ename, dname FROM emp, dept WHERE dept.deptno
= emp.deptno(+);

Feb 12, 2024 PGDCS&A Unit III 22


9.User-Defined Operators
 Like built-in operators, user-defined operators take a set of
operands as input and return a result. However, you create
them with the CREATE OPERATOR statement, and they are
identified by names (e.g., MERGE). They reside in the same
namespace as tables, views, types, and stand-alone functions.

 Once you have defined a new operator, you can use it in SQL
statements like any other built-in operator. For example, you
can use user-defined operators in the select list of a SELECT
statement, the condition of a WHERE clause, or in ORDER
BY clauses and GROUP BY clauses. However, you must have
EXECUTE privilege on the operator to do so, because it is a
user-defined object.

Feb 12, 2024 PGDCS&A Unit III 23


Feb 12, 2024 PGDCS&A Unit III 24
 Operators are used in expressions or
conditional statements. they show equality,
inequality, or a combination of both.
Mathematical operators are found in every
computer language and may be familiar to
you. SQL operators follow the same rules you
may have learned in a math class or know
from previous programming experience.

Feb 12, 2024 PGDCS&A Unit III 25

You might also like