2017-10-18 10 views
-3

(Oracle)SQLを使用して別々の抽出を200+ 個生成する必要があります。クエリはwhere条件を除いて同一です。私はそのリストをjavaで定義して参照することは許されていません。複数のレポートを1つのSQLステートメントで

SQLのみを使用して、プロセスを自動化する方法はありますか?

これは私が想像することができる流れである:配列が

2.1にその配列の添字のためのSQLを実行し尽くされていないが

  1. は異なる検索条件に
  2. を格納する配列を定義します名前にその検索条件を有するファイル(ファイルの上書きを避けるため)

Thaあなたのselect文とスプールを生成する

SQLスクリプト:NKあなた

+2

MS SQL ServerまたはOracleを使用していますか?関与していない製品にはタグを付けないでください。 – jarlh

+1

これまでに試したことを示してください。純粋なコーディング支援の質問のように見えます –

+0

'itemno =:itemnoまたは:itemnoがnullの場合や、(prodgrppatternや:prodgrppatternのようなproductgroupがnullの場合) ...? –

答えて

1

は、次のスクリプトを試してみてください。スクリプトはステートメントを生成し、別のスプールで実行します。

set serveroutput on size 1000000 
    set verify off 
    set feedback off 
    spool script.sql 

    declare 
     v_main_select varchar2(32000):= 'select col1, col2, col3 from table1'; -- your main statement 
    begin 
     for r_query in (select condition, where_statement from (
          select 'condition1' condition, 'where id = 10' where_statement from dual -- your condition name and where statements 
          union 
          select 'condition2', 'where id = 11' from dual 
          -- more unions for each condition.... 
          ) 
        ) loop 
     dbms_output.put_line('spool'||' '||r_query.condition); 
     dbms_output.put_line(v_main_select||' '||r_query.where_statement||';'); 
     dbms_output.put_line('spool off'); 
     end loop; 
    end; 
    /

    spool off 

    @script.sql 
関連する問題