1. pl/sql 对sql进行的扩展,面向过程
declare 说明部分 变量 常量 必然定义数据类型 变来那个赋值:=
特色的变量类型 引用行变量 table.clounm%type 应用某表的某个字段的类型
penamer emp.ename%
begin
select ename into penamer from ...
end
记录行变量:代表表中的类型
记录型的变量
emp_rec emp%rowtype
begin
select * into emp_rec penamer from ...
end
if语句
if条件 then 语句1;语句2
end if;
if条件 then 语句1;
else if
else
end if;
循环
WHILE LOOP
END LOOP
loop循环
loop
..
exit when ...
end loop
for循环
for i in 1..3 loop
end loop
光标来代表集合
CURSOR 光标名【参数名 数据累in个】
CURSOR c1 is select ename from emp
光标的属性 %found %notfound %isopen %rowcount 影响的行数不是总行数
光标的限制 默认情况下orecal默认一个回话之允许打开300个连接限制的
打开光标
open c1
close c1
fetch c1 into pename
fetch 的作用 把当前指针指向记录的返回
将指针指向下一条语句
declare
cursor cemp is select is select ename from emp;
pename ..
psal
open
loop
fetch cemp into pename ,psal;
exit when cemp%notfound
end loop
对于oracle 默认的事务隔离级别是 read connied
对于orcale执行效率最高的就是plsql,所以少些java代码
修改光标小志 alter system set open_cursors= 400 scope =both
带参数的光标
cursor cemp(dno numbern) is select ...
open cemp(10);
例外 增强程序的健壮性
例外 No_data_found
begin
select ename from into .. from ..
exception no_data_found then ...
when othres then ...
end
例外 too_many_rows
例外 zero_divide
例外 value erroy
例外 自定义例外 exception 在declare中声明某变量 no_enm_found
if xxx%notfound then
raise no_enm_found;
orcela 会自动启动pmon 发现异常会自动关闭,进程监视器,清理垃圾和资源