1

我有疑问。我有 1 列user_auto有价值234。我想找出哪个表正在使用此列并具有特定值。

我已经完成了有多少表正在使用该列。

SELECT t.name AS table_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%user_auto%'
ORDER BY  table_name;

现在我想要这张表user_auto = 234改变值。表示 User_auto 的值为 234。想要有关此用户的所有详细信息吗?

4

1 回答 1

0

你想要这样的东西吗?

SQL> desc foo1
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 USER_AUTO                                          NUMBER

SQL> desc foo2
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 USER_AUTO                                          NUMBER

SQL> select * From foo1;

 USER_AUTO
----------
       123
      1234

SQL> select * From foo2;

 USER_AUTO
----------
       234

SQL> set serverout on
SQL> declare
  2    v_val varchar2(3) := '234';
  3    v_cnt pls_integer;
  4  begin
  5    for r_tab in (select table_name, column_name
  6                    from all_tab_columns
  7                   where column_name = 'USER_AUTO'
  8                   order by 1)
  9    loop
 10      dbms_output.put_line('Found table ' || r_tab.table_name || ' with column '||r_tab.column_name);
 11      execute immediate 'begin select count(*) into :b0 from '
 12                        || r_tab.table_name
 13                        || ' where rownum = 1 and ' || r_tab.column_name || ' = :b1;'
 14                        || 'end;' using out v_cnt, v_val;
 15      if (v_cnt = 1)
 16      then
 17        dbms_output.put_line(chr(9)||'row found for ' || v_val);
 18      else
 19        dbms_output.put_line(chr(9)||'no row found for ' || v_val);
 20      end if;
 21    end loop;
 22  end;
 23  /
Found table FOO1 with column USER_AUTO
        no row found for 234
Found table FOO2 with column USER_AUTO
        row found for 234

PL/SQL procedure successfully completed.
于 2012-11-14T00:03:02.283 回答