informix存储过程的调试

  
存储过程的调试通常采用两种方法。
1. 设置 debug file , trace 方式。
2. return   …… with resume 方式调试。
例: 1
create procedure getday(t_day date,t_int int ,t_flag char(10)) returning date;
define i int;
define tt_day date;
   DEFINE ESQL,EISAM          INT;
   DEFINE ETEXT               CHAR(80);
   Set debug file to “sun.tmp”;
    let tt_day="18991231";
    let i=0;
   if t_flag="year" then
        while 1=1
            on exception in(-1267)
               let i=i+1;
            end exception ;
            let tt_day=t_day-i;
            let tt_day=tt_day+t_int units year;
            trace tt_day;
            exit while;
         end while;
    elif t_flag="month" then
         while 1=1
            on exception in(-1267)
              let i=i+1;
            end exception ;
            let tt_day=t_day-i;
            let tt_day=tt_day+t_int units month;
            trace tt_day;
            exit while;
         end while;
    elif t_flag="day" then
          let tt_day=t_day+t_int units day;
     else
          let tt_day=t_day;
     end if;
     return tt_day;
end procedure;
 
 
例: 2
create procedure getday(t_day date,t_int int ,t_flag char(10)) returning date;
define i int;
define tt_day date;
   DEFINE ESQL,EISAM          INT;
   DEFINE ETEXT               CHAR(80);
   let tt_day="18991231";
                let i=0;
   if t_flag="year" then
          while 1=1
                on exception in(-1267)
                   let i=i+1;
                end exception ;
                 let tt_day=t_day-i;
                 let tt_day=tt_day+t_int units year;
                       return tt_day with resume;
                 exit while;
           end while;
        elif t_flag="month" then
                while 1=1
                on exception in(-1267)
                   let i=i+1;
                end exception ;
                       let tt_day=t_day-i;
                        let tt_day=tt_day+t_int units month;
                        return tt_day with resume;
                         exit while;
                end while;
        elif t_flag="day" then
                let tt_day=t_day+t_int units day;
        else
                let tt_day=t_day;
        end if;
        return tt_day;
end procedure;
其中重点提下跟踪调试语句trace
 
存储过程被正确创建后,说明无语法错误,但有可能有逻辑错误
TRACE
语句用于调试存储过程,  它可以跟踪以下存储过程实体的值:
变量( Variables)
过程参数 (Procedure arguments)
返回值 (Return values)
SQL 
错误代码( SQL error codes)
ISAM 
错误代码 (ISAM error codes)
TRACE 
语句把跟踪结果写到一个文件中,  该文件由 SQL 语句 SET DEBUG FILE 指定

 
TRACE  语句的三种形式:
TRACE ON 
:打开跟踪调试,  跟踪所有语句
TRACE OFF 
:关闭跟踪调试
TRACE PROCEDURE
  对于过程调用,  不跟踪过程体,仅跟踪过程的输入和返回值。

create procedure tracepro(var_user_num int)
 define var_user_date date;
 set debug file to "/export/home/user/trace";
--
设置输出文件
 trace on;
--
跟踪所有执行的语句
 select user_date into var_user_date
  from users
  where user_num = var_user_num;
 if var_user_date is null then
  trace "user date is null";
--
执行到这里输出 user date is null
  execute procedure other((var_user_num );
 end if;
 trace off;
--
关闭跟踪
end procedure;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值