SQL operators with Oracle

Explanations and examples about SQL language operators, available in the Oracle database engine and in most management systems on the market.

In this article we are going to learn about various operators that you can use in SQL queries for the Oracle database management system.

It is a series of basic operators that, apart from Oracle, are present in most, if not all, database engines.

Arithmetic operators:

They are the typical ones that we use for basic mathematical operations in most languages.

+ = sum

– = Subtraction

* = Multiplication

/ = division

comparison operators

These operators are used to compare two elements with each other.

!> = distinct

>= = Greater than or equal to

<= = Less than or equal to
= = Same as

Also, among the comparison comparators we have a special one, which is used to search for similarities in text strings. This is the “like” operator.

Like = Used to match strings of characters. Properties:

The like operator has associated control characters that allow you to specify any character or any group of characters. You can view them as “wildcards”. First let’s see what they are and then some examples.

% = represents any string of 0 or more characters.

_= represents any single character.

Examples of LIKE operator in SQL for Oracle

We obtain the data of the players whose last names begin with an “S”:

SELECT LAST NAME FROM PLAYERS WHERE LAST NAME LIKE ‘S%’;

We obtain those surnames that have an “R” in the second position:

SELECT LAST NAME FROM PLAYERS WHERE LAST NAME LIKE ‘_R%’;

We obtain those surnames that begin with “A” and have an “o” inside:

See also  Installing IIS on Windows XP Professional

SELECT LAST NAME FROM PLAYERS WHERE LAST NAME LIKE ‘A%O%’;

Logical operators

These types of operators help us to relate Boolean sentences, obtaining another Boolean sentence.

Not = Negation

and = and

or = or

In case someone does not know the logical operators and needs an additional explanation, it should be said that:

  • a and b: It would be true (true or true), if a and b are true at the same time. false otherwise
  • a or b: True if a or b are true, that is, either of the two true would be true. False if both are false at the same time.

Testing with sets of values

Also very useful are the operators that allow us to know if certain elements are in a set of values.

  • In = lets you know whether or not an expression belongs to a set of values.
  • Between = lets you know if an expression is between those values ​​or not:

Examples of SQL statements with in and between operators

Select the last names of the players where the player number (Player_num) is (In) or 10 or 20

SELECT LAST NAME FROM PLAYERS WHERE PLAYER_NUM IN (10, 20);

Select the last names of the players where their salary is not between (Not Between) 15000000 and 20000000.

SELECT LAST NAME FROM PLAYERS WHERE SALARY NOT BETWEEN 15000000 AND 20000000;

That is all for now. We have been able to learn many SQL operators with Oracle. It is important to know them by heart because you will constantly use these operators in your SQL statements.

Loading Facebook Comments ...
Loading Disqus Comments ...