Solved

how to write Pl/SQL script

Posted on 2014-12-17
4
212 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
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax Assistance 2 35
Syntax error creating JSON recordset 4 28
T-SQL: Stored Procedure Syntax 3 34
Oracle SQL Developer - SubString 2 31
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.

726 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