• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

I need to be able to Select rows of data from an Oracle db. I then need to be able to ammend certain parts of the data selected and insert it back in the same table. Any ideas?

I need to be able to Select data from an Orcale table and use it as a template. In the db there is multiple records stored for one 'template', I need to copy most fields associated with the certain 'template'. Once the data has been retrieved I then need to change the data already stored in some fields i.e  change project No to the actual project number that has been inputted on the GUI. Im presuming I need some sort of array/dataset and will need a loop, unfortunatly Im stuck with how. Help much appreciated!

Select statment

SELECT ProjectNo, TaskNo, CustomerNo, etc etc FROM P_AMaster WHERE ProjectNo like '" + ddlTemplates.SelectedItem.Text + "'";

Ive tried to give an example of the table
ProjectNo TaskNo CustomerNo PlannerNo ...... ...... .......
Temp1     0000   .......     .......
Temp1     1111   .......    .......
Temp1     2222   ......     .......

Open in new window

0
dwezil
Asked:
dwezil
1 Solution
 
MikeOM_DBACommented:

You may need to write a stored procedure, something like this:


CREATE OR REPLACE PROCEDURE copy_template (
   p_template_id     VARCHAR2,
   p_new_projectno   VARCHAR2,
   p_customerno      NUMBER
)
IS
BEGIN
   FOR t IN (SELECT projectno, taskno, customerno, etc1, etc2
               FROM p_amaster
              WHERE projectno = p_template_id)
   LOOP
      INSERT INTO p_amaster
           VALUES (p_new_projectno, t.taskno, p_customerno, t.etc1, t.etc2);
   END LOOP;
   COMMIT;
END;
/

Open in new window

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now