1 / 13

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. Arithmetic Operators:

chuong
Download Presentation

Operators Supported By SQL*Plus:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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 ( )

  3. 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.

  4. 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 ;

  5. 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.)

  6. 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.

  7. 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_price from product_master where 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_master where 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.

  8. 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’.

  9. 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_master where supplier_master like ‘ja%’ ; 2. Retrieve all information about suppliers where the second character of names are either ‘r’ or ‘h’. select * from supplier_master where supplier_name like ‘_r%’ or supplier_name like ‘_h%’ ;

  10. 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’);

  11. 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;

  12. 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;

  13. 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’);

More Related