Linux でエクスポート前にスキーマの行数を確認する

データベースのエクスポートを開始する前に、スキーマの行数を確認します。確認したスキーマの行数をエクスポート完了後の行数と比較します。
  1. [SQL] > [コマンド プロンプト]で、以下を入力します。
    sqlplus protect/<パスワード>@protect
  2. [接続しました]メッセージを受信した後、[SQL] > [コマンド プロンプト]で以下のコマンドを入力し、行数を生成する PL\SQL 関数を作成します。
    create or replace function
    row_count (p_tablename in varchar2)
    return number
    as
    l_count number;
    begin execute immediate
    'select count(*)
    from ' || p_tablename
    into l_count;
    return l_count;
    end;
    /
  3. 次のクエリーを実行してスキーマの各テーブルの行数を確認します。
    spool rowCount_before_export.txt
    select table_name, row_count(table_name) num_of_rows from user_tables;
    spool off
    rowCount_before_export.txt
    ファイルが実行ディレクトリに生成されます。
  4. 今後使用できるように、
    rowCount_before_export.txt
    ファイルを保存します。