日期:2014-05-16  浏览次数:20322 次

oracle创建存储过程常见错误以及调试方法+

create or replace procedure testoutput is
begin
dbms_output.put_line('hello world! this is the first procedure');
end;

/ --编译

?

create or replace procedure a(no1 in number,name1 varchar2,loc varchar2)
is
dept_number number(2) :=no1;
dept_name varchar2(14) :=name1;
dept_loc varchar2(13) :=loc;
begin
?insert into scott.dept values(dept_number,dept_name,dept_loc);
exception
when others then
--dbms_output.put_line('erro');
raise;
end;
/

?

exec A(50,'50','50');

?

oracle 11.1.0.6.0 的SQL Developer工具在执行存储过程是有bug

?

SQL> create or replace procedure jl_test
2 (a in varchar2,b out varchar2)
3 as
4 begin
5 b:= a;
6 end;
7 /
SQL> var c varchar2(10);
SQL> exec jl_test('01',:c)
PL/SQL 过程已成功完成。
SQL> print c
C
--------------------------------
01

  在java中调用存储过程用的是call ps_name

常见错误:

1.从外部文件导入创建存储过程的文件最后缺少/,导致创建过程中暂停住,没有正常编译

2.传入的参数不必指定长度,而在声明区必须指定,并且应注意长度类型的匹配

3.不要在sql developer中运行存储过程,要在命令行中运行

4.在打印前先运行set serveroutput on;

?

create or replace procedure getClientData6(x out varchar2) is
tempresult varchar2(1024);
begin
tempresult := 'start->';
select customers.contactfirstname into tempresult from customers ;--where customers.customernumber='103';
--select hotelid||hotelname into tempresult from hotel where hotelid =10041764;
x:=tempresult;
dbms_output.put_line(x);
end getClientData6;


我的异常网推荐解决方案:oracle存储过程,http://www.aiyiweb.com/oracle-develop/177537.html