Extracting rows from a DB including depedent rows

前端 未结 3 1400
灰色年华
灰色年华 2021-02-10 18:15

I\'d like to generate insert-strings for a row in my Oracle database including all its dependent rows in other tables (and their dependent rows).

Example:



        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-10 18:41

    I just use plain old SQL to do these tasks - use the select statements to generate your inserts:

    set pagesize 0
    set verify off
    
      SELECT 'INSERT INTO a(a_id, name) VALUES ('
             || a_id || ', '
             || '''' || name || ''');'
        FROM a
       WHERE a_id = &&1;
    
      SELECT 'INSERT INTO b(b_id, a_id) VALUES ('
             || b_id || ', '
             || a_id || ');'
        FROM b
       WHERE a_id = &&1;
    

提交回复
热议问题