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!

4
  • so why only that three and nor the other?
    – hotfix
    Commented May 28, 2019 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. Commented May 29, 2019 at 6:23
  • 13k rows is not a large amount of records, you can do it with an insert
    – hotfix
    Commented May 29, 2019 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. Commented May 29, 2019 at 6:42

1 Answer 1

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

1
  • Your first sentence : you would use a MERGE statement instead of INSERT-SELECT Commented May 29, 2019 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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