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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值