PL/SQL语言基础(一)
一个pl/sql块最多由4个不同的部分成,只有一个部分是必不可少的
1. 块 :只有命名块才有,也即是有名称的函数,存储过程等块名称
2. 声明部分: 定义变量,游标,引用的子块
3. 执行部分:必不可少的一部分,运行时要执行的语句
4. 异常处理部分: 正常处理过程抛出的异常提示,错误信息
pl/sql 除了命名块还有匿名块 www.2cto.com
匿名块 :没有名字的块,格式如:
declare
…….声明部分
begin
………….执行部分
exception
异常处理
end ; www.2cto.com
简单的匿名块例子:
declare
empname varchar(2oracle账号0);
begin
select ename into empname from scott.emp where rownum <2;
dbms_output.put_line(empname);
exception
when VALUE_ERROR
THEN
dbms_output.put_line(' sql is not right');
end;