1.删除指定员工记录
create or replace procedure delt(v_id in t.id%type)
as
no_result exception;
begin
delete from t where id=v_id;
if SQL%notfound then
raise no_result;
end if;
dbms_output.put_line('ID:'||v_id||'被删除');
commit;
exception
when no_result then
dbms_output.put_line('删除的数据不存在');
when others then
dbms_output.put_line('发生其它错误');
end delt;
as
no_result exception;
begin
delete from t where id=v_id;
if SQL%notfound then
raise no_result;
end if;
dbms_output.put_line('ID:'||v_id||'被删除');
commit;
exception
when no_result then
dbms_output.put_line('删除的数据不存在');
when others then
dbms_output.put_line('发生其它错误');
end delt;
总结:
1.声明的变量要放在as之后.
执行存储过程
a. 第一种方法
SQL> set serveroutput on
SQL> exec delt(13);
ID:13被删除
SQL> exec delt(13);
ID:13被删除
b.第二种方法
SQL> begin
2 delt(12);
3 end;
4 /
ID:12被删除
2 delt(12);
3 end;
4 /
ID:12被删除
PL/SQL procedure successfully completed.
2.动态sql
存储过程中不能执行ddl语句,如果要执行就要使用动态sql
create or replace procedure drop_table
as
begin
execute immediate 'drop table d';
end;
as
begin
execute immediate 'drop table d';
end;
编译的时候不检查语法,执行时才检查.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26937943/viewspace-765079/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26937943/viewspace-765079/
5434

被折叠的 条评论
为什么被折叠?



