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

dwezilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.