子程序与触发器

目标:

  1.掌握存储过程

  2.掌握自定义函数

  3.了解程序包相关概念、用途

  4.掌握触发器相关概念、用法

1.掌握存储过程

     子程序:子程序是命名的PL/SQL块,编译并存储在数据库中。分为过程(执行某些操作)、函数(操作并返回值)

 存储过程用例:

create or replace procedure 
pro_add_teacher(p_tname varchar2,p_tid teacher.tid%type,p_gender char,p_birthday date,p_sal teacher.sal%type)
as
e_tid_validate exception;
begin
   if length(trim(p_tid))!=18 then
     raise e_tid_validate;
   end if;
    insert into teacher(tno,tname,tid,gender,birthdate,sal)
    values(sq_teacher.nextval,p_tname,p_tid,p_gender,p_birthday,p_sal);
    commit;
 exception
    when e_tid_validate then
      dbms_output.put_line('身份证号码错误');
    when others then
      dbms_output.put_line('内部错误');
      rollback;
end pro_add_teacher;

PL/SQL执行时会有个隐性游标就叫SQL,rows:=SQL%Rowcount;可以返回影响的条数。

 

posted @ 2017-09-20 20:47  建宁小骄傲  阅读(163)  评论(0编辑  收藏  举报