Oracle:PL*Plus编程(三)

来源:互联网 发布:如何清洗内衣知乎 编辑:程序博客网 时间:2024/06/05 04:53

异常

一.常用异常

异常名称 错误代码 描述 ACCESS_INTO_NULL ORA-06530 试图对未初始化对象属性赋值。 CASE_NOT_FOUNT ORA-06592 未在case语句中找到匹配的when子句,也没有默认的else子句 INVALID_CURSOR ORA-01001 程序试图进行非法游标操作 INVALID_NUMBER ORA-01722 试图将字符串转换成数字时失败,因为字符串并不代表有效的数字 LOGIN_DENIED ORA-01017 试图用非法的用户名或密码连接数据库 TOO_MANAY_ROWS ORA-01422 select into 语句返回多行 DUP_VAL_ON_INDEX ORA-00001 试图向唯一索引约束的列中插入重复值。

例子:

begin     dbms_output.put_line(1/0);exception     when zero_divide then end;

结果:

Division by zero

OTHERS:可以处理所有异常
例如:

begin     dbms_output.put_line(1/0);exception     when others then dbms_output.put_line('Division by zero');end;

结果:

Division by zero

过程

二.过程

1.创建过程

语法:

CREATE [OR REPLACE] PROCEDURE procedure_name{[parameter_name [IN | OUT | IN OUT] type [, ...]}{IS | AS}BEGINprocedure_bodyEND procedure_name;

例如:

create procedure update_test_type(    test_id in test.id%TYPE,    test_type in varchar(10) ) as    v_count integer;begin    select count(*)    into v_count    from test    where id = test_id;    if v_count = 1 then        update test        set type = test_type        where id = test_id;        commit;    end if;exception    when others then        rollback;end update_test_type;

2.调用过程

call update_test_type(1, '09');

3.获取有关过程的信息

select object_name, aggregate, parallelfrom user_procedureswhere object_name='update_test_type';

4.删除过程

drop procedure update_test_type;

5.查看错误

show errors
原创粉丝点击