oracle—pl/sql

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 发现异常会自动关闭,进程监视器,清理垃圾和资源

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值