oracle pl/sql 中的动态函数

系统 1888 0

1.execute immediate

create or replace function getrealtypeforreport(p_stanid number,p_id number,p_infoname varchar2) return varchar2
is
 v_string                 varchar2(200);
 v_returninfo             varchar2(200);
 v_acttabname             stanactive.acttabname%type;
 v_actpkcol               stanactive.actpkcol%type;
begin
     select acttabname,actpkcol into v_acttabname,v_actpkcol from stanactive where stanid=p_stanid;
   v_string:='select realtype from vw_'||v_acttabname||' where '||v_actpkcol||' = '||p_id;
   execute immediate v_string into v_returninfo;
 return v_returninfo;
end;
/
show err;

2. Open ttdscur for v_sql

create or replace function getfieldstring(p_expectfield varchar2,p_expecttable varchar2,p_expectcause varchar2) return varchar2
is
/*
函数功能:获取单个属性将其拼成一行
参数说明:p_expectfield   查询字段
          p_expecttable   查询主表
          p_expectcause   查询条件
*/
 v_sql    varchar2(4000):='';
 type ttds_cursor is ref cursor;
 ttdscur     ttds_cursor;
 ttdigital    varchar2(4000);
 v_cnt                   number;
 v_return  varchar2(4000):='';
begin
 v_sql:='select '||p_expectfield||' from '||p_expecttable||' where '||p_expectcause;
 v_cnt:=0;
 Open ttdscur for v_sql;
 loop
  fetch ttdscur into ttdigital;
  exit when ttdscur%notfound;
  if v_cnt=0 then
   v_return:=ttdigital;
  else
   v_return:=v_return||','||ttdigital;
  end if;
  v_cnt:=v_cnt+1;
 end loop;
 Close ttdscur;
 return v_return;
end getfieldstring;
/
show err;

举例:

select getfieldstring('certno','rightcert','activeid=@id and certtypeid in (3)') from dual;

 

 

oracle pl/sql 中的动态函数


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论