经常需要查询一批类似表中的记录量,通过下面的语句实现:
select 'SELECT COUNT(*) as tabnum,' || '''' || tname || '''' ||
' as tabname FROM ' || TNAME || ' UNION '
from tab
where tname like '%COMPANY%'
ORDER BY TNAME;
执行完效果如下:
SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_180816’ as tabname FROM PUBLIC_COMPANYINFO_180816 UNION SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_201805’ as tabname FROM PUBLIC_COMPANYINFO_201805 UNION SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_201806’ as tabname FROM PUBLIC_COMPANYINFO_201806 UNION SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_201807’ as tabname FROM PUBLIC_COMPANYINFO_201807 UNION SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_201808’ as tabname FROM PUBLIC_COMPANYINFO_201808 UNION SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_201809’ as tabname FROM PUBLIC_COMPANYINFO_201809 UNION SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_201810’ as tabname FROM PUBLIC_COMPANYINFO_201810 UNION SELECT COUNT() as tabnum,‘PUBLIC_COMPANYINFO_201811’ as tabname FROM PUBLIC_COMPANYINFO_201811 UNION SELECT COUNT(*) as tabnum,‘PUBLIC_COMPANYINFO_201812’ as tabname FROM PUBLIC_COMPANYINFO_201812 UNION
把最后一个UNION更换成分号 ; 就可用直接执行,可以清楚看到这些表中的记录数。
|