First, give a smallProgram:
1 Set Serveroutput On
2 Declare
3 Maxrecords constant Int : = 100 ;
4 I Int : = 1 ;
5 Begin
6 For I In 1 .. Maxrecords Loop
7 Insert Into Testtable (recordnumber, currentdate)
8 Values (I, sysdate)
9 End Loop;
10 Dbmps_output.put_line ( ' Successfully entered data ' );
11 Commit ;
12 End ;
1: Allow Server output
2. Define partial identifiers
3: Define maxrecords as an integer constant of 100
4: Define I as an integer variable and the initial value is 1;
5: execution part ID
6: I cycle from 1 to maxrecords
7, 8: insert data into the database
9: End Loop
10: the prompt message indicating successful input is displayed.
11: Submit results
12: end execution
======================================
Note: sysdate is the system time; dbmps_output.put_line is the method defined in the package, and the function is to output information; all changes to database data in Oracle are not directly operated on the database, instead, it is stored in the memory called the workspace. It is permanently changed only after the commit statement is executed.
The above content involves the main program structure of PL/SQL
Definition part: decare execution part begin .. end;
Exception Handling
Declare
Define statement segments
Begin
Execution statement segment
Exception
Exception Handling statement segment
End;
==================================