Skip to main content

Database Knowledge for a Tester Part IV

1 COMPUTATIONS ON TABLE DATA

Computations on table data may include displaying an employee’s name and the employee salary from the EMPLOYEE Master table alongwith the annual salary of the employee (i.e. Salary * 12). This can be achieved by using Arithmetic operator. We will see all these explained in below mentioned sections.

1.1 Operators Usage

1.1.1 Arithmetic Operator
Oracle allows arithmetic operators to be used while viewing records from the table or while performing Data Manipulation operations such as Insert, Update and Delete.

For e.g.

Consider we want to increment the salary of all employees by Rs 500.

UPDATE EMPLOYEE SET SALARY = (SALARY + 500)

Similarly you can use the above arithmetic operator for manipulating other data based on the requirement.

1.1.2 Logical Operator


The AND operator
The AND operator requires that each condition must be met for the record to be included in the result set. It can be used in any valid SQL statement such as Select, Insert, Update or Delete.

For e.g.

Consider we want to view the employee whose salary lies between 1000 to 5000.

SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE SALARY>=1000 AND SALARY<=5000.

The OR operator
The OR operator requires that any of the conditions must be met for the record to be included in the result set. It can be used in any valid SQL statement such as Select, Insert, Update or Delete.

For e.g.

Consider we want to view the employee which belongs to either ADMIN or IT department.

SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE DEPTT=’ADMIN’ OR DEPTT=’IT’

Combining the AND and OR operator
It can be used in any valid SQL statement such as Select, Insert, Update or Delete. When combining these conditions it is important to use brackets so that the database knows what order to evaluate each condition.

For e.g.

Consider we want to view the employee and which belongs to either ADMIN or IT department and their salary is greater than 3000.

SELECT EMPLOYEE_NAME, SALARY FROM EMPLOYEE WHERE (DEPTT=’ADMIN’ OR DEPTT=’IT’) AND SALARY>3000.

The NOT operator

The NOT operator display only those records that do not satisfy the conditions specified.

For e.g.

Consider we want to view the employees which are not married.

SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE NOT (MARITAL STATUS=’M’).


1.1.3 Range Searching – BETWEEN operator


The BETWEEN operator allows the selection of rows that contain values within a specified lower and upper limit. The range coded after the word BETWEEN is inclusive.

For e.g.

We can write the “Consider we want to view the employee whose salary lies between 1000 to 5000” also as:

SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE SALARY BETWEEN1000 AND 5000

1.1.4 Pattern Matching – LIKE predicate


The LIKE predicate allows comparison of one string value with another string value, which is not identical. This is achieved by using wildcard characters. Two wildcard characters that are available are:

• % allows to match any string of any length (including zero length)
• _ allows to match on a single character.

For e.g.

Suppose we want to view the Employee Name which starts with Letter “S”.

SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE EMPLOYEE_NAME LIKE ‘S%’

Similarly if we want to view only those employee name which start with letter S and is of 4 characters only.

SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE EMPLOYEE_NAME LIKE ‘S____’

1.1.5 IN and NOT IN Predicates

If a value needs to be compared to a list of values then the IN predicate is used. This predicate helps reduce the need to use multiple OR conditions.

For e.g.

Consider we want the list of all employees which belong to either ADMIN, HR, QUALITY, IT or PROJECT department.

SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE EMPLOYEE_NAME IN (‘ADMIN’,’HR’, ‘QUALITY’,’ IT’, ‘PROJECT’)

Note: NOT IN is just the opposite of IN and select all the rows where values do not match the values in the list.

1.2 Oracle Functions

1.2.1 Oracle Table “DUAL”

DUAL is a table owned by SYS. When an arithmetic calculation is to be performed such as 2*2 or 4/2 and so on, there is no table being referenced; only numeric literals are being used. To facilitate such calculation via a SELECT statement, Oracle provides a dummy table called DUAL.

For e.g.

SELECT 2*2 from DUAL will return 4.

SELECT SYSDATE from DUAL will return system date.

1.2.2 GROUP or AGGREGATE Functions

Functions that act on a set of values are called Group or Aggregate functions. For e.g. SUM is a function which calculated the total set of numbers. A Group function returns a single result row for a group of queried rows.

Some of the GROUP or AGGREGATE Function is described below:



1.2.3 Single Row or Scalar Functions

Functions that act on only one value at a time are called Scalar Functions. Single row function can be classified corresponding to different data types as:
  • String Functions - For String data type.
  • Numeric Functions – For Number data type
  • Conversion Functions – For Conversion data type
  • Date Functions - For Date data type
Some of the available scalar functions are described below:




1.3 Date Functions




1.4 Miscellaneous Functions


UID – This function returns an integer value corresponding to the userid of the user currently logged in.

Syntax:

UID(INTO [variable])

For e.g.

SELECT UID FROM DUAL;

USER – This function returns the user name of the user who has logged in. The value returned is in varchar 2 datatype.

Syntax:

USER

For e.g.
SELECT USER FROM DUAL;

2 REFERENCES


SQL, PL/SQL Third Edition by Ivan Bayross.

3 Download



Click hereto download a pdf copy of this article.

Comments

Popular posts from this blog

Mantis - Defect Management Tool - User Guide

Introduction This white paper contains information related to an open source defect management tool called Mantis which is freely available for managing all your defects. Where to Download One can download the latest version of Mantis from http://sourceforge.net/project/showfiles.php?group_id=14963 Download the “mantis-stable” and then “mantis-x.y.z.zip”.1.1 PRE-REQUISITE Operating System Windows 2003 Server, MacOS, OS/2, Linux, Solaris Database MySQL database 3.23.2 and higher Software PHP 4.0.6 and higher Application Server Apache 1.3, Apache 2.0.54, IIS 6.0 with Web Services Extension Browser IE6 and above, Mozilla Firefox STEPS FOR INSTALLATION – FOR WINDOWS MySQL Installation Install MySQL by downloading it from http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-gui-tools-5.0-r6-win32.msi/from/http:/www.mirrorservice.org/sites/ftp.mysql.com/ . Please follow the below mentioned steps while installing MySQL: (Please remember the password for “root” account...

Why to do Software Testing?

Regardless of the limitations, testing is an integral part in software development. It is broadly deployed in every phase in the software development cycle. Typically, more than 50% percent of the development time is spent in testing. Testing is usually performed for the following purposes: To improve quality. As computers and software are used in critical applications, the outcome of a bug can be severe. Bugs can cause huge losses. Bugs in critical systems have caused airplane crashes, allowed space shuttle missions to go awry, halted trading on the stock market, and worse. Bugs can kill. Bugs can cause disasters. The so-called year 2000 (Y2K) bug has given birth to a cottage industry of consultants and programming tools dedicated to making sure the modern world doesn't come to a screeching halt on the first day of the next century. [Bugs] In a computerized embedded world, the quality and reliability of software is a matter of life and death. Quality means the conformance to the ...

Is BCI (Brain Computer Interface) a road to immortality?

What is a Brain-Computer Interface? Brain-computer interface is a technology which can read your mind and display it on a device - a mobile, laptop or TV screen. It means what data is being carried by our billion neurons are prone to hack.  When combined with other mechanical devices, can also be used to control the device.  So in future, if you want to switch on your TV or light, you just have to think and that's all.  Google and Alexa home will be replaced by BMI controlled devices.  I am not an expert in this field but based on my research and analysis, I can predict that when BMI tech will get matured, the human can do brain to brain talk and many other magical things - in future Telepathy will be a day to day affair. BCI can give you all kind of experience from the comfort of your home.  You can go on vacation without leaving your bedroom. You can have romantic experience without having a partner and many more such experiences. ...