UPDATE within Cursors

declare
cursor d is
select Name, Age from Rem1 where Name = 'Santosh' for update of Age;
record d%ROWTYPE;
begin
OPEN d;
loop
FETCH d into record;
EXIT when d%NOTFOUND;
begin
update Rem1 set Age = 30 where CURRENT of d;
insert into Keeper values(record.Name, record.Age);
commit;
EXCEPTION
when others then
rollback;
end;
end loop;
CLOSE d;
end;
How to Issue multiple update statements within this CURSOR?
Can You give me a snippet of how to do it? Just show me using the SQL code that I had sent

Try this:declare
cursor d is
  select name,age
    from rem1
   where name = 'Santosh'
     for update of age;
begin
for c in d loop
  update rem1 set age = 30 where current of d;
  insert into keeper values(c.name,c.age);  -- Age is old value.
end loop;
commit;  -- Outside loop.
end;If commit is on inside of loop, you get an "ORA-01002: Fetch out of sequence." error.
Kind regards,
Russ

Similar Messages

  • How to know which stock type updated within movement type

    Expert,
    I need to know which stock type updated within each movement type.
    I'm using two different system (SAP and Oracle) which is in each system updating stock. So i need to do stock calculation manually from that two systems.
    I'm planning to imported material document data (from MKPF & MSEG) to Oracle and then combine the stock calculation.
    And then i'm facing this :
    Ilustration :
    MIGO transaction - Goods Receipt PO - Stock Type Unrest
    in MSEG field BWART : 101, SHKZG : S, INSMK : blank --> no problem
    MIGO transaction - Goods Receipt PO - change Stock Type to Quality Inspection
    in MSEG field BWART : 101, SHKZG : S, INSMK : 2 --> no problem
    MIGO transaction - Transfer Posting - movement type 322 (reversal QI to Unrest.)
    in MSEG field BWART : 322, SHKZG : S, INSMK : blank --> problem
    in MSEG field BWART : 322, SHKZG : H, INSMK : blank --> problem
    I have a problem that in MKPF & MSEG there is no indicator which stock type updated within movement type (BWART) 322.
    How to know that first row will be updating stock QI and second row will be updating stock Unrest.??
    I've already checked to OMJJ, SM30-V_156SC_VC, table T156... and still having no clue.
    Or is it just a 'hardcode' ? And i need to do 'hardcode' too in Oracle system?
    Thank you so much.

    The stock type indicator doesn't update for the movement type 322 in table MSEG.
    At the time of transferring, you do not have to enter the stock type for movement type 322.
    I can give you one clue, check can it fulfill your requirement.
    You have two line items for movement type 322 in MSEG table, There are a field XAUTO will be updated as X for credit entry.
    You can assume, the line item (without value for XAUTO) is for less from QI stock and the line item (with value X for XAUTO) is for add to unrestricted stock.

  • Apply monthly Windows 2008 r2 updates within SQL Server 2008 cluster

    Hello is applying Windows updates within 2 node SQL Server 2008 cluster (active-passive) as simple as download/install the windows update on the passive node, then failover, then apply on other node, and then fail back over ?...or are there other needed/recommended
    steps ?  Thanks in advance.

    Thanks for your reply Shanky_621 much appreciated.
    In your link provided http://support.microsoft.com/kb/174799 it looks like the steps order is slightly different from this link of
    http://technet.microsoft.com/en-us/library/cc731291.aspx which mentions...
    "...where the recommended sequence is to move all services and applications off of the node, pause the node, then apply software updates to the node."
    ...does it matter which is done first ('Pause' or 'move Services/Application') or can I simply go to the Passive node (say 'B' where there are no Services or Applications currently on it), 'Pause' it, apply the Windows updates, then 'Resume' it, &
    reboot ?

  • How can I implement a recursive update within triggers?

    Given
    INSTANCE (table)
    INST_ID
    etc.
    INSTANCE_STRUCTURE (table)
    PARENT_ID (fk to INST_ID)
    CHILD_ID (fk to INST_ID)
    And that I COULD write code which recursively navigates the hierarchy (ie. START WITH parent_id = ? CONNECT BY PRIOR child_id = parent_id) and issues UPDATEs to each "child" along the way, thereby propogating the desired update, how can I accomplish the same thing using triggers?
    Keep in mind I am using Oracle 7.3 and I have no choice. Also, the DBA is very difficult to get a hold of and I have no idea if there may be some server settings which are preventing some of my attempts from succeeding.
    Of course the simplest method is to make an update trigger on INSTANCE select all CHILD_ID from INSTANCE_STRUCTURE and issue UPDATE to each which, in turn, would invoke the same trigger, however, we can't have a mutating table, now can we?
    Next, I tried the old global variable in a package bit. That's when I first started getting this "end of channel" business which essentially disconnects me from Oracle (while using SQLPlus). I started to debug that, and then other users started getting errors ... apparently due to the global variable being global ACROSS sessions ... which I did not expect (correct me if I'm wrong and I can try it again), however, due to the amount of data I'm dealing with in any one particular line of hierarchy, I'm not sure I wouldn't get an error anyhow ... particularly if I have to maintain a global array for everyone at once. Anyhow, it was during that, that I realized the "too many open cursors" thing and so I started working with START WITH CONNECT BY to identify all rows which must be dealt with.
    Then, I tried setting up some new tables (as opposed to global variables) in which I would identify userenv('sessionid') and other data so that a BEFORE UPDATE, FOR EACH ROW trigger could check to make sure that the AFTER UPDATE trigger had not begun yet (IOW, not recursing yet). Basically, everything's fine until the AFTER UPDATE trigger tries to apply UPDATEs for the children (identified from a cursor on START WITH CONNECT BY) ... then I get the "end of channel" thing again.
    Obviously, this whole thing is an attempt to denormalize some data for performance reasons.
    Any help would be appreciated.
    Thanks.

    Nevermind, I figured somethin' out.

  • Any way to keep files updates within folders?

    Hey guys.. I am experimenting with iPhoto, and had a few quick questions.
    I just imported a folder, containing the folder structure I use to organize a specific set of pics on my hard drive. They're reference/inspiration shots for my own photography. I was stoked to discover that each folder became an "event".
    However my library is "managed", so while they weren't deleted from their location, the shots I am looking at inside of iPhoto are now contained inside the iPhoto Library file. Is that correct?
    As I'm always adding files to those folders, and occasionally moving them around manually, my main question I have is concerning whether there's any way to keep those "events" up to date with what files are in the actual folders?
    I'm not opposed to having a 2nd REFERENCED library File for this sole purpose.
    In a Managed Library:
    Is there any way to add a file to a folder manually using the finder, and have iPhoto recognize that it contains a new file and update itself when I view that "event"? Or can I update it manually at least? Like a "refresh".
    In a Referenced Library:
    - Can I keep the "event" up to date with changes to the referenced folder?
    In Either case:
    - If I delete/move a file from a folder via the finder, will the "event" be corrupted, or "missing" a file?
    - If I delete/move a file a file from an event via iPhoto, will the file be deleted in reality, or just the reference/management of it?
    - If I find that some of my iPhoto "events" could be combined into one for ease of navigation:
    a) Can I do this? How?
b) Will that change the folder structure of my original ile?
    Finally,
    - If I go with 2 libraries (Managed for personal shots, and Referenced for other peoples shots), how do I switch between libraries? (I'd want the Managed/Personal shots to open upon launch by default.)
    Cheers! Thanks in advance!
    Ben

    You're not quite getting what iPhoto is, what a managed and referenced Libraries are.
    iPhoto is a Photo Manager. It replaces the Finder for anything to do with your Photos. It's your go-to app whenever you want to add, delete, view, manage or whatever your photos.
    A Managed Library means that iPhoto manages the actual files. They are copied to the Library package on import.
    A Referenced Library means that you manage the files. Then import them. After that you never access the files again. It's all done via iPhoto.
    So, what you're trying to do - syncing a folder system with an iPhoto Library - is unnecessarily complex. Either use the Finder for your Photo or use iPhoto (or similar apps, like Aperture, Lightroom etc)
    However my library is "managed", so while they weren't deleted from their location, the shots I am looking at inside of iPhoto are now contained inside the iPhoto Library file. Is that correct?
    Correct.
    As I'm always adding files to those folders, and occasionally moving them around manually, my main question I have is concerning whether there's any way to keep those "events" up to date with what files are in the actual folders?
    You can do this with Automator, Apple Script or with an app like Hazel: http://www.noodlesoft.com/hazel.php
    But... why would you? iPhoto is a photo manager, why are you using the Finder for the job as well. Rather than update those folders, why not just import the updates to iPhoto?
    I'm not opposed to having a 2nd REFERENCED library File for this sole purpose.
    It would make no difference. All it does is make more work for exactly zero benefit.
    In a Referenced Library:
    - Can I keep the "event" up to date with changes to the referenced folder?
    See above. But remember that every new import means at least one new event, so you'll need to consolidate events after the import.
    In Either case:
    - If I delete/move a file from a folder via the finder, will the "event" be corrupted, or "missing" a file?
    Yes. In a Managed Library you never delete anything via the Finder. That's all done from within the iPhoto Window. (See what I mean about it replacing the Finder?). In a Referenced Library you need to delete the images from iPhoto first. Then you delete them from the folder structure. (See? More work/no benefit)
    - If I delete/move a file a file from an event via iPhoto, will the file be deleted in reality, or just the reference/management of it?
    In a Managed LIbrary the shot gets moved to the iPhoto trash. Empty that and it's moved to the system trash. Empty that and it's gone. For Referenced see above.
    - If I find that some of my iPhoto "events" could be combined into one for ease of navigation:
    a) Can I do this? How?
b) Will that change the folder structure of my original ile?
    You can consolidate Events simply by dragging one to another. You can move photos between event susing Flagging and so on. No, the files on the disk are never moved at all regardless.
    Again, the location of the files on the disk makes no difference as you never access them anyway.
    For help accessing your photos in iPhoto see this user tip:
    https://discussions.apple.com/docs/DOC-4491
    If I go with 2 libraries (Managed for personal shots, and Referenced for other peoples shots), how do I switch between libraries? (I'd want the Managed/Personal shots to open upon launch by default.)
    Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Choose Library'
    Here's a post that describes why Referenced Libraries are a bad idea
    https://discussions.apple.com/thread/3062728?tstart=0
    A General comment:
    Deep breath. This is simple and you're making it very complex.
    Use one managed Library. You can easily separate your personal work from these inspirational photos with a keyword. Events are a very limited form of organisation. iPhoto gets its real power from Albums and keyword. For instance:
    I use Events simply as big buckets of Photos: Spring 08, July - Nov 06 are typical Events in my Library. I use keywords and Smart Albums extensively. I title the pics broadly.
    I keyword on a
    Who
    What
    Where basis (The When is in the photos's Exif metadata). I also rate the pics on a 1 - 5 star basis.
    Using this system I can find pretty much find any pic in my 50k library in a couple of seconds.
    So, for example, I have a batch of pics titled 'Seattle 08' and a  typical keywording might include: John, Anne, Landscape, mountain, trees, snow. With a rating included it's so very easy to find the best pics we took at Mount Rainier.
    File -> New Smart Album
    set it to 'All"
    title contains Seattle
    keyword is mountain
    keyword is snow
    rating is 5 stars
    Or, want a chronological album of John from birth to today?
    New Smart Album
    Keyword is John
    Set the View options to Sort By Date Ascending
    Want only the best pics?
    add Rating is greater than 4 stars
    The best thing about this system is that it's dynamic. If I add 50 more pics of John  to the Library tomorrow, as I keyword and rate them they are added to the Smart Album.
    In the end, organisation is about finding the pics. The point is to make locating that pic or batch of pics findable fast. This system works for me.

  • Multiple SQL Update within Parent Query

    I am tring to extract an image from within a MS SQL image field,
    opening the image using JAI, getting the src.getWidth() & src.getHeight
    () of each item within the database, and then writing the width and
    height back into the database. Everything works except when I goto
    write the values into the database - the page (when loading) continues
    to work and work and work until I restart the tomcat service. I do not
    understand why this would occur, and what is even stranger - I have
    very similar code i used for resizing images in the database into a
    thumbnail - display and original file sizes using a similar approach...
    and that works with out a problem...
    I have tried the code with out the inner update query - it works. I
    tried with just the selection of a single specific item in the first
    query and that works, but when I try multiple updates the second query
    appears to stall.
    The code is as follows.:
    <%@ page language="java" import="javax.servlet.*,javax.servlet.http.*,java.io.*,java.util.*,java.sql.*,javax.media.jai.*,java.awt.*,java.awt.image.*,java.awt.Graphics.*,java.awt.geom.*,java.awt.image.renderable.*,javax.media.jai.widget.*,com.jspsmart.upload.*,java.net.*,com.sun.media.jai.codec.*"%>
    <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
    <%
         // Variables
         int count=0;
         int width                                             = 0;
         int height                                             = 0;
         String vFileName                                   = "";
         String vFileExt                                        = "";
         String vFileID                                        = "";
         String format                                        = "0";
         // Connect to the database
         Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
         Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://206.152.227.62:1433;DatabaseName=WWWBBD;User=wwwbbd;Password=bbd1412");
         //Create the statement
         Statement sqlGetPics                              = con.createStatement();
         Statement sqlUpdate                                   = con.createStatement();
         //build the query
         String qryGetPics                                   = "SELECT TOP 5 FileID, FileExt, FileName, AdjFile = CASE WHEN FullFile IS NULL THEN Display ELSE FullFile END FROM FileStore WHERE (UPPER(FileExt) = '.JPG' OR UPPER(FileExt) = '.TIF' OR UPPER(FileExt) = '.GIF' OR UPPER(FileExt) = '.BMP') AND (NOT Display IS NULL OR NOT FullFile IS NULL)";
         //execute the query
         ResultSet rsGetPics                                   = sqlGetPics.executeQuery(qryGetPics);
         // Initialization
         SmartUpload uploader                              = new SmartUpload();
         uploader.initialize(getServletConfig(),request,response);
         mySmartUpload.initialize(getServletConfig(), request, response);
         // Upload
         mySmartUpload.upload();
         while (rsGetPics.next()) {
              vFileID                                             = rsGetPics.getString("FileID");
              vFileExt                                        = rsGetPics.getString("FileExt");
              vFileName                                        = rsGetPics.getString("FileName") + vFileExt;
              width                                             = 0;
              height                                             = 0;
              uploader.fieldToFile(rsGetPics, "AdjFile", "/upload/" + vFileName);
              if (vFileExt.equalsIgnoreCase(".JPG") || vFileExt.equalsIgnoreCase(".JPEG"))
                   format                                        = "JPEG";
              else if (vFileExt.equalsIgnoreCase(".TIF") || vFileExt.equalsIgnoreCase(".TIFF"))
                   format                                        = "TIFF";
              else if (vFileExt.equalsIgnoreCase(".GIF"))
                   format                                        = "JPEG";
              else if (vFileExt.equalsIgnoreCase(".BMP"))
                   format                                        = "BMP";
              else
                   format                                        = "0";
              // update the width & height
              if (format != "0")
                   try
                        //Opens the image
                        RenderedImage src                    = JAI.create("fileload","d:\\servers\\tomcat\\webapps\\jsp\\upload\\" + vFileName);
                        width                                   = src.getWidth();
                        height                                   = src.getHeight();
                        java.io.File imageFile               = new java.io.File("d:\\servers\\tomcat\\webapps\\jsp\\upload\\" + vFileName);
                        InputStream is                         = new FileInputStream(imageFile);
                        //build the query
                        String qryUpdate                    = "UPDATE FileStore SET Width = " + width + ", Height = " + height + " WHERE FileID = " + vFileID;
                        //execute the query
                        ResultSet rsUpdate                    = sqlUpdate.executeQuery(qryUpdate);
                        %>[<%=width%>x<%=height%>:<%=vFileID%>:<%=qryUpdate%>]<BR><%
                   catch(Exception e)
                        {out.println("An error occurs : " + e.toString());}               
              count++;          
         //rsUpdate.close();
         sqlUpdate.close();
    %>
    <HTML>
    <HEAD>
         <TITLE>Repair Files</TITLE>
    </HEAD>
    <BODY>
    <%=count%> files updated in the database.
    </BODY>
    </HTML>

    BTW - I also tried this with a prepared statment query... no good.

  • How to get an UPDATABLE REF CURSOR from the STORED PROCEDURE

    using C# with
    ORACLE OLE DB version: 9.0.0.1
    ADO version: 2.7
    I returns a REF CURSOR from a stored procedure seems like:
    type TCursor is ref cursor;
    procedure test_out_cursor(p_Dummy in varchar, p_Cur out TCursor) is
    begin
         open p_Cur for select * from DUAL;
    end;
    I create an ADO Command object and set
    cmd.Properties["IRowsetChange"].Value = true;
    cmd.Properties["Updatability"].Value = 7;
    cmd.Properties["PLSQLRSet"].Value = 1;
    cmd.CommandText = "{CALL OXSYS.TEST.TEST_OUT_CURSOR(?)}";
    and I use a Recordset object to open it:
    rs.Open(cmd, Missing.Value,
    ADODB.CursorTypeEnum.adOpenStatic,
    ADODB.LockTypeEnum.adLockBatchOptimistic,
    (int) ADODB.CommandTypeEnum.adCmdText +
    (int) ADODB.ExecuteOptionEnum.adOptionUnspecified);
    The rs can be opened but can NOT be updated!
    I saved the recordset into a XML file and there's no
    rs:baseschema/rs:basetable/rs:basecolumn
    attributes for "s:AttributeType" element.
    Any one have idea about this?
    thanks very much

    It is not possible through ADO/OLEDB.
    Try ODP.NET currently in Beta, it is possible to update DataSet created with refcursors. You need to specify your custom SQL or SP to send update/insert/delete.
    As I remember there is a sample with ODP.NET Beta 1 just doing this.

  • Changes in Picturealbums from Iphoto is not updated within Itunes/ATV

    I would like to choose what picture albums from IPhoto that should be synchronized to AppleTV. But the AppleTV tab within Itunes does not update with the new albums that I have created in Iphoto. Anyone has an idea how I can force Itunes to refresh the list of shared albums from Iphoto ?
    I've tried reboot everything there is after I made my changes

    Welcome to the  Discussion Forums.
    Could there be any photos with file types not supported by the tv in these albums. Or any illegal characters such as "/" in any of the album names, file names or even keywords or descriptions. Have you tried rebuilding your iphoto library.

  • For Update In Cursor

    cursor t_c is
    select a.f1, b.f2, c.f3
    from A, B, C
    where A.id = B.id
    and A.id = C.id
    for update B.f5, B.f6, B.f7, C.f8, C.f9;
    for item in t_c
    loop
    update B
    set f5 = something,
    f6 = something,
    f7 = something;
    where current of t_c;
    update C
    set f8 = something,
    f9 = something;
    where current of t_c;
    end loop;
    my selection statement is fine.
    but the update statement is not working, as i end
    up with the original values.
    when i take out the update statement for table C
    (including the 'for update' section), the update
    for table B works fine.
    i can't see any mistakes from my script.
    could anyone please point out?
    thanks ...

    have you tried to rewrite the cursor to not use a for update of,
    but to use the rownum instead?
    cursor t_c is
    select a.f1, b.f2, c.f3
    from A, B, C
    where A.id = B.id
    and A.id = C.id
    for update B.f5, B.f6, B.f7, C.f8, C.f9;
    for item in t_c
    loop
    update B
    set f5 = something,
    f6 = something,
    f7 = something;
    where current of t_c;
    update C
    set f8 = something,
    f9 = something;
    where current of t_c;
    end loop;
    my selection statement is fine.
    but the update statement is not working, as i end
    up with the original values.
    when i take out the update statement for table C
    (including the 'for update' section), the update
    for table B works fine.
    i can't see any mistakes from my script.
    could anyone please point out?
    thanks ...

  • Commit after every three UPDATEs in CURSOR FOR loop

    DB Version: 11g
    I know that experts in here despise the concept of COMMITing inside loop.
    But most of the UPDATEs being fired by the code below are updating around 1 million records and it is breaking our UNDO tablespace.
    begin
    for rec in
          (select owner,table_name,column_name 
          from dba_tab_cols where column_name like 'ABCD%' and owner = p_schema_name)
          loop
            begin
            execute immediate 'update '||rec.owner||'.'||rec.table_name||' set '||rec.column_name|| ' = '''||rec.owner||'';
            end;
          end loop;
    end;We are not expecting ORA-01555 error as these are just batch updates.
    I was thinking of implementing something like
    FOR i IN 1..myarray.count
    LOOP
                             DBMS_OUTPUT.PUT_LINE('event_key at' || i || ' is: ' || myarray(i));
                             INSERT INTO emp
                             empid,
                             event_id,
                             dept,
                             event_key
                             VALUES
                             v_empid,
                             3423,
                             p_dept,
                             myarray(i)
                             if(MOD(i, p_CommitFreq) = 0)  --- When the loop counter becomes fully divisible by p_commit_frequency, it COMMITs
                             then
                                       commit;
                             end if;
    END LOOP;(Found from an OTN thread)
    But i don't know how to access the loop counter value in a CURSOR FOR loop.

    To be fair, what is really despised is code that takes an operation that could have been performed in a single SQL statement and steps through it in the slowest possible way, committing pointlessly as it goes along (exactly like the example you found). Your original version doesn't do that - it looks more like some sort of one-off migration where you have to set every value of every column that matches some naming standard pattern to a constant. If that's the case, and if there are huge volumes involved and you can't simply add a bit more undo, then I don't see much wrong with committing after each update, especially if you track how far you've got so you can restart cleanly if it fails.
    If you really want an incrementing counter in an unnamed cursor, apart from the explicit variable others have suggested, you could add rownum to the cursor (alias it to something that isn't an Oracle keyword), although it could complicate the ORDER BY that you might be considering for the restart logic. You could have that instead of the redundant 'owner' column in your example which is always the same as the constant p_schema_name.
    Another approach would be to keep track of SQL%ROWCOUNT after each update by adding it to a variable, and commit when the total number of rows updated so far reaches, say, a million.
    Could the generated statement use a WHERE clause, or does it really have to update every row in every table it finds?
    Could there be more than one column to update per table? If so it might be worth generating one multi-column update statement per table, although it'll complicate things a bit.
    btw you don't need the inner 'begin' and 'end' keywords, and whoever supplied the MOD example you found should know that three or four spaces usually make a good indent and you don't need brackets around IF conditions.

  • PL/SQL Using Cursor to Update Another Cursor

    Dear all,
    i am trying to do the below process ..i just wrote this code as an example ..can anyone give me idea how to acheive
    this .. i attached the error msg i am getting below ..
    CREATE OR REPLACE PROCEDURE EMP_COMPARE
    AS
    CURSOR c_emp_err
    IS
    SELECT EMPNO FROM EMP_ERR;
    CURSOR c_emp_cur
    IS
    SELECT EMPNO,FRST_NAME,LAST_NAME
    FROM EMP WHERE DEPTNO=20;
    BEGIN
    FOR r_emp IN c_emp_cur
    LOOP
    IF r_emp.EMPNO NOT IN(c_emp_err) --DONT PICK THE EMP'S WHICH ARE IN ERROR TABLE
    THEN
    UPDATE EMP SET APPLY_DATE=SYSDATE
    WHERE EMPNO=r_emp.EMPNO;
    END IF;
    END LOOP;
    END;
    ERR: PLS-00320: the declaration of the type of this expression is incomplete or malformed
    Thanks in Advance ...

    Hi,
    I see.
    My answer still applies: don't use cursors if you don't have to. Look for a way to do what you need to using just SQL statements.
    If you really do have to use two cursors, where some values in one are taken from the other, you can have nested cursors.
    For exampe, using scott's tables, say you want to give a 10% salaray raise to everyone in any department based in a given city.
    You could have two cursors:
    (1) find each department based in the right city
    (2) find each employee in the current department from (1)
    CREATE OR REPLACE PROCEDURE     slow_update
    (     in_city_name     IN     VARCHAR2
    AS
         CURSOR     dept_csr     (target_loc     VARCHAR2)
         IS     SELECT     deptno
              FROM     dept
              WHERE     loc     = UPPER (target_loc);
         CURSOR     emp_csr     (target_deptno     NUMBER)
         IS     SELECT     empno
              FROM     emp
              WHERE     deptno     = target_deptno;
    BEGIN
         FOR     dept_rec IN dept_csr (in_city_name)
         LOOP
              FOR     emp_rec IN emp_csr (dept_rec.deptno)
              LOOP
                   UPDATE     emp
                   SET     sal     = sal * 1.1
                   WHERE     empno     = emp_rec.empno;
              END LOOP;
         END LOOP;
    END     slow_update;Notice how I used parameters in the cursors.
    You would run the procedure like this:
    EXECUTE  slow_update ('Dallas');Repeat: This is for demonstration purposes only.
    The smart way to do such an UPDATE doesn't require cursors or PL/SQL:
    UPDATE     emp
    SET     sal     = sal * 1.1
    WHERE     deptno     IN     (
                   SELECT     deptno
                   FROM     dept
                   WHERE     loc     = UPPER (:target_city_name)
                   );

  • Dynamic update  of cursor records when table gets updated

    Hi,
    I am having a table with 4 columns as mentioned below
    For a particular prod the value greater less than 5 should be rounded to 5 and value greater than 5 should be rounded to 10. And the rounded quantity should be adjusted with in a product starting with orderby of rank with in a prod else leave it
    Table1
    Col1     prod     value1     rank
    1     A     2     1          
    2     A     6     2
    3     A     5     3
    4     B     6     1
    5     B     3     2
    6     B     7     3
    7     C     4     1
    8     C     2     2
    9     C     1     3
    10     C     7     4
    Output
    Col1     prod     value1     rank
    1     A     5     1          
    2     A     5     2
    3     A     3     3
    4     B     10     1
    5     B     0     2
    6     B     6     3
    7     C     5     1
    8     C     5     2
    9     C     0     3
    10     C     4     4
    I have taken all the records in to a cursor. Once after rounding the request of 1st rank and adjusting the values of next rank is done. Trying to round the value for 2nd rank as done for 1st rank. Its not taking the recently updated value(i,e adjusted value in rounding of 1st rank).
    This is becoz of using a cursor having a value which is of old value.
    Is there any way to handle such scenario's where cursor records gets dynamically updated when a table record is updated.
    Any help really appreciated.
    Thanks in Advance

    Hi,
    Below is the scenario. Which I am looking for.
    ITEM_ID(A)
    ITEM_ID Value Date
    A          3     D1     
    A          5     D2
    A          3     D3     
    A          5     D4
    A          3     D5     
    A          5     D6
    Rounding for Item A has to be done for the rows less then D2 and rounding value is
    x and value adjustment to be done from very next row.
    --For record D1 rounding to be done and value adjustment is to be done from D2 to till the end untill the adjustment value is 0.
    --For record D2 (updated value has to be taken from rounding which updated in D1 row rounding) and the adjustment has to be done from very next row D3 to till the end or adjustment value is o.
    --For D3 row onwards no rounding has to be done.
    ITEM_ID(B)
    B          7     D1     
    B          8     D2
    B          9     D3     
    B          5     D4
    B          4     D5     
    B          3     D6
    Rounding for Item has to be done for the rows less then D3 and rounding value is
    y and value adjustment to be done from very next row.
    --For record D1 rounding to be done and value adjustment is to be done from D2 to till the end untill the adjustment value is 0.
    --For record D2 (updated value has to be taken from rounding which updated in D1 row rounding) and the adjustment has to be done from very next row D3 to till the end or adjustment value is o.
    --For record D3 (updated value has to be taken from rounding which updated in D2 row rounding) and the adjustment has to be done from very next row D4 to till the end or adjustment value is o.
    --For D4 row onwards no rounding has to be done.
    Thanks in Advance
    Edited by: unique on Apr 16, 2010 11:20 PM

  • Writting exception within cursor for loop

    I have two cursor for loop as
    for rec1 in () loop --loop 1
    for rec2 in () loop --loop2
    <statements>
    end loop;
    end loop
    Now I want to handle exception within my second for loop so that after terminating the loop it will again go to the first loop...
    How to do it ? Please help......

    you may
    BEGIN
       FOR rec1 IN your_select1
       LOOP                                                              --loop 1
          BEGIN
             FOR rec2 IN your_select2
             LOOP                                                         --loop2
                statements;
             END LOOP;
          EXCEPTION
             WHEN OTHERS
             THEN
                log_error;
          END;
       END LOOP;
    END;or ...depending on your exact needs:
    BEGIN
       FOR rec1 IN your_select1
       LOOP                                                              --loop 1
          FOR rec2 IN your_select2
          LOOP
             BEGIN                                                        --loop2
                statements;
             EXCEPTION
                WHEN OTHERS
                THEN
                   log_error;
             END;
          END LOOP;
       END LOOP;
    END;

  • 10.4.11 update and cursor jump

    This problem occurs in Thunderbird, MS Word, Allgood Solitaire, Firefox, and so on.
    I let Software Update download the 10.4.11 patch. I installed, rebooted etc. The cursor jumps when I use the trackpad, and also acts as double-click when I mouse-over a link, or hover over the deck in Solitaire. Action in Word was especially annoying -- cursor would select entire paragraphs or lines as I typed. I have to keep moving the cursor out of the window. The behavior for the window reminds me of focus feature in window under X-windows or Solaris, but here I can't tu
    rn it off.so
    Cursor behavior improved somewhat after running Disk Utility and fixing permissions.

    I think 10.4.11 mistakenly sets Trackpad Gestures/Clicking as a default.
    Here's the solution:
    System Preferences -> Keyboard & Mouse -> Trackpad
    Under Trackpad Gestures, un-select Clicking.
    Good luck!

  • PROBLUM IN UPDATE WITH CURSOR

    Hi All
    I have a table a
    SQL> select * from a;
    A                   B          C          D
    vikas               6        100          0
    vikas               6        101          0
    manoj             500        102          0
    manoj               6        103          0
    p                 400        104          0
    VIKAS               6        105          0and i wrote a cursor to update the column d either by b or c whichever is greater
    DECLARE
             ae NUMBER;
             ad number;
             dd number;
             cursor c1 is select b,c from a ;
    BEGIN
           open c1;
    LOOP
           fetch c1 into ae,ad;
           IF ae>ad THEN
              update A
              set d=ae;
           ELSE
              UPDATE A
              set d=ad;
           END IF;
                 exit when c1%notfound;
    END LOOP;
            CLOSE c1;
        END;BUT the result is
    d become 105 for all rows
    Please Guide
    Thanks And Regards
    vikas

    Hi Try this
    This this the table data
    A     B     C     D
    vikas     6     100     0
    vike     6     101     0
    manoj 500 102     0
    mnj     6     103     0
    P     6     104     0
    VIKAS 400 105     0
    This is the block
    declare
    aa t1.a%type;
    bb t1.b%type;
    cc t1.c%type;
    dd t1.b%type;
    v_number number :=0;
    cursor c1 is select a,b,c from t1;
    begin
    open c1;
    loop
    fetch c1 into aa,bb,cc;
    if bb < cc then
    update t1 set d=cc where a=aa;
    else
    update t1 set d=bb where a=aa;
    v_number :=V_number+1;
    commit;
    end if;
    exit when c1%notfound;
    end loop;
    close c1;
    commit;
    end;
    After execution the result is
    A     B     C     D
    vikas     6     100     100
    vike     6     101     101
    manoj 500     102     500
    mnj     6     103     103
    P     6     104     104
    VIKAS 400     105     400
    Hopes this helps you
    thanks & Regards
    Srikkanth.M
    Edited by: Srikkanth.M on May 11, 2011 4:22 PM

Maybe you are looking for

  • Preenchimento dos campos cEAN e cEANTrib no XML da NFE

    Boa tarde,    A partir de 1º de julho de 2011, segundo o Ajuste SINIEF n. 16, de 16/12/2010, será obrigatório O preenchimento dos campos cEAN e cEANTrib com o GTIN (Numeração Global de Item Comercial) caso ele exista. A diferença entre os campos é qu

  • Photoshop (12) editor doesn't work in iPhoto?

    In advanced preferences in iPhoto I indicated photos were to be edited in Photoshop Elements (12) Editor yet when I highlight a photo in iPhoto and hit edit nothing happens - I don't go to the edit function in Photoshop or in iPhoto.  I want to file

  • DPI and image quality in programs like Windows Photo Viewer

    I'll keep this as short as possible.  About 6 years ago I bought a Panasonic Lumix DMC-F28 digital camera (not DSLR).  It claims 10 MP.  After that my daughter bought a Canon Rebel (don;t know the model) which has 12 MP.  I would compare her pics wit

  • I can't create another account in Mail!

    i have an existing @mac.com email account but i want to *create another Mail account* even thought i already have a @live.com email. I use my @mac.com email for ichat already, but when i try to sign in to Mail with that same account it says it cannot

  • Vendor adress details(Email adrerss of other communication tab)

    Hi All, I need email addresses maintained in Other communication tab of a vendor . I will be thankful if somebody will guide me the table or function module that will fetch other communication tab details for me. Thanks.