Note that there are some explanatory texts on larger screens.

plurals
  1. POOracle loop insert
    text
    copied!<p>I'm having issues to perform one mass update in our Oracle DB.</p> <p>I would like to do mass insert to mapping table which we can call <strong>map</strong></p> <p>There are other two tables from which I have to obtain the data The first table is the <strong>account</strong> table from which I can select the desired accounts for inserting with this query:</p> <pre><code>select account_id from account where company_id in ( select company_id from company where company_name = 'string'); </code></pre> <p>This query will select my all the accounts depending on the company name which I want to insert.</p> <p>Next I have table which we can call <strong>group</strong> and in this table I have exact number of groups which I inserted, groups have UIDs so we have group_id 1 to 500.</p> <p>Here is what i need to do: I need to insert into table map UID mappings between the accounts and groups. There is no special order in which needs to be done</p> <pre><code>insert into map (account_id, group_id) values (number,number); </code></pre> <p>But unfortunately I don't know how to do such mass insert with selects which are containing more then one result and also how to count the looping.</p> <p>So my idea is do something like this:</p> <pre><code>insert into map (account_id, group_id) values ((select account_id from account where company_id in ( select company_id from company where company_name = 'string')),loop from 1 to 500); </code></pre> <p>With rule that <code>group_id</code> can be inserted with many <code>account_id</code>s but one <code>account_id</code> can be linked only to one group.</p> <p>Of course this query will not work, I'm just trying to express what I want to do. Hope this make sense.</p> <p>I since I know what exactly I want to insert where and I have all the counts I know that I have 500 <code>account_id</code>s and 50 <code>group_id</code>s. Also they are in order meaning <code>account_id</code> 1 to 500 and <code>group_id</code> 1 to 500, so I think in this case it should be fairly easy to loop the insert somehow. </p> <p>I hope I have made myself clear as much as possible.</p> <p>Thank you for your answers and suggestions!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload