比如,我知道某张表有50条记录,但是不知道表名,要怎么查询?user_tables里能找到这张有50条记录的表名吗?

解决方案 »

  1.   

    可以,但是结果不一定唯一吧 如果还有其他表中也有50条记录呢?你可以定义一个游标 select * from dba_tables 把所有的表查出来
    然后遍历 针对每一个表进行select count(*) into num
    如果结果是50就取出来
    不过如果有多个表的话 就看你怎么取舍了
      

  2.   

    多个表无所谓,一个库中记录数相同的表应该不会太多,数都数的过来。
    求高手SQL代码。
      

  3.   

    declare
      v_num       integer := 0;
      v_tableName varchar2(50);
      v_sql       varchar2(500);
      cursor allcursor is
        select d.table_name
          from dba_tables d
         where d.owner = 'MW_APP'
           and d.tablespace_name = 'USERS';
    begin
      open allcursor;
      loop
        fetch allcursor
          into v_tableName;
        exit when allcursor%notfound;
        v_sql := 'select count(*) from ' || v_tableName;
        dbms_output.put_line(v_sql);
        execute immediate v_sql
          into v_num;
        if (v_num < 50) then
          dbms_output.put_line(v_tableName);
        end if;
      end loop;
      close allcursor;
    end;
    自己先看看吧
      

  4.   


    多谢了,不过能不能不用游标啊,这个挺麻烦的。我看他们查找记录超过10000万行的表名,只要几条select语句就行了。
      

  5.   

    select owner, tablespace_name, table_name
      from all_tables
     where num_rows = 50