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 7883557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:33:51+00:00 2026-06-03T04:33:51+00:00

If I am referencing an entire table with a cursor. Can I use the

  • 0

If I am referencing an entire table with a cursor. Can I use the insert statement based on conditions in other tables multiple times? For example:

V_Name                 Emp.Name%type;
V_E_Number             Emp.Number%type;
V_Location             Emp.Location%type;
V_City                 Emp.City%type;
V_P_ID                 Emp.P_ID%type;
V_State_Code           Emp.State_Code%type;

Cursor C1 is Select emp.name, emp.number, emp.Location, emp.City, emp.P_ID, emp.State_Code
             From Employee Emp, Former_Employee Femp
             Where Emp.Number = Femp.Number
             And State_Code = '4';

Begin

Open C1;

Loop

Fetch C1 Into V_Name, V_E_Number, V_Location, V_City, V_P_ID, V_State_Code;

EXIT WHEN C1%NOTFOUND;

IF New_Emp.P_ID != V_P_ID 
Then Insert Into New_Emp
Values (V_Name, V_E_Number, V_Location, V_City, V_P_ID, V_State_Code); 

IF New_Emp.P_ID = V_P_ID,
   New_Emp.State_Code = V_State_Code
Then Insert Into Emp_Archive
VALUES (V_Name, V_E_Number, V_Location, V_City, V_P_ID, V_State_Code);  

Else Do Nothing;

End If;

End Loop;

Close C1;

End;
/ 

Then Can I open the cursor again and use another If Statement to populate a different table with different conditions?

  • 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-03T04:33:52+00:00Added an answer on June 3, 2026 at 4:33 am

    You can open a cursor, fetch from the cursor, close the cursor, and then re-open it later. You may get different data when you open the cursor again because the data in the underlying table may have changed. However, looking at your code, there seems to be no need to declare a cursor in the first place– you can simply code two INSERT statements (assuming that the new_emp record that your code refers to but does not declare is valid)

    INSERT INTO new_emp
      Select emp.name, emp.number, emp.Location, emp.City, emp.P_ID, emp.State_Code
        From Employee Emp, Former_Employee Femp
        Where Emp.Number = Femp.Number
          And State_Code = '4'
          AND emp.p_id   = new_emp.p_id;
    
    INSERT INTO Emp_Archive
      Select emp.name, emp.number, emp.Location, emp.City, emp.P_ID, emp.State_Code
        From Employee Emp, Former_Employee Femp
        Where Emp.Number = Femp.Number
          And State_Code = '4'
          AND emp.p_id   = new_emp.p_id
          AND emp.state_code = new_emp.state_code;
    

    You could simplify that further by doing a single INSERT ALL

    INSERT ALL 
      WHEN new_emp.p_id = p_id
           THEN INTO new_emp( name, number, location, city, p_id, state_code )
                  VALUES( name, number, location, city, p_id, state_code )
      WHEN new_emp.p_id = p_id AND
           new_emp.state_code = state_code
           THEN INTO emp_archive( name, number, location, city, p_id, state_code )
                  VALUES( name, number, location, city, p_id, state_code )
      Select emp.name, emp.number, emp.Location, emp.City, emp.P_ID, emp.State_Code
        From Employee Emp, Former_Employee Femp
        Where Emp.Number = Femp.Number
          And State_Code = '4'  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Referencing this FsEye issue, how can I use reflection to determine whether an object
Referencing this Fiddle ( http://jsfiddle.net/j5uGN ), how can I toggle a clicked image's border
I have a self referencing table named categories that has a parentcategoryid column that
Can't seem change the name of my iPhone app 100%. I followed multiple threads
I have tree structures that are stored in a DB table. The table can
I have a self referencing table as covered in the doctrine documentation (which is
Referencing this post: ruby on rails average per day I'm getting the average per
Referencing Is Facebook an OpenID provider? here. This is kind of an additional question
Referencing my Earlier Question , regarding downloading a file from a server and handling
I'm referencing a static library . I've dragged the library project into my app

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.