13
Operators Supported By SQL*Plus: The operators supported by SQL*Plus are classified into three categories. 1. Arithmetic operators 2. Comparison Operators 3. Logical operators

Operators Supported By SQL*Plus:

  • Upload
    chuong

  • View
    49

  • Download
    0

Embed Size (px)

DESCRIPTION

Operators Supported By SQL*Plus: The operators supported by SQL*Plus are classified into three categories. 1. Arithmetic operators 2. Comparison Operators 3. Logical operators. Arithmetic Operators: - PowerPoint PPT Presentation

Citation preview

Page 1: Operators Supported By SQL*Plus:

• Operators Supported By SQL*Plus:

The operators supported by SQL*Plus are classified into three categories.

1. Arithmetic operators

2. Comparison Operators

3. Logical operators

Page 2: Operators Supported By SQL*Plus:

• Arithmetic Operators:

To perform calculations based on number values, we include arithmetic expressions in SQL command.

An arithmetic expression consists of column names with number data type and an arithmetic operators connecting them.

The arithmetic operators are

addition (+)

subtraction (-)

multiplication (*)

division (/)

exponentiation (**)

Enclosed Operations ( )

Page 3: Operators Supported By SQL*Plus:

• Example Of Arithmetic Operator:

Retrieve the contents of the column product_no, description and compute 5% of the values contained in the column sell_price and 105% of the values contained in the field sell_price for each row from the table product_master.

select product_no, description , sell_price * 0.05, sell_price * 1.05, from product_master ;

Here sell_price * 0.05, sell_price * 1.05 are not columns in the table

product_master.

The calculations are done on the columns sell_price.

By default, the oracle engine will use column names of the table product_master as column headerswhen displaying column output.

As there are no columns with the names sell_price * 0.05, sell_price * 1.05 in the table product_master, the engine will perform the required operation & use each formula as the default column header when displaying output.

Page 4: Operators Supported By SQL*Plus:

• Renaming Column Names

• We can rename the default output column names with an alias, when required.

Syntax:

select default columnname new columnname from tablename;

Example:

select product_no, description , sell_price * 0.05 increase, sell_price * 1.05 new price from product_master ;

Page 5: Operators Supported By SQL*Plus:

• Comparison Operators:

Comparison Operators are used in conditions to compare one expression with another.

They are =, !=, <, >, <=, >=, between, in, like, null. between, in, like, null can also be used for checking ‘not’ condition.

(not between, not in etc.)

Page 6: Operators Supported By SQL*Plus:

• Range Searching:• Between Operator:

In order to select data that is within the range of values, the between operator is used.

The Between operator allows the selection of rows that contain values within a specified lower and upper limits.

The range coded after the word between is inclusive. The lower value must be coded first. The two values in between the range must be linked with the keyword

AND. We can use this operator with both character and numeric data types.

However one cannot mix the data types.

Page 7: Operators Supported By SQL*Plus:

• Examples of Between & Not Between: Between:

Retrieve product_no, description, profit_%, sell_price from product_master table where values contained within the field profit_% is between 10 and 20.

select product_no, description, profit_%, sell_pricefrom product_masterwhere profit_% between 10 and 20;

The above query will retrieve all records for specified columns from specified table Where the profit_% is in between 10 & 20, both values inclusive.

NOT Between:select product_no, description, profit_%, sell_price

from product_masterwhere profit_% not between10 and 20;

The above query will retrieve all records for specified columns from specified table

Except Where the profit_% is in between 10 & 20, both values inclusive.

Page 8: Operators Supported By SQL*Plus:

• Pattern Matching Operators:

They are as mentioned below.

1.Like

2. not like

3.In

4. Not in

The comparison operators discussed so far have compared one value, exactly to one other value. Such situation may not be always required. For this purpose Oracle provides a predicate ‘like’.

Page 9: Operators Supported By SQL*Plus:

• The use of Like predicate:

Like predicate allows comparison of one string with another string value, which is not identical.

This is achieved by using two wild card characters. They are percent (%) sign and underscore ( _ )

For character data types % sign matches any string _ matches any single character.

Examples:1.Retrieve all information about suppliers whose names starts with the letters ‘ja’ from supplier_master.

select * from supplier_masterwhere supplier_master like ‘ja%’ ;

2. Retrieve all information about suppliers where the second character of names are either ‘r’ or ‘h’.

select * from supplier_masterwhere supplier_name like ‘_r%’ or supplier_name like ‘_h

%’ ;

Page 10: Operators Supported By SQL*Plus:

• In Operator: In case a value needs to be compared to a list of values then the In

operator is used.

i.e. One can check a single value against multiple values

by using the In operator.

select suplier_name

from supplier_master

where supplier_name in (‘Akash’, ‘Anand’, ‘Pradeep’);

• Not In:

select suplier_name

from supplier_master

where supplier_name not in (‘Akash’, ‘Anand’, ‘Pradeep’);

Page 11: Operators Supported By SQL*Plus:

• Logical Operators:

1. AND Operator:

The Oracle engine will process all rows in a table and display the results only when all of the conditions specified using the AND operator are satisfied.

select *

from product_master

where profit_% = 10 and profit_%=20;

Page 12: Operators Supported By SQL*Plus:

1. OR Operator:

The Oracle engine will process all rows in a table and display the results only when any of the conditions specified using the OR operator are satisfied.

select *

from product_master

where profit_% = 10 OR profit_%=20;

Page 13: Operators Supported By SQL*Plus:

3. NOT Operator:

The Oracle engine will process all rows in a table and display the results only when none of the conditions specified using the NOT operator are satisfied.

select suplier_name

from supplier_master

where supplier_name not in (‘Akash’, ‘Anand’, ‘Pradeep’);