查询以查找表中没有值的所有列

时间:2017-10-31 09:30:03

标签: oracle plsql

我已经编写了这个查询,用于查找表中没有值但不起作用的列总数。

SET serveroutput ON;
        DECLARE
          v_count      NUMBER;
          v_table_name VARCHAR2(200);
          CURSOR c2
          IS
            SELECT Column_name FROM all_tab_columns WHERE table_name= A;
        BEGIN
          FOR r1 IN c2
          LOOP
            dbms_output.put_line(r1.column_name);
            EXECUTE immediate('SELECT COUNT(r1.column_name) INTO v_count FROM HR'||'.'||A);
            IF v_count =0 THEN
              dbms_output.put_line(v_count);
            END IF;
          END LOOP;
END;

1 个答案:

答案 0 :(得分:0)

我希望您尝试使用此代码。它对我有用:)

SET serveroutput ON;
 DECLARE
  myOwner VARCHAR2(20):='HR';
  myTable VARCHAR2(25):='A';
  CURSOR c2
  IS
    SELECT column_name,
      avg_col_len
    FROM all_tab_columns
    WHERE table_name = myTable
    AND owner        = myOwner;
BEGIN
  FOR r1 IN c2
  LOOP
    IF r1.AVG_COL_LEN =0 THEN
      dbms_output.put_line('column_name = '||r1.column_name);
    END IF;
  END LOOP;
END;

希望这可以帮到你。