zoukankan      html  css  js  c++  java
  • oracle pl/sql 中的动态函数

    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;

  • 相关阅读:
    活脑筋的相信机会!
    亿万富翁巴菲特的理财习惯大揭秘
    让你的创业失败的18个昏招 都归结到这里
    创业成功的基础:时间管理
    三个故事的启发
    张瑞敏:借来的火点不亮自己的心灵
    李嘉诚谈管理艺术:想当老板还是领袖
    高燃:“80后人精儿”是这样炼成的
    比尔盖茨的11条人生箴言(英汉对照)
    笔者认为,中国的互联网行业需要真正的CEO
  • 原文地址:https://www.cnblogs.com/BradMiller/p/1743965.html
Copyright © 2011-2022 走看看