0

I'm pretty new in Oracle universe and I need help. I have to iterate through Users Table and insert these 3 specific rows into Task_Group Table. The hard thing to do is to check if these rows even exist (tables are just samples, I need to iterate through a table with a lot of rows), and then insert them only in rows and set Company_Number to: 22.enter image description here

Please help, guys!

  • so why only that three and nor the other? – hotfix May 28 at 19:20
  • @hotfix It's a task, I must iterate between 13256 row and 14639 row for example and insert them into a new table with Company_Number set to 22. – NewJavaEnthusiast May 29 at 6:23
  • 13k rows is not a large amount of records, you can do it with an insert – hotfix May 29 at 6:26
  • @hotfix It's working on this template table, so thanks a lot, I will upvote and select your answer as my solution. – NewJavaEnthusiast May 29 at 6:42
1

You can check whether the entry for the user already exists in the table and then exclude that users.

Depending on your data, you can do it with an insert, e.g.

insert into task_group (id, user_id, phone,name, company_no)
select rownum, id, phone,name, 22 
  from users u 
 where not exists(select 1 from task_group t where t.user_id = u.id);

you cann also loop over the data in your cursor and do commit every x Rows, but it is a very slow way to do that

  • Your first sentence : you would use a MERGE statement instead of INSERT-SELECT – Michael Kutz May 29 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.