Solved

how to write Pl/SQL script

Posted on 2014-12-17
4
216 Views
Last Modified: 2014-12-21
Hi ,

I have SQL script with 200 update .

My DB team ask me to write PL/SQl script using for loop ?

I am not understand what they asking ? can you tell me?
If possible then how to do that ?
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 250 total points
ID: 40506304
Perhaps, your 200 update SQL script is viewed by the DBA as a very big transaction taking many resources. I think what they ask you is to write a cursor to update the table(s) row by row committing each row's update separately. This would minimise the load on the server.
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 40506861
I do not understand what you are asking.

What generated the script with 200 update statements?
If it was another script then you might be able to create a loop.

A PL/SQL loop is pretty simple and there are many examples on the web and even in the documentation.

For example:
begin
    for i in (select val1, val2, val3 from some_table) loop
          update some_other_table set col1=i.val1, col2=i.val2 where col3=i.val3;
   end loop;
   commit;
end;
/

Open in new window


Note: depending on the size of the transactions you might want to move the commit inside the for loop.  We cannot help with that since we do not know your database.
0
 
LVL 32

Expert Comment

by:awking00
ID: 40509208
>>I have SQL script with 200 update .<<
Can you post that script?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question