create or replace function GET_COUNT_ZS(deptcode in varchar2, tablename in varchar2,bs in varchar2)return varchar2is num varchar2(1000);c number;beginif(bs=0) then num:='select count(*) from '||tablename||' where deptcode like '''||deptcode||'%''';end if;if(bs=1) thennum:='select count(*) from '||tablename||' where deptcode like '''||deptcode||'%'''||' and SFDTGL=1' ;end if;execute immediate num into c;return c;end;
Second:
create or replace function GET_COU_SYQK(deptcode in varchar2, SYZT in varchar2)return varchar2isnum varchar2(1000);c number;beginnum:='select count(*) from t_fwcq where deptcode like '''||deptcode||'%'' and sszthz = '''||SYZT||'''';execute immediate num into c;return c;end;
The called SQL statement:
VaR STB = new stringbuilder (); Stb. append ("select"); Stb. append ("get_count_zs ('" + deptcode + "','t _ fwzc ', 0) as countzc"); Stb. append (", get_count_zs ('" + deptcode + "','t _ fwcq ', 0) as countfw"); Stb. append (", get_count_zs ('" + deptcode + "', 'zc _ DT ', 0) as countdt"); Stb. append (", get_count_zs ('" + deptcode + "','t _ fwzc ', 1) as countygl"); Stb. append (", get_cou_syqk ('" + deptcode + "', '') as countzy"); Stb. append (", get_cou_syqk ('" + deptcode + "', 'id') as countxz"); Stb. append (", get_cou_syqk ('" + deptcode + "', 'lease ') as countcz"); Stb. append (", get_cou_syqk ('" + deptcode + "', 'occupies ') as countzhany"); Stb. append (", get_cou_syqk ('" + deptcode + "', 'sold ') as countcs"); Stb. append (", get_cou_syqk ('" + deptcode + "', 'disc deficient ') as countpk"); Stb. append (", get_cou_syqk ('" + deptcode + "', 'archive ') as countfc"); Stb. append (", get_cou_syqk ('" + deptcode + "', 'others') as countyqt"); Stb. append ("from dual ");