How to structure SP with many DML operations

Hi
I have a stored procedure that does inserts, updates and deletes. My question is should this be within one begin and end or should each of these DML's have their own begin, end and exception blocks? What would be considered to be a good practice?

I'm with user553641 on this; keep things simple.
I write my programs as small, simple procedures or functions, that generally do one thing. I name them appropriately, and that helps things to be self documenting.
I group things together in a package, and there might be one or two main procedures that are exposed in the specification. Inside the package body, those main procedures will call the "sub" procedures (which in turn may call other procedures), etc.
Doing this has several benefits:
1. Testing becomes easier - you can test each bit of the code in isolation before running the code altogether - this is much, much easier than trying to test one massive "spaghetti" piece of code.
2. Easier maintenance - it's easy to see what the purpose of each procedure does, so if you need to make changes, you have a much better handle on what the potential impacts might be.
3. Easier to see what the flow of the program is when you're writing it - you can say "I want to promote someone" - so you have a main proc called "promote_person" which in turn calls two procedures: "change_job_title" and "alter_salary" - you don't have to consider the alter_salary part whilst you're working on the change_job_title part, etc (this is called "top down programming")
4. Promotes code reuse - "alter_salary" and "change_job_title" could be used elsewhere.
Think of it like building a house - would you build a house by taking one huge, house-sized brick and carve everything out, or would you use lots of small bricks to build up the walls bit by bit?

Similar Messages

  • Query performance on same table with many DML operations

    Hi all,
    I am having one table with 100 rows of data. After that, i inserted, deleted, modified data so many times.
    The select statement after DML operations is taking so much of time compare with before DML operations (There is no much difference in data).
    If i created same table again newly with same data and fire the same select statement, it is taking less time.
    My question is, is there any command like compress or re-indexing or something like that to improve the performance without creating new table again.
    Thanks in advance,
    Pal

    Try searching "rebuilding indexes" on http://asktom.oracle.com. You will get lots of hits and many lively discussions. Certainly Tom's opinion is that re-build are very rarley required.
    As far as I know, Oracle has always re-used deleted rows in indexes as long as the new row belongs in that place in the index. The only situation I am aware of where deleted rows do not get re-used is where you have a monotonically increasing key (e.g one generated by a seqence), and most, but not all, of the older rows are deleted over time.
    For example if you had a table like this where seq_no is populated by a sequence and indexed
    seq_no         NUMBER
    processed_flag VARCHAR2(1)
    trans_date     DATEand then did deletes like:
    DELETE FROM t
    WHERE processed_flag = 'Y' and
          trans_date <= ADD_MONTHS(sysdate, -24);that deleted the 99% of the rows in the time period that were processed, leaving only a few. Then, the index leaf blocks would be very sparsely populated (i.e. lots of deleted rows in them), but since the current seq_no values are much larger than those old ones remaining, the space could not be re-used. Any leaf block that had all of its rows deleted would be reused in another part of the index.
    HTH
    John

  • QUESTION:  HOW TO WRITE QUERY  WITH MANY TO MANY RELATIONSHIPS

    Could someone help me out here?
    I was sitting here looking at some tables ie table_name and synonyms and wondering.
    If a table can belong to many synonyms and a synonym can belong to many tables how would one write a query where I would like to know which tables belong to each synonym or on the other hand which synonym belongs to what tables?
    Would I try to develop an outside join for this, a corrolated query or a query with a subquery or would there be another format that would work better?
    What would be the best method of attack on this?
    Thanks for your thoughts on this.
    al

    Actually, the relationship is not many to many. A table can have many synonyms, but a synonym within a namespace (i.e. a PUBLIC synonym, or a private synonym created by a user) can only point to one table. The xxx_synonmys tables already contain the information about the table_name and table_owner.
    John

  • Count DML operations

    Hi Friends,
    Can we count and analyze that how many DML operations/transactions been made in current session and on a particular table.
    If yes then how ?
    Thanks in advance...

    Hi,
    You can audit on table : http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_48a.htm#SQLRF01107
    Nicolas.

  • I have an older Ipod shuffle with many songs loaded on it. How can I transfer these songs to a new computer since the old computer is no longer available

    I have an oder Ipod shuffle with many songs loaded on it. How can I transfer ths songs to a new computer since the old computer is no longer available?

    I had the same problem with my iPad, i couldn't get the newer version of itunes because the computer was too old and my iPad couldnt sync with the old itunes. I got a PC from school a few months later so that solved the problem for me. Unfortunately i don't think there would be a program to put your music on your iPod, iTunes should be the only way to transfer files to Apple devices. What operating system are you running and what version of it is it?

  • Rss form with many item fileds how to insert at once all?

    RSS Form have single channel with many items.How to get them all form form so that can be added to a file.
    For now what i have done is a form having (RSS) input types as channel(title,link,desc) with many items together(title,link,desc)
    here i submitted the form to a servlet.to add to a file created a filehandler as well. but now problem is how to add many items to file together. Onechannel with many items sholud get uploaded to filehandler which will create a RSS file structure.On the basis of input.
    at the time of addition in a channel item can be 1-5 with all fileds (title,link desc) now how sholud i iterate them all.
    please if someone can suggest me anything please let me know.
    vijendra

    Hi,
    Did you try it? when you execute insert/update, corresponding trigger gets executed in same session and that's why I have V('Variable Name') . V('Variable Name') get will get replaced by its value in the current session sate.
    Thanks,
    --Manish                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to know which DML operation is taking place on a table within a procedu

    Hii all,
    My DB Version
    SQL> select *
      2  from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - ProductionHow to find what DML Operation is taking place on a particular table within a procedure??
    For suppose I've the below procedure
    create table r_dummy
    name varchar2(4000),
    emp_id number
    Create or replace procedure r_dummy_proc
    p_name          in     varchar2,
    p_emp_id     in     number
    is
    Begin
              Update r_dummy
              set name = p_name
              where emp_id = p_emp_id;
              if sql%rowcount > 1 then
                   dbms_output.put_line('Successfully updated employee name');
              end if;
    End;Here from the code I can identify that an update operation is taking place on table 'R_DUMMY'
    But how to find that without actually viewing the code?? I've hundreds of procedures in my DB and would like to find what DML is taking place on which table and in which procedure.
    Please help with some suggestions.

    And here is the solution
    with t as
      select distinct name,type,text,line
      from user_source s
      where regexp_like(s.text,'cp_ca_dtls','i')
    x as
      select name,line,text
      from
      select name,case when (regexp_instr(text,'(update)|(insert)|(delete)',1,1,1,'i') >0) and regexp_instr(ld,'CP_CA_DTLS',1,1,1,'i') >0
             then line
             else null
             end as line,text
      from
      Select   name,text,line,lead(text) over(partition by name order by line) ld
      from user_source
      where name in
          select distinct name
          from user_source
          where upper(text) like '%CP_CA_DTLS%'
      order by 1 nulls last
      )where line is not null
    select name,line,text
    from t t1
    where regexp_instr(text,'(update)|(insert)|(delete)',1,1,1,'i') >0
    and exists
         select 1
         from t t2
         where t1.name = t2.name
            and t1.type = t2.type
            and t1.line = t2.line
    union
    select name,line,text
    from x

  • How to Track DDL and DML Operations happening in Backend into Log Files....

    Hi I have one requirement for Tracking the DDL And DML Operation happening in Backend once the user Inserts or Updates any Table.How to Implement the same can anyone proviode the code for the same.
    Ex: I have multiple tables in my database if any user fires the DDL or DML it should make entry in the Log file as
    Name of the Table Operation Timestamp
    X Insert DD-MM-YYYY HH24:MM:SS
    Y Update DD-MM-YYYY HH24:MM:SS
    Z Delete DD-MM-YYYY HH24:MM:SS
    L Select DD-MM-YYYY HH24:MM:SS
    Is it Possible to Develop it through Procedure,Function or Package,please give me Idea,,,,,

    Please do not post same question in multiple forum. How to Track DDL and DML Operations happening in Backend into Log Files....
    What's wrong with the answers posted in the above forum ? Do you go through the "AUDIT" option as suggested in the above post by various members ?

  • I have several disks with many comedy routines;I want to select a few from each disk and combine them to one disk for my personal use.How?

    I have several disks with many comedy routines;I want to select a few from each disk to make one single disk for my personal use.How?

    Copy the routines into a new folder on your hard drive. Then burn the folder to a new blank disc using Disk Utility.

  • Safari 5.1 now is garbled with many of the sites having lines on top of each other. Is any one else having that issue? If so, how did you resolve it? Thanks in advance for any help.

    Safari 5.1 now is garbled with many of the sites having lines on top of each other. Is any one else having that issue? If so, how did you resolve it? Thanks in advance for any help.

    "Did you make the .psd file with a transparent background (checkerboard) in Photoshop? And when you placed it in AI did you choose the top option Convert Photoshop Layers to Objects?"
    Yep, and it still didn't work.
    But I figured what I did wrong: I was selecting both the text and the heart, and then I was doing the whole Object>Wrap Text>Make thing, as opposed to just selecting the heart and doing it. Once I did it, I moved the heart around on top of the text, and it "made room" for the pic, wrapping itself around the heart.
    Thanks so much, and thanks A MILLION for being so patient.
    Jeez, when can I get some textbook to learn all the intricacies of Illustrator?

  • How do I resolve this related Ical message? The server responded with "400" to operation CalDAVUploadDropBoxFileQueueableOperation.

    How do I resolve this related Ical message? The server responded with “400” to operation CalDAVUploadDropBoxFileQueueableOperation.

    I am having this problem too...and also I (most of the time) can't invite anyone on my google apps domain to a meeting. WEIRD! HELP!!! I just switched to Mac from PC...this was supposed to be EASY!
    I get all kinds of error  messages...
    1) The request for “Test Appointment” in “[email protected]” in account “yyyy.com Google” failed.  The server responded with “400” to operation CalDAVScheduleEventQueueableOperation. *My google calendar *IS* updated despite the error, but the appointment is greyed out on my calendar.
    2)  The URL https://calendar.google.com/calendar/dav/[email protected]/user///calendar.google.com/calendar/dav/[email protected]/user/ encountered HTTP error 404. Make sure the URL is correct. The URL *IS* correct.
    Also, when I try to invite people to appointments, iCal adds random attendees and frequently will not add an attendee if they are in my domain. HELP.

  • I have been trying to get my iPhone to sync with a new computer.  As a result I have ended up with many of my apps on the old computer, but missing from the the new one and the iPhone.  How do I get the apps on the old one to the iPhone and then the new c

    I have been trying to get my iPhone to sync with a new computer.  As a result I have ended up with many of my apps on the old computer, but missing from the the new one and the iPhone.  How do I get the apps on the old one to the iPhone and then the new computer?

    You don't. Backup your itunes library on the old computer and move it to the new computer.

  • Hello guys..does anybody know how to install and use adobe master collection with the new lion?   I need to use Flash and illustratore, but apparently those programmes are incompatible with the new operative sistem...   I am a new mac users and I'd like t

    Hello guys..does anybody know how to install and use adobe master collection with the new lion?
    I need to use Flash and illustratore, but apparently those programmes are incompatible with the new operative sistem...
    I am a new mac users and I'd like to know if there are other similar programmes I can use with lion!

    Lab79 wrote:
    Are you on Apple's payroll?
    well dude I can only let you know that as I work with those programme I don't have to pay for it is my company that pays the programme I whant to use( that's why I was asking if there where other programmes ..that I could use with lion insted that Illustrator and Flash!)..I know Adobe since 2005 and I can say that Adobs products are very good...I think that if it's an Adobe probleme or fault ..they will solve it very soon...but unfortunally I have the impression that after Jobs passed away Appel decided to change politics..and everything started to go very bad! (see FCP X)..
    good luck with apple dude..
    Where is the Apple problem? I have CS4 and CS5 running perfectly fine on my Macbook Pro. Installed 5 after Lion upgrade. Worth every cent. Adobe did have some catching up to do with Lion but with the CS5.5 update all runs fine. But not yours. So it is a problem with the Lion OS? You say you have been with Adobe since 2005. So you would be aware of all the other issues that Adobe had catching up with past Oss in Mac and Windows then. They get it right, but it is up to them. It is not up to Apple, nor Microsoft for that matter, to run around and check that every software developer in the world is running their business properly.
    And what has politics got to do with anything. Some people just have to blame Software for their poor Hardware maintainence of failure of the same.
    <The only think I can really do is to go back on my old windows...give back this orrible lap top and ask for my money back!>
    Great suggestion. You should go with that one, but good luck getting a refund.
    Bye

  • I did a presentation with many images and animations, now I need to change only the images without modify the related animations. How can I do it?

    I did a presentation with many images and animations, now I need to change only the images without modify the related animations. How can I do it?
    I use Keynote 09

    Select the image you want to change and go to Format Menu>Advanced>Define as Media Placeholder (or command, option, control i).

  • How can I filter to find photos NOT pinned to a map? I have 28,000 phots with many mapped and many not. The Search function does not include GPS data. I haven't found  way to search metadata inside or out of Elements.

    How can I filter to find photos NOT pinned to a map? I have 28,000 phots with many mapped and many not. The Search function does not include GPS data. I haven't found  way to search metadata inside or out of Elements.

    How can I filter to find photos NOT pinned to a map? I have 28,000 phots with many mapped and many not. The Search function does not include GPS data. I haven't found  way to search metadata inside or out of Elements.

Maybe you are looking for

  • Quicktime Streaming of keynotes does not work

    When I want to watch the keynotes on apple.com all I get is stuttering audio and chopped video. Why? How can I solve this? It's independent of the resolution I select. btw. why am I forced to use that stone-aged Quicktime to watch a movie by the "HTM

  • Single session for all Application Modules

    Hello, I've got an application that has several Application Modules. All these modules need some data that are set from time to time. I've written some code that calls getSession().getUserData().put("myData",myData). After this method was called in a

  • I want to buy some DAQCard 700

    I have an application that require the DAQCard 700. Do you have some of them to offer? I need a lot to have spare parts for some systems.

  • Error creating Virtual Machine from Oracle VM Template Input/output error

    Hi, I'm creating a virtual machine from the Oracle VM Template (OVM_OL5U6_X86_64_EBIZ12.1.3_APPS_VIS_PVM) I downloaded from eDelivery. I keep getting this error. ========= Check Agent Version Check Address and NetworkType Register virtual machine img

  • Why is Firefox for Android and Nook HD+ such garbage?

    it's very annoying, u can't save pages, the menu system sucks, the top is stupidly designed to hide after a few seconds, the tab system is stupidly hidden and confusing and hard to use! make it the way it is in windows, not this simpleton trendy crap