代码之家  ›  专栏  ›  技术社区  ›  Rashack

检查Oracle中表中的所有列

  •  0
  • Rashack  · 技术社区  · 15 年前

    这是个棘手的问题,很可能是语法问题。但是我有点迷路了。。。

    以下是我目前掌握的情况:

    DECLARE
       cursor tableNames is
          select table_name
          from user_tables
          where table_name not like '%_A';
        lSql varchar2(3000);
        type t_columnRow is ref cursor;
    
        v_columns t_columnRow;
    begin
    
    FOR tableName in tableNames
    LOOP
        open v_columns for select COLUMN_NAME from user_tab_columns where table_name = tableName;
    
        for columnRow in v_columns LOOP
            DBMS_OUTPUT.PUT_LINE(tableName || '.' || columnRow.COLUMN_NAME);
            -- Here I would just concatenate the strings ....
        END LOOP;
    
    END LOOP;    
    
    End;
    

    Error at line 1
    ORA-06550: line 14, column 84:
    PLS-00382: expression is of wrong type
    ORA-06550: line 16, column 22:
    PLS-00221: 'V_COLUMNS' is not a procedure or is undefined
    ORA-06550: line 16, column 5:
    PL/SQL: Statement ignored
    
    2 回复  |  直到 13 年前
        1
  •  2
  •   Christian13467    15 年前

    试试这个:

    BEGIN
        FOR t IN (SELECT table_name FROM user_tables WHERE table_name not like '%_A')
        LOOP
            FOR c IN (SELECT column_name FROM user_tab_columns WHERE table_name = t.table_name)
            LOOP
                DBMS_OUTPUT.PUT_LINE(t.table_name||'.'||c.column_name);
                -- Here I would just concatenate the strings ....
            END LOOP;
        END LOOP;
    END;
    
        2
  •  1
  •   Adam Paynter    15 年前

    你也许可以做一些简单的事情:

    DECLARE
       cursor tableNames is
          select table_name
          from user_tables
          where table_name not like '%_A';
        lSql varchar2(3000);
    begin
    
    FOR tableName in tableNames
    LOOP   
        for columnRow in (select COLUMN_NAME from user_tab_columns where table_name = tableName) LOOP
            DBMS_OUTPUT.PUT_LINE(tableName || '.' || columnRow.COLUMN_NAME);
            -- Here I would just concatenate the strings ....
        END LOOP;
    
    END LOOP;    
    
    End;