首先给出一段小程序:
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( ' 成功录入数据 ' );
11 commit ;
12 end ;
1:允许服务器输出
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( ' 成功录入数据 ' );
11 commit ;
12 end ;
2.定义部分标识
3:定义maxrecords为整型常量100
4:定义i为整型变量,初始值为1;
5:执行部分标识
6:i从1循环到maxrecords
7,8:向数据库里插入数据
9:结束循环
10:显示成功录入提示信息
11:提交结果
12:结束执行
============================
注明:sysdate是系统时间;dbmps_output.put_line为包中定义的方法,功能是输出信息;在oracle中所有对数据库数据的更改并没有直接操作数据库,而是放在叫工作区的内存中,只有在commit语句执行后,才发生永久更改.
上面的内容涉及到了pl/sql的主要程序结构
定义部分:decare 执行部分begin..end;
另外还有异常处理部分
declare
定义语句段
begin
执行语句段
exception
异常处理语句段
end;
=============================