Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:56:50+00:00 2026-06-09T13:56:50+00:00

I have 2 tables- student and studLoad both having 2 fields studID and studName

  • 0

I have 2 tables- student and studLoad both having 2 fields studID and studName. I want to load data from student table into stuLoad table.
If the data already exists in the studLoad table, then it should be updated else it should be inserted. following is my code to do so:

    create or replace procedure studentLoad is
v_id student.studID%type;
v_name student.studName%type;
v_sn studLoad.studName%type;
cursor cur_load is
select * from student;


begin
  open cur_load;
  loop
   fetch cur_load into v_id,v_name;

   exit when cur_load%notfound;
   select studName into v_sn from studLoad where studID = v_id;
   if(v_sn!= v_name) then
      update studLoad set studName= v_name where studID= v_id;
   else
      insert into studLoad values(v_id,v_name);
   dbms_output.put_line(v_id || ' ' || v_name);
   end if;
  end loop;
      close cur_load;
end;

It’s not working. the rows in studLoad table are noT updated. How do I solve this? In SQL server we use IF EXISTS(select...from stuLoad..) to check if the record exists in the table, is there a way to do the same in Oracle? if yes then please let me know the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:56:52+00:00Added an answer on June 9, 2026 at 1:56 pm

    This is a highly inefficient way of doing it. You can use the merge statement and then there’s no need for cursors, looping or (if you can do without) PL/SQL.

    MERGE INTO studLoad l
    USING ( SELECT studId, studName FROM student ) s
    ON (l.studId = s.studId)
    WHEN MATCHED THEN
      UPDATE SET l.studName = s.studName
       WHERE l.studName != s.studName
    WHEN NOT MATCHED THEN 
    INSERT (l.studID, l.studName)
    VALUES (s.studId, s.studName)
    

    Make sure you commit, once completed, in order to be able to see this in the database.


    To actually answer your question I would do it something like as follows. This has the benefit of doing most of the work in SQL and only updating based on the rowid, a unique address in the table.

    It declares a type, which you place the data within in bulk, 10,000 rows at a time. Then processes these rows individually.

    However, as I say this will not be as efficient as merge.

    declare
    
       cursor c_data is
        select b.rowid as rid, a.studId, a.studName
          from student a
          left outer join studLoad b
            on a.studId = b.studId
           and a.studName <> b.studName
               ;
    
       type t__data is table of c_data%rowtype index by binary_integer;
       t_data t__data;
    
    begin
    
       open c_data;
       loop
          fetch c_data bulk collect into t_data limit 10000;
    
          exit when t_data.count = 0;
    
          for idx in t_data.first .. t_data.last loop
             if t_data(idx).rid is null then
                insert into studLoad (studId, studName)
                values (t_data(idx).studId, t_data(idx).studName);
             else
                update studLoad
                   set studName = t_data(idx).studName
                 where rowid = t_data(idx).rid
                       ;
             end if;
          end loop;
    
       end loop;
       close c_data;
    
    end;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables. The designs were like student table create table student (studID
I have two tables. 1- student table & 2- Score table I want to
I have two tables associated by FK. Table student is mapped like this: @Entity
I have bind 2 separate tables using BindingSource. Left grid contains student table and
I have the following tables: Student Data Student ID (primary key) Prior Education Student
I have 3 tables Student, Course, and the linking table StudentCourse, how do i
Supose I have following entities created from database tables: Person Student Student include Person
I want to fetch the top 10 records from 2 tables which have id
I have the folowing tables: Table student: id name 1 foo 2 bar 3
I have 2 tables, a master table and a transaction table. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.