2024-10-17 09:56:58
--目标表名、字段自己去修改
DECLARE
V_SQL VARCHAR2(500);
BEGIN
FOR C IN (SELECT TABLE_NAME, COLUMN_NAME
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = 'TP_WARNING_INFO'
ORDER BY COLUMN_ID) LOOP
V_SQL := 'INSERT INTO 目标表名(字段名,字段分组内容,内容的出现次数) SELECT ''' ||
C.COLUMN_NAME || ''' AS COLUMN_NAME,' || C.COLUMN_NAME ||
',COUNT(*) FROM ' || C.TABLE_NAME || ' GROUP BY ' ||
C.COLUMN_NAME;
--DBMS_OUTPUT.PUT_LINE(V_SQL);
EXECUTE IMMEDIATE VC_SQL;
COMMIT;
END LOOP;
END;
我这边就把拼接的sql打印出来了,应该是需要你要的效果把,有问题追问