Trending December 2023 # Oracle Pl/Sql If Then Else Statement: Elsif, Nested # Suggested January 2024 # Top 15 Popular

You are reading the article Oracle Pl/Sql If Then Else Statement: Elsif, Nested updated in December 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Oracle Pl/Sql If Then Else Statement: Elsif, Nested

What are Decision-Making Statements?

Decision making statements are those who will decide the flow-control of SQL statements based on the conditions. It gives the programmer a better control of preventing a particular code from executing (diagram 1) or choosing a desired code based on the condition (diagram 2). Below is the pictorial representation of the “Decision Making Statement”.

Decision Making Statement Diagram

Types of Decision Making Statements:

Oracle provides the following types of decision making statements.

IF-THEN

IF-THEN-ELSE

IF-THEN-ELSIF

NESTED-IF

CASE

SEARCHED CASE

In this tutorial, you will learn-

IF-THEN Statement

The IF-THEN statement is mainly used to execute a particular section of codes only when the condition is satisfied.

The condition should yield Boolean (True/False). It is a basic conditional statement which will allow the ORACLE to execute/skip a particular piece of code based on the pre-defined conditions.

Syntax for IF THEN Statements:

THEN -executed only if the condition returns TRUE END if;

In the above syntax, keyword ‘IF’ will be followed by a condition which evaluates to ‘TRUE’/’FALSE’.

Note: Whenever condition evaluated to ‘NULL’, then SQL will treat ‘NULL’ as ‘FALSE’.

Example 1: In this example, we are going to print a message when the number is greater than 100. For that, we will execute the following code

To print a message when a number has value more than 100, we execute the following code.

DECLARE a NUMBER :=10; BEGIN dbms_output.put_line(‘Program started.' ); dbms_output.put_line('a is greater than 100'); END IF; dbms_output.put_line(‘Program completed.'); END; /

Code Explanation:

Code line 2: Declaring the variable ‘a’ as ‘NUMBER’ data type and initializing it with value ’10’.

Code line 4: Printing the statement “Program started”.

Code line 5: Checking the condition, whether variable ‘a’ is greater than ‘100.’

Code line 6: If ‘a’ is greater than ‘100’, then “a is greater than 100” will be printed. If ‘a’ is lesser than or equal to 100, then condition fails, so the above printing statement ignored.

Code line 8: Printing the statement “Program completed”.

Code Output:

Program started. Program completed.

Example 2: In this example, we are going to print a message if a given alphabet is present in English vowels (A, E, I, O, U).

To print a message when the given character is Vowel, we execute the following code.

DECLARE a CHAR(1) :=’u’; BEGIN IF UPPER(a) in ('A’,'E','I','0','U' ) THEN dbms_output.put_line(‘The character is in English Vowels'); END IF; END; /

Code Explanation:

Code line 2: Declaring the variable ‘a’ as ‘CHAR’ of size ‘1’ data type and initializing it with value ‘u’.

Code line 4: Checking the condition, whether variable ‘a’ is present in the list (‘A’,’E’,’I’,’O’,’U’).

Value of ‘a’ has been converted to uppercase before comparing to make the comparison is case-insensitive.

Code line 5: If ‘a’ is present in the list, then the statement “The character is in English Vowels” will be printed. If condition failed, then this program will not give any output, as outside the IF-THEN block we have not issued any printing statement.

Code Output:

The character is in English Vowels IF-THEN-ELSE Statement

The IF-THEN-ELSE statement is mainly used to select between two alternatives based on the condition.

Below is the syntax representation of IF-THEN-ELSE statement.

Syntax for IF-THEN-ELSE Statements:

THEN -executed only if the condition returns TRUE ELSE -execute if the condition failed (returns FALSE) END if;

In the above syntax, keyword ‘IF’ will be followed by a condition which evaluates to ‘TRUE’/’FALSE’.

In any case, one of the two action blocks will be executed.

Note: Whenever condition evaluates to ‘NULL’, then SQL will treat ‘NULL’ as ‘FALSE’.

Example 1: In this example, we are going to print message whether the given number is odd or even.

DECLARE a NUMBER:=11; BEGIN dbms_output.put_line (‘Program started'); IF( mod(a,2)=0) THEN dbms_output.put_line('a is even number' ); ELSE dbms_output.put_line('a is odd number1); END IF; dbms_output.put_line (‘Program completed.’); END; /

Code Explanation:

Code line 2: Declaring the variable ‘a’ as ‘NUMBER’ data type and initializing it with value ’11’.

Code line 4: Printing the statement “Program started”.

Code line 5: Checking the condition, whether modulus of variable ‘a’ by ‘2’ is 0.

Code line 6: If ‘0’, then “a is even number” will be printed.

Code line10: Printing the statement “Program completed”

Code Output:

Program started. a is odd number Program completed. IF-THEN-ELSIF Statement

The IF-THEN-ELSIF statement is mainly used where one alternative should be chosen from a set of alternatives, where each alternative has its own conditions to be satisfied.

The IF-THEN-ELSIF statement may contain ‘ELSE’ block in it. This ‘ELSE’ block will be executed if none of the conditions is satisfied.

Note: ELSE block is optional in this conditional statement. If there is no ELSE block, and none of the condition satisfied, then the controller will skip all the action block and start executing the remaining part of the code.

Syntax for IF-THEN-ELSIF Statements:

THEN -executed only if the condition returns TRUE < ELSE —optional END if;

If condition1 is not satisfied, then the controller will check for condition2.

The controller will exit from the IF-statement in the following two cases.

When none of the conditions satisfied, the then controller will execute ELSE block if present, then will exit from the IF-statement.

Note: Whenever condition evaluates to ‘NULL’, then SQL will treat ‘NULL’ as ‘FALSE’.

Example 1: Without ELSE block

DECLARE mark NUMBER :=55; BEGIN dbms_output.put_line(‘Program started.’ ); dbms_output.put_line(‘Grade A’); dbms_output.put_line(‘Grade B'); dbms_output.put_line(‘Grade C’); END IF; dbms_output.put_line(‘Program completed.’); END; /

Code Explanation:

Code line 2: Declaring the variable ‘mark’ as ‘NUMBER’ data type and initializing it with value ’55’.

Code line 4: Printing the statement “Program started”.

Code line 5: Checking the condition1, whether ‘mark’ is greater or equal 70.

Code line12: Printing the statement “Program completed”.

Code Output:

Program started. Grade B Program completed.

Example 2: With ELSE block

DECLARE mark NUMBER :=25; BEGIN dbms_output.put_line(‘Program started.’ ); dbms_output.put_line(‘Grade A’); dbms_output.put_line(‘Grade B'); dbms_output.put_line(‘Grade C); ELSE dbms_output.put_line(‘No Grade’); END IF; dbms_output.put_line(‘Program completed.' ); END; /

Code Explanation:

Code line 2: Declaring the variable ‘mark’ as ‘NUMBER’ data type and initializing it with value ’25’.

Code line 4: Printing the statement “Program started”.

Code line 5: Checking the condition 1, whether ‘mark’ is greater or equal 70.

Code line 11: Since all the conditions are failed, control will now check for the presence of ELSE block, and it will print the message ‘No Grade’ from ELSE block.

Code line14: Printing the statement “Program completed”.

Code Output:

Program started. No Grade Program completed. NESTED-IF Statement

The ‘IF’ statement will consider the nearest ‘END IF’ statement as an endpoint for that particular condition.

The pictorial representation for NESTED-IF is shown below diagram.

THEN —executed only if the condition returns TRUE THEN END IF; —END IF corresponds to condition2 END IF; —END IF corresponds to condition1

Syntax Explanation:

In the above syntax, the outer IF contains one more IF statement in its action block.

Here we are going to see an example of Nested If –

Example of Nested- If Statement: Greatest of three number

In this example, we are going to print the greatest of three numbers by using Nested-If statement. The numbers will be assigned in the declare part, as you can see in the code below, i.e Number= 10,15 and 20 and the maximum number will be fetched using nested-if statements.

DECLARE a NUMBER :=10; b NUMBER :=15; c NUMBER :=20; BEGIN dbms_output.put_line(‘Program started.' ); /*Nested-if l */ dbms_output.put_line(’Checking Nested-IF 1'); dbms_output.put_line(‘A is greatest’); ELSE dbms_output.put_line(‘C is greatest’); END IF; ELSE /*Nested-if2 */ dbms_output.put_line('Checking Nested-IF 2' ); dbms_output.put_line(’B is greatest' ); ELSE dbms_output.put_line(’C is greatest' ); END IF; END IF; dbms_output.put_line(‘Program completed.’ ); END; /

Code Explanation:

Code line 2: Declaring the variable ‘a’ as ‘NUMBER’ data type and initializing it with value ’10’.

Code line 3: Declaring the variable ‘b’ as ‘NUMBER’ data type and initializing it with value ’15’.

Code line 4: Declaring the variable ‘c’ as ‘NUMBER’ data type and initializing it with value ’20’.

Code line 6: Printing the statement “Program started” (line 6).

Code line 7: Checking the condition1, whether ‘a’ is greater than ‘b’ (line 7).

Code line 10: If ‘a’ is greater than ‘b, then condition in ‘nested-if 1’ will check if ‘a’ is greater than ‘c'(line 10).

Code line 13: If still ‘a’ is greater, then message ‘A is greatest’ will be printed (line 11). Else if condition2 fails, then ‘C is greatest’ will be printed (line 13).

Code line 18: In case condition1 returns false, then condition in ‘nested-if 2’ will check if ‘b’ is greater than ‘c'(line 18).

Code line 21: If ‘b’ is greater than ‘c’ , then message ‘B is greatest’ will be printed (line 19), else if condition2 fails, then ‘C is greatest’ will be printed (line 21).

Code line 24: Printing the statement “Program completed” (line 24).

Output of code:

Program started. Checking Nested-IF 2 C is greatest Program completed. Summary

In this chapter, we have learned the different decision-making statements and their syntax and examples. Below table gives the summary of various conditional statements that we have discussed.

TYPE DESCRIPTION USAGE

IF-THEN Checks for a Boolean condition, if TRUE code in ‘THEN’ block will be executed. To skip,/execute a particular code based on the condition.

IF-THEN-ELSE Checks for a Boolean condition, if TRUE code in ‘THEN’ block will be executed, if false code in ‘ELSE’ block is executed. Most appropriate in ‘THIS-OR-THAT’ condition.

IF-THEN-ELSIF Checks for a Boolean condition in sequential order. The first block in the sequence which returns TRUE condition will be executed. If none of the conditions in the sequence is TRUE, then code in ‘ELSE’ block is executed. Used to choose from more than two alternatives mostly.

NESTED-IF Allows one or more IF-THEN or IF-THEN-ELSIF statement inside another IF-THEN or IF-THEN-ELSIF statement(s). Mainly used in nested condition situation.

You're reading Oracle Pl/Sql If Then Else Statement: Elsif, Nested

If Else Statement In Python: Understanding Concept Conditional

Introduction to if-else Statement in Python

To test which conditions are either TRUE or FALSE amongst two or more, the Python programming language provides a logical statement structure of the form IF-ELIF-ELSE which can be considered the form if statement followed by one or more else if represented as elif in Python. The else statement validates desired conditions against certain criteria or assumptions, enabling the user to perform a required task based on the output returned in the context of the IF ELSE logical statement in Python.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax in Python:

… … else:

The tab always indents the body of the if-else statement.

You can use various logical conditions inside the if-else statement for evaluation. Let’s say p and q are variables defined in the Python environment. The condition could be:

p == q.

p != q

p < q

p <= q

Flowchart

The flowchart shows that the program first evaluates the test expression. If the expression evaluates to ‘True,’ it executes a specified set of statements. If it evaluates to ‘False,’ it executes another specified set of statements.

Here is the node representation, which can be converted into the if-else statement.

if (A) { XX } elif (B) { YY } else{ ZZ } Examples of if-else Statement in Python

Let’s see some examples to understand if-else more:

Example #1

Code:

var = 100 print("true expression executed") else: print("false expression executed")

Output:

As one can see, var = 100. If the value checked in the if condition is greater than 100, the program prints “True expression executed.” However, if a value is less than or equal to 90, see how this code would have behaved below.

var = 90 print("true expression executed") else: print("false expression executed")

There could use a one-liner code for the above logic.

Code:

var = 100

Output:

Example #2

Now let’s see some comparison of variables.

Code:

p = 90 q = 20 print("true expression executed") print("false expression executed") else: print("Nothing")

Output:

Example #3

Now let’s see the use of the logical operator in an if-else statement:

Code:

p = 2000 q = 3330 r = 600 print("Both conditions are True") else: print("Nothing")

Output:

The same way it can be done for “OR.”

Code:

p = 2000 q = 30 r = 600 print("Any one expression is true") else: print("Nothing")

Output:

Code:

p = 2000 q = 30 r = 600 s = 60 t = 60 print("True is this") else: print("Nothing")

Output:

Example #4

Now let’s see an if-else statement with a pass operator.

There are ample situations where one doesn’t know what logic to put at the writing program’s start. The pass operator is the one that is used at that time.

Code:

pass else: print("Nothing")

Output:

If a statement evaluates to true and contains a pass operator, the program doesn’t print anything

Conclusions

As we saw above, how important is the concept of if-else? Knowing its ways of implementation in your code will help you get a good understanding of it. If one is already familiar with the if-else statement in another computer language, then it becomes really easy to understand the if-else in Python. Concept wise remains the same; syntactically, it varies in Python.

When someone has multiple conditions, one should use if-else if statements rather than a nested if-else statement. This will make the code more readable and cleaner. Similarly, the more one practices various if-else, the more one will learn about their easiness and practicality.

However, one can look for a dictionary concept as an alternative to the if-else statement.

Recommended Articles

We hope this EDUCBA information on “If else Statement in Python” benefited you. You can view EDUCBA’s recommended articles for more information.

Excel Vba Select Case Statement

Case Value_1 Code Block when Test_Expression = Value_1 Case Value_2 Code Block when Test_Expression = Value_2 Case Value_3 Code Block when Test_Expression = Value_3 Case Else Code Block when none of the case conditions are met Dim UserInput As Integer UserInput = InputBox(“Please enter a number between 1 and 5”) Select Case UserInput Case 1 MsgBox “You entered 1″ Case 2 MsgBox “You entered 2″ Case 3 MsgBox “You entered 3″ Case 4 MsgBox “You entered 4″ Case 5 MsgBox “You entered 5″ End Select Dim UserInput As Integer UserInput = InputBox(“Please enter a number”) Select Case UserInput Case Is < 100 MsgBox “You entered a number less than 100″ MsgBox “You entered a number more than (or equal to) 100″ End Select Dim UserInput As Integer UserInput = InputBox(“Please enter a number”) Select Case UserInput Case Is < 100 MsgBox “You entered a number less than 100″ Case Else MsgBox “You entered a number more than (or equal to) 100″ End Select Dim UserInput As Integer UserInput = InputBox(“Please enter a number between 1 and 100”) Select Case UserInput Case 1 To 25 MsgBox “You entered a number less than 25″ Case 26 To 50 MsgBox “You entered a number between 26 and 50″ Case 51 To 75 MsgBox “You entered a number between 51 and 75″ Case 75 To 100 MsgBox “You entered a number more than 75″ End Select Dim StudentMarks As Integer Dim FinalGrade As String StudentMarks = InputBox(“Enter Marks”) Select Case StudentMarks Case Is < 33 FinalGrade = “F” Case 33 To 50 FinalGrade = “E” Case 51 To 60 FinalGrade = “D” Case 60 To 70 FinalGrade = “C” Case 70 To 90 FinalGrade = “B” Case 90 To 100 FinalGrade = “A” End Select MsgBox “The Grade is ” & FinalGrade End Sub

The above code asks the user for the marks and based on it, shows a message box with the final grade.

In the above code, I have specified all the conditions – for marks 0 – 100.

Another way to use Select Case is to use a Case Else at the end. This is useful when you have accounted for all the conditions and then specify what to do when none of the conditions is met.

The below code is a variation of the Grade code with a minor change. In the end, it has a Case else statement, which will be executed when none of the above conditions are true.

Sub CheckOddEven() Dim StudentMarks As Integer Dim FinalGrade As String StudentMarks = InputBox("Enter Marks") Select Case StudentMarks Case Is < 33 FinalGrade = "F" Case 33 To 50 FinalGrade = "E" Case 51 To 60 FinalGrade = "D" Case 60 To 70 FinalGrade = "C" Case 70 To 90 FinalGrade = "B" Case Else FinalGrade = "A" End Select MsgBox "The Grade is " & FinalGrade Dim FinalGrade As String Select Case StudentMarks Case Is < 33 FinalGrade = "F" Case 33 To 50 FinalGrade = "E" Case 51 To 60 FinalGrade = "D" Case 60 To 70 FinalGrade = "C" Case 70 To 90 FinalGrade = "B" Case Else FinalGrade = "A" End Select GetGrade = FinalGrade CheckValue = Range("A1").Value Select Case (CheckValue Mod 2) = 0 Case True MsgBox "The number is even" Case False MsgBox "The number is odd" End Select Select Case Weekday(Now) Case 1, 7 MsgBox "Today is a Weekend" Case Else MsgBox "Today is a Weekday" End Select Select Case Weekday(Now) Case 1, 7    Select Case Weekday(Now)    Case 1       MsgBox "Today is Sunday"    Case Else       MsgBox "Today is Saturday"   End Select Case Else MsgBox "Today is a Weekday" End Select Dim Department As String Department = InputBox("Enter Your Department Name") Select Case Department Case "Marketing" MsgBox "Please connect with Bob Raines for Onboarding" Case "Finance" MsgBox "Please connect with Patricia Cruz for Onboarding" Case "HR" MsgBox "Please connect with Oliver Rand for Onboarding" Case "Admin" MsgBox "Please connect with Helen Hume for Onboarding" Case Else MsgBox "Please connect with Tony Randall for Onboarding" End Select End Sub

Hope all the examples above were helpful in understanding the concept and application of Select Case in Excel VBA.

You May Also Like the Following VBA Tutorials:

The Return Statement In Python

The return statement in python is an extremely useful statement used to return the flow of program from the function to the function caller. The keyword return is used to write the return statement.

Since everything in python is an object the return value can be any object such as – numeric (int, float, double) or collections (list, tuple, dictionary) or user defined functions and classes or packages.

The return statement has the following features –

Return statement cannot be used outside the function.

Any code written after return statement is called dead code as it will never be executed.

Return statement can pass any value implicitly or explicitly, if no value is given then None is returned.

Syntax

Following is the syntax of return statement in python –

def some_function(parameters): print(some_function) Example

Following is the simple example of return statement –

def welcome(str): return str + " from TutorialsPoint" print(welcome("Good morning")) Output

Following is an output of the above code –

Good morning from TutorialsPoint

The return statement is useful in multiple ways and the below sections discuss the different use case of return statement along with examples.

Use of return statement in Python

Functions are core of any programming language as they allow for code modularity thereby reducing program complexity. Functions can display the result within itself, but it makes the program complex, hence it is best to pass the result from all the functions to a common place.

It is in this scenario that the return statement is useful as it terminates the currently executing function and passes control of the program to the statement that invoked the function.

Example

In the below code the sum_fibonacci function is used to calculate the sum of the first 15 terms in the fibonacci series. After calculating the sum, it prints and returns the sum to the sum_result variable. This is to show that printing inside the function and returning the value give the same output.

# Defining function to calculate sum of Fibonacci series def sum_fibonacci(terms): first_term = 0 second_term = 1 sum_series = 0 # Finding the sum of first 15 terms of Fibonacci series for i in range(0, terms): sum_series = sum_series + first_term next_term = first_term + second_term first_term = second_term second_term = next_term # Printing the sum inside the function print("Sum of Fibonacci series inside the function is = {}".format(sum_series)) # Returning the sum using return statement return sum_series # Invoking the sum_fibonacci function sum_result = sum_fibonacci(15) print("Sum of Fibonacci series outside the function is = {}".format(sum_result)) Output

The output shows that the sum from inside the function using print statement and the sum from outside the function using return statement is equal.

Sum of Fibonacci series inside the function is = 986 Sum of Fibonacci series outside the function is = 986 Returning a function using return statement

In python, functions are first class objects which means that they can be stored in a variable or can be passed as an argument to another function. Since functions are objects, return statement can be used to return a function as a value from another function. Functions that return a function or take a function as an argument are called higher-order functions.

Example

In this example, finding_sum function contains another function – add inside it. The finding_sum function is called first and receives the first number as the parameter. The add function receives the second number as parameter and returns the sum of the two numbers to finding_sum function. The finding_sum function then returns the add function as a value to sum variable.

# Defining function to return sum of two numbers # Function to get the first number def finding_sum(num1): # Function to get the second number def add(num2): return num1 + num2 # return sum of numbers to add function return add # return value present in add function to finding_sum function sum = finding_sum(5) print("The sum of the two numbers is: {}".format(sum(10))) Output

The output of the program gives the sum of the two numbers – 5 and 10.

The sum of the two numbers is: 15 Returning None using return statement

Functions in python always return a value, even if the return statement is not written explicitly. Hence, python does not have procedures, which in other programming languages are functions without a return statement. If a return statement does not return a result or is omitted from a function, then python will implicitly return default value of None.

Explicit calling of return None should only be considered if the program contains multiple return statement to let other programmers know the termination point of the function.

Example

The program below gives a perfect illustration of using return None. In this program the check_prime() function is used to check if a list contains any prime numbers. If the list contains prime numbers, then all the prime numbers present in the list are printed. However, if there are no prime numbers in the list then None is returned, since this program contains multiple return statements, hence None is called explicitly.

def check_prime(list): prime_list = [] for i in list: counter = 0 for j in range(1, i): if i % j == 0: counter = counter + 1 if counter == 1: prime_list.append(i) if len(prime_list): return prime_list else: return None list = [4, 6, 8, 10, 12] print("The prime numbers in the list are: {}".format(check_prime(list))) Output

The output prints None since there are no prime numbers in the list.

The prime numbers in the list are: [4] Returning multiple values using return statement

The return statement in python can also be used to return multiple values from a single function using a ‘,’ to separate the values. This feature can be especially useful when multiple calculations need to be performed on the same dataset without changing the original dataset. The result from the return statement is a tuple of the values.

Example

In this example the built-in functions of the statistics library are used to compute the mean, median and mode which are returned using a single return statement showing how multiple values can be returned from a function.

import statistics as stat # Defining function to perform different statistical calculations def finding_stats(data): return stat.mean(data), stat.median(data), stat.mode(data) # returning multiple values list_numbers = [5, 7, 13, 17, 17, 19, 33, 47, 83, 89] print("The mean, median and mode of the data is: {}".format(finding_stats(list_numbers))) Output

The output gives the mean, median and mode of the dataset with type as tuple.

The mean, median and mode of the data is: (33, 18.0, 17)

Oracle Expected To Match Earnings Projections

Software giant Oracle, now a hardware company as well thanks to its purchase of Sun Microsystems, reports earnings on Thursday after the close of trading, and at least one analyst believes there will be no major surprises.

That’s good or not so good, depending on your perspective. It could be argued that Oracle’s (NASDAQ: ORCL) only significant competitor on a soup-to-nuts, hardware and software basis is IBM (NYSE: IBM). On the other hand, Oracle isn’t in a high-growth industry. Much of its growth has come from acquisitions in recent years, and there aren’t that many big targets left for it any more.

There’s also the added pressure on Oracle’s margins from Sun. As Broadpoint.AmTech analyst Yun Kim noted in a research note on the company earlier this month, Oracle currently enjoys the highest operating margin in the industry and is a relentless cost cutter.

Sun, however, is a hardware company, and hardware is not known for being a high margin business (with Apple a notable exception) and could cause “Oracle’s overall margin profile to decline substantially and it may be weighed down for some time while the company digests the acquisition,” Kim wrote.

Still, Kim expects Oracle to meet estimates with revenue for the third fiscal quarter ended February 26 of $6.41 billion, a 9 percent improvement over the second fiscal quarter and a 17 percent improvement over the same quarter last year. Oracle should report net income of $1.9 billion, or $0.37 per share.

Agreeing with Kim, a consensus survey by Thomson Reuters estimates Oracle will report earnings of $6.35 billion and EPS of $0.38.

One potential area of softness might be the benefit for currency. Recent strength in the U.S. dollar versus the Euro could likely lead to much less than the 7 to 8 percent currency benefit Oracle had forecasted for the quarter. But Kim added he does not expect weaker-than-expected currency to have any significant impact on its non-GAAP EPS.

“We believe its core database business remains solid, although certain local regions and certain verticals faced a more challenging sales environment than expected. Within its database business, ORCL’s middleware business put together yet another strong performance. We believe its application business is likely to remain lackluster,” Kim wrote in his note.

All things considered, he does not project any significant changes to projections as a result. Sun, he wrote, will not be a distraction for now. “We believe that investors are likely to focus on Oracle’s core business in the near-term and not put too much emphasis on Sun’s business as long as it continues to reaffirm its FY11 financial targets, which includes contribution from Sun,” he wrote.

Sun is expected to provide around $635 million, $1 million off from an earlier projection by UBS, and it will provide around $1.22 billion in product and services revenue next quarter, according to Kim.

The fourth fiscal quarter ending in May is traditionally Oracle’s busiest for the year. Kim projects Oracle will report revenue of $9.61 billion and non-GAAP income of $2.71 billion, or $0.58 per share.

Andy Patrizio is a senior editor at chúng tôi the news service of chúng tôi the network for technology professionals.

Top 5 Types Of Oracle Constraints

Introduction to Oracle Constraints

Oracle Constraints clause provides data integrity to the data that is being used by the application from the database by applying certain rules or conditions on a column of a database table which will define a very basic behavioral layer on the column of that particular table to check the sanctity of the data flowing into it like NOT NULL constraint on the column will not allow any data of that column to be NULL as it will not allow users to insert NULL data into the column.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Types of Oracle Constraints

Oracle has multiple types of constraints for multiple purposes. In this section, we are going to go through the different types of constraints in Oracle.

1. NOT NULL

If we just add a column, by default the column is allowed to hold NULL values but in case there is a requirement that the column should not hold any NULL values. We can use NOT NULL constraint on that particular column. This will enforce the column to always have a value and it will not allow any NULL record to be added in the column. We will add NOT NULL constraint using both CREATE TABLE and ALTER TABLE constraint. We will create a table STUDENT with student_id, LastName and zfirstName columns having NOT NULL constraint.

Let us look at the query.

Query:

);

Let us now the query in SQL Developer and look at the result.

As you can see from the above screenshot we have successfully created the table with NOT NULL constraints. Let us now look at the ALTER statement query to add NOT NULL constraint to the age column of STUDENT TABLE.

Query:

desc STUDENT;

Let us now run the query in the SQL developer.

Output:

As we can see from the output the column AGE has now NOT NULL constraint added to it.

2. UNIQUE

This constraint in Oracle ensures that all the values of the column are different from each other and there are no duplicates. We will again use two examples to understand. First using the CREATE statement and then using ALTER statement. We will create a table STUDENT with student_id having UNIQUE constraint.

Let us look at the query using the CREATE TABLE statement.

Query:

);

Let us now run the above query in SQL developer.

Output:

As we can see UNIQUE constraint has been added to the columns of the table. Now let add a UNIQUE constraint to age column using ALTER TABLE statement.

Query:

ALTER TABLE STUDENT ADD UNIQUE(age);

Let us run this query in SQL developer.

Output:

As we can see the table student has been successfully altered.

3. PRIMARY KEY

Primary key constraint uniquely describes each value of a column. No duplicates or NULL value is allowed. One important point is that a table can have only one primary key which in itself can be a combination of single or multiple fields.

We will first create a table ‘student’ with student_id as the primary key using the CREATE TABLE statement.

Query:

);

Output:

As we can see the Table STUDENT has been successfully created. Let us now add primary Key using the ALTER TABLE statement to student_id column after the STUDENT table has been created.

Query:

ADD PRIMARY KEY (student_id);

Let us now run the query in SQL developer and check the result.

Output:

As we can see the table STUDENT has been successfully altered.

4. FOREIGN KEY Constraints

A foreign key is a field which refers to the PRIMARY KEY of another table and the table which actually has the foreign key is called child table. Let us now create a table order which we has student_id column as a foreign key refrencing student_id column of student table using CREATE TABLE statement.

Query:

);

Let us now run the query in SQL developer and look at the result.

Output:

As we can see the orders table has been successfully created. Now we will use the ALTER TABLE statement to add a foreign key to the student_id column of orders table.

Query:

Let us run the query in SQL developer and look at the result.

Output:

As we can see the table orders has been successfully altered.

5. CHECK Constraint

The CHECK constraint is used to limit the value of the range that can be placed in a column. In case we want to restrict certain values in a column or a table we introduce the check constraint. We will introduce the CHECK constraint using both CREATE TABLE and ALTER TABLE statement.

We are going to create a table student with age column having a check constraint.

Query:

);

Let us run the query in SQL developer and look at the result.

Output:

As we can see the table has been successfully created with the CHECK constraint. Let us now add CHECK constraint on the same column after the table student has been created using ALTER TABLE statement.

Query:

Let us now run the query in SQL developer and see the result.

Output:

As we can see the CHECK constraint has been added to the table.

Recommended Articles

This is a guide to Oracle Constraints. Here we discuss the definition of Constraints in Oracle database. We also discussed the various types that can be used in Oracle database along with examples. You can also go through our suggested articles to learn more –

Update the detailed information about Oracle Pl/Sql If Then Else Statement: Elsif, Nested on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!