Operators In PLSQL

Operators In PLSQL



Binary Operator
If any operation perform on two operands(variable) is known as binary operator.
In java language these opeatrs are classified into following types.

1.Arithmetic Operators
2.Relational operators
3.Comparison operators
4.Logical operators
5.String operators

Arithmetic Operators
These are the operands can be used to perform simple mathametical operation. Which are classified into following types.
Operator Operation Example
+ Addition x+y
- Substraction x-y
* Multiplication x*y
/ Division x/y
** Exponentiation operator x**y
Write a PLSQL-program to print addition of two numbes
create table calc (sn int ,fno int,sno int ,res int)
insert into calc(sn,fno,sno) values(1,12,12)
insert into calc(sn,fno,sno) values(2,123,124)

DECLARE 
   c_sn calc.sn%type := 1; 
   c_fno  calc.fno%type; 
   c_sno calc.sno%type; 
   c_res int;
BEGIN 
   SELECT fno, sno INTO c_fno, c_sno
   FROM calc
   WHERE sn= c_sn;  
    c_res:=c_fno*c_sno;
     update calc set res=c_res where sn=c_sn;
   dbms_output.put_line ('Multiflication of  ' ||c_sno || ' * ' || c_sno || ' is = ' || c_res); 
END; 
/ 
                                            

Output:

Multiflication of 12* 12 is = 24

Relational Operators
Relational operators are used to check the relation between two variables. These are classified into following types
Operator Example
= x=y
< x<y
> x>y
<= x<=y
>= x>=y
!=
<>
~=
x!=y
x<>y
x~=y
Comparison Operators
Comparison operators are used for comparing one expression to another. The result is always either TRUE, FALSE or NULL.
Operator Description Example
LIKE The LIKE operator compares a character, string, or CLOB value to a pattern and returns TRUE if the value matches the pattern and FALSE if it does not. If 'Zara Ali' like 'Z% A_i' returns a Boolean true, whereas, 'Nuha Ali' like 'Z% A_i' returns a Boolean false.
BETWEEN The BETWEEN operator tests whether a value lies in a specified range. x BETWEEN a AND b means that x >= a and x <= b. If x = 10 then, x between 5 and 20 returns true, x between 5 and 10 returns true, but x between 11 and 20 returns false.
IN The IN operator tests set membership. x IN (set) means that x is equal to any member of set. If x = 'm' then, x in ('a', 'b', 'c') returns Boolean false but x in ('m', 'n', 'o') returns Boolean true.
IS NULL The IS NULL operator returns the BOOLEAN value TRUE if its operand is NULL or FALSE if it is not NULL. Comparisons involving NULL values always yield NULL. If x = 'm', then 'x is null' returns Boolean false.
Write a C-program to print logical operators program using &&, || ,!


Logical Operators
Following table shows the Logical operators supported by PL/SQL. All these operators work on Boolean operands and produce Boolean results. Let us assume variable A holds true and variable B holds false, then −
Operator Description Example
and Called the logical AND operator. If both the operands are true then condition becomes true. (A and B) is false.
or Called the logical OR Operator. If any of the two operands is true then condition becomes true. (A or B) is true.
not Called the logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true then Logical NOT operator will make it false. not (A and B) is true.