Loading...

데이터베이스

oracle 1 / 1 페이지
1. sqlplus 의 spool 을 이용한 방법Set heading offSet feedback offSet pagesize 0Set termout offSet trimout onSet trimspool onSet recsep offSet linesize 100Column d noprint new_value date_Column u noprint new_value user_Spool tmpSelect 'Select '''||table_name||' , ''||count(*) from '||table_name||';', to_char(sysdate, 'YYYYMMDDHH24MISS') d, user ufrom user_tablesorder by table_name/Spool offSpool count_&user_._&[email protected] off위의 내용을 rowcount.sql 이라는 텍스트 파일로 저장하고 sqlplus 에 접속해서 이 파일을 @rowcount.sql 로 실행합니다.그러면, sqlplus 를 실행시켰던 폴더 위치에 count_<user name>_<system_date>.LST 라는 파일이 생성되어 있습니다.2. stored procedure 에서 for loop 문을 이용set serveroutput ondeclare v_cnt number;begin for v_rec in (select table_name from all_tables a where owner='XXX') loop execute immediate 'select count(*) from XXX.' || v_rec.table_name into v_cnt; dbms_output.put_line('Table XXX.' || v_rec.table_name || ' has ' || v_cnt || ' row(s).'); end loop;end;위에서 XXX 를 원하는 owner 로 바꿔서 실행합니다.원하는 결과 포맷이 다르면 put_line 에서 원하는 출력 포맷으로 변경하면 되겠죠.3. xmltable 을 이용// 아래는 PLS-00201: identifier 'SYS.DBMS_XQUERYINT' must be declared// 에러를 발생하고 실행 안됩니다.SQL> select table_name, column_value cnt from user_tables, xmltable (('count(ora:view("'||table_name||'"))'))4.xmlgen.getxml 을 이용//아래는 실행은 되지만,/ROWSET/ROW/C 의 의미를 몰라서찜찜... SELECT table_name , to_number( extractvalue ( xmltype ( dbms_xmlgen.getxml ('select count(* ) c from '||table_name)),'/ROWSET/ROW/C')) No_of_recs FROM user_tables ORDER by 1;5. num_rows 와 user_tables 을 이용select table_name,sum(num_rows) from user_tables group by table_name order by table_name6. dba_tables 을 조회하는 방법// 아래의 방법은 실행 이전에 dba_tables 을 업뎃해줘야 하는 불편이 있다.// 즉,// exec dbms_stats.gather_schema_stats(ownname=> 'NAME');// 을 실행하고 아래의 select 를 실행해야 최신(?) 값을 얻는다.SELECT table_name, num_rows FROM dba_tablesWHERE TABLE_NAME='NAME'To update the latest row count value in the DBA_TABLES view execute.
840 조회
2025.09.10 등록
홈으로 전체메뉴
전체 검색
회원가입