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

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

HP Quality Center - Best Practices

1.Introduction Quality Center is a test management tool which provides very good features for managing both your manual and automated test cases. This paper highlights the best practices for managing your test cases. When you open Quality center, depending on your rights it display the below mentioned option in the sidebar: 1. Requirements 2. Test Plan 3. Test Lab 4. Defects 5. Dashboard 2.Requirements When you have assigned with the responsibility of developing your test cases in the quality center then you must be wondering where to start with. I am going to share my experience to overcome such a situation. You need to find the solution of some question before you start writing your test cases. 1. Is your requirement developed and available? 2. Is your requirement organized in a logical sequence? If answer to both of the above question is Yes, then you can start with Requirement option in the side bar. In case your requirement is under development, then you keep your...

ABC of Unit Testing

What is Unit Testing? After writing any code, every programmer will do some kind of testing to make sure the code works as expected. This testing is called 'unit testing'. Unit testing is done in different ways. Some programmers write simple test applications to test their own code. Some others simply debug the code and change the values during debugging to make sure the code works fine for different cases. Some facts about unit testing: Unit testing is done by developers. Quality department does different tests, they are not unit tests. Every programmer must do unit testing after finishing development or during development itself. Unit testing can be done by writing separate test applications to call your classes and methods to make sure the classes work as expected. This is called manual unit testing. Unit testing can be automated by writing unit test scripts. This is called Automated Unit Testing. In automated Unit Testing, after writing each class/method, you will write sev...