Instance 1--IF statement
/* Web Oracle Database development must be pl/sql_2-3
Determine the number the user has entered from the keyboard
1. How to use the IF statement
2. Receive input from a keyboard (string) */
Set serveroutput on;
--Receive a keyboard input
--num: Address value, meaning: The value entered is saved on the address
Accept num Prompt ' Please enter a number ';
Declare--Define variable to save the number of keyboard input
Pnum Number: = #
Begin-Executing an IF statement for conditional judgment
If Pnum=0 then Dbms_output.put_line (' you enter the number is: 0 ');
elsif Pnum=1 then Dbms_output.put_line (' you enter the number is: 1 ');
elsif pnum=2 then Dbms_output.put_line (' you enter the number is: 2 ');
else Dbms_output.put_line (' You enter the number: other number ');
End If;
End
/
Instance 2--while statement
/*
The necessary pl/sql_2-4 of Oracle database development in MU-class network
While loop statement prints the number 1-10
*/
Set Serveroutput on
Declare
Pnum number: = 1;
Begin
While pnum<=10 loop
Dbms_output.put_line (Pnum);
Pnum: = Pnum +1;
End Loop;
End
/
Instance 3--loop statement
/* Web Oracle Database development must be pl/sql_2-4
Loop Loop Statement Prints the number 1-10 */
Set Serveroutput on
DECLARE pnum number: = 1;
Begin Loop Exit when pnum>10;
Dbms_output.put_line (Pnum);
Pnum: = Pnum +1;
End Loop;
End
/
Instance 3--for statement
/* Web Oracle Database development must be pl/sql_2-4
For Loop statement to print the number 1-10
For loop format:
For I in 1..9 loop
End Loop; */
Set Serveroutput on
DECLARE pnum number: = 1;
Begin for Pnum in 1..10 loop
Dbms_output.put_line (Pnum);
End Loop;
End
/
-PL/SQL Foundation of Oracle Development Tool for MU lesson network note