IT运维笔记


oracle自定义函数查询分表

create or replace function c_tjs(v_myid in VARCHAR,v_riqi in VARCHAR)
return number
as
      v_tname varchar2(17);
      v_pname varchar2(21);
      v_sql varchar2(300);
      v_num number;
begin
     v_tname:='T_TEST_'||substr(v_riqi,3,4);
     v_pname:='P_TEST_'||v_riqi;
     v_sql:='select count(*)  from '||v_tname||' partition('||v_pname||') where ismgid='||v_myid;
     EXECUTE IMMEDIATE v_sql into v_num;
     return(v_num);
end;