Oracle Control statements

Source: Internet
Author: User

PL OUTPUT Statement

Set serverout on; --turn on the output statement function of PL
Declare

n Number:=1; --Declares a variable n of type number and assigns a value of 1
V varchar2: = ' world '; --Declare a variable V of type VARCHAR2 "World"
Begin--The control statement is written between Begin-end
Dbms_output.put_line (' Hello ' | | n| | V); --Output statement, data connection using ' | | '
End

If condition statement
Set serverout on;
declare emp_count number;
Begin
Select COUNT (*) into Emp_count from EMP where sal>=3000;
If Emp_count>0 Then
Dbms_output.put_line (' There ' | | emp_count| | ' The basic salary of an employee is greater than or equal to 3000 ');
Else
Dbms_output.put_line (' No employees have a basic salary greater than or equal to 3000 ');
End If;
End

Assignment statements
Set serverout on;
declare emp_count number;
Begin
Select COUNT (*) into Emp_count from EMP where sal>=3000; --Query out data and assign value to Emp_count
If Emp_count=1 Then
Dbms_output.put_line (' 1 employees have a basic salary greater than or equal to 3000 ');
else if Emp_count>1 then
Dbms_output.put_line (' There are more than 1 employees with a basic salary greater than or equal to 3000 ');
Else
Dbms_output.put_line (' No employees have a basic salary greater than or equal to 3000 ');
End If;
End If;
End

Case when Process Control statement

Set serverout on;
declare emp_count number;
Begin
Select COUNT (*) into Emp_count from EMP where sal>=3000;
Case Emp_count
When 0 then Dbms_output.put_line (' No employee's basic salary is greater than or equal to 3000 ');
When 1 then Dbms_output.put_line (' 1 employees have a basic salary greater than or equal to 3000 ');
When 2 then Dbms_output.put_line (' 2 employees have a basic salary greater than or equal to 3000 ');
When 3 then Dbms_output.put_line (' 3 employees have a basic salary greater than or equal to 3000 ');
else Dbms_output.put_line (' basic pay of more than 3 employees is greater than or equal to 3000 ');
End case;
End

Unconditional loop Loops

Set serverout on;
DECLARE g_id number:=2;
G_losal number;
G_hisal number;
Begin
Loop
if (g_id>4) then
Exit
End If;

Select Losal,hisal into G_losal,g_hisal from Salgrade where grade=g_id;
Dbms_output.put_line (g_id | | ' Lowest salary of grade ' | | G_losal | | ', the most well-paid: ' | | G_hisal);

g_id:=g_id+1;

End Loop;
End

While loop
Set serverout on;
DECLARE g_id number:=2;
G_losal number;
G_hisal number;
Begin

While G_id<5 loop

Select Losal,hisal into G_losal,g_hisal from Salgrade where grade=g_id;
Dbms_output.put_line (g_id | | ' Lowest salary of grade ' | | G_losal | | ', the most well-paid: ' | | G_hisal);
g_id:=g_id+1;
End Loop;

End

For loop
Set serverout on;
declare g_losal number;
G_hisal number;
Begin
For g_id in 2..4 loop
Select Losal,hisal into G_losal,g_hisal from Salgrade where grade=g_id;
Dbms_output.put_line (g_id | | ' Lowest salary of grade ' | | G_losal | | ', the most well-paid: ' | | G_hisal);
End Loop;
End

Oracle Control statements

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.