`

实战oracle存储过程for循环if判断的使用(含源码)

阅读更多

代码为一个小实例介绍oracle存储过程的for循环的使用和if的使用,在存储过程中拼接JSON还回给调用者

 

create or replace procedure p_yourname(
  p_xxa       in      varchar2,    --参数一为输入参数
  p_xx b      in      varchar2,    --参数二为输入参数
  p_xxc       inout   varchar2,    --参数三为输入输出参数
  p_result    out     varchar2     --参数四为输出参数
) 
/***********
Tom.Cai 2013-07-23
功能XXX
************/
is
  t_temp varchar2(10);
  v_num tablename%ROWTYPE; --表名称加上%ROWTYPE
  v_code number  :=0;
begin
   -- do something yourself
   t_temp :='{'||'jsonname'||
   for v_num in ( select aa,bb from table where faa = p_xxa) 
     loop
         t_temp := t_temp ||'['||aa||':'|| v_num .aa||','||aa||':'||v_num .bb||']'; --拼接
           exit; --退出循环
       end if;
   end loop;
   t_temp:=t_temp ||'}';
   if(t_temp.length>20) then  --此处判断仅为demo,没有实际意义
     p_result := t_temp;
   else
     return;
   end if;
exception
  when others then
    --do something 
end p_route;



 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics