FOR the UPDATE OF table.field

Why the following does it
create table division (code varchar2(2) primary key, div_desc varchar2(20));

insert into division values ('01', 'Ninja assassins');
insert into division values ('02', 'Working for the man');


create table employees (tk number, first_name varchar2(10), last_name varchar2(10), code varchar2(2) references division(code));

insert into employees values (1, 'Chuck', 'Smith', '01');
insert into employees values (2, 'John',  'Smith', '02');

DECLARE

  CURSOR my_csr IS
    Select e.tk, e.first_name, e.last_name
    From employees e, division d
    Where e.code = d.code
      and e.code = '01'
      and e.last_name = 'Smith'
    For update;
    
    cnt_updated NUMBER;

BEGIN

  cnt_updated := 0; 

  FOR my_row IN my_csr
  LOOP

    Update employees
    Set last_name = 'Forbes'
    Where current of my_csr;
    
    cnt_updated := cnt_updated + SQL%ROWCOUNT;
    dbms_output.put_line('You updated '||cnt_updated||' records');

  END LOOP;
END;
but just add the clause "for update" allows to make the point?
DECLARE

  CURSOR my_csr IS
    Select e.tk, e.first_name, e.last_name
    From employees e, division d
    Where e.code = d.code
      and e.code = '01'
      and e.last_name = 'Smith'
    For update *of e.tk*;
We discovered this recently, and fellow developers are wondering "why?" Is there a reason documented, or is - just how it is?

Thank you
-= Chuck

of 'of the user to the database PL/SQL Oracle® reference Guide. "
"10g Release 2 (10.2):
"During the interrogation of several tables, you can use the FOR UPDATE clause to limit the line blocking to specific tables. Rows in a table are locked unless done FOR UPDATE OF clause refers to a column in the table. For example, the following query locks the rows in the employees table, but not in the departments table:

DECLARE
CURSOR c1 IS SELECT last_name, department_name FROM employees, departments
WHERE employees.department_id = departments.department_id
AND job_id = "SA_MAN."
FOR the UPDATE OF treatment; »

a little demo:

SQL> select * from v$version;

BANNER
-------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE    11.1.0.6.0      Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production

  1   DECLARE
  2     CURSOR my_csr IS
  3       Select e.tk, e.first_name, e.last_name, e.rowid
  4       From employees_t e, division d
  5       Where e.code = d.code
  6         and e.code = '01'
  7         and e.last_name = 'Smith'
  8       For update of e.tk;
  9       cnt_updated NUMBER;
 10   BEGIN
 11     cnt_updated := 0;
 12     FOR my_row IN my_csr
 13     LOOP
 14       Update employees_t
 15       Set last_name = 'Forbes'
 16       Where current of my_csr;
 17       cnt_updated := cnt_updated + SQL%ROWCOUNT;
 18       dbms_output.put_line('You updated '||cnt_updated||' records');
 19     END LOOP;
 20*  END;
SQL> /
You updated 1 records

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

  1   DECLARE
  2     CURSOR my_csr IS
  3       Select e.tk, e.first_name, e.last_name, e.rowid
  4       From employees_t e, division d
  5       Where e.code = d.code
  6         and e.code = '01'
  7         and e.last_name = 'Smith'
  8       For update;-- of e.tk;
  9       cnt_updated NUMBER;
 10   BEGIN
 11     cnt_updated := 0;
 12     FOR my_row IN my_csr
 13     LOOP
 14       Update employees_t
 15       Set last_name = 'Forbes'
 16       Where current of my_csr;
 17       cnt_updated := cnt_updated + SQL%ROWCOUNT;
 18       dbms_output.put_line('You updated '||cnt_updated||' records');
 19     END LOOP;
 20*  END;
SQL> /

PL/SQL procedure successfully completed.

Amiel

Tags: Database

Similar Questions

  • SELECT... FOR the vs LOCK TABLE of UPDATE... MODE OF LINE SHARING IN

    Hello
    In practice, what is the difference between the two versions of line locking methods...?
    In my case, I need to block only the lines that will be extracted by a cursor... but because the select stmt using the sum aggregate function... I can't use the format:
    cursor c1 
    is
      select x , y ,sum(a)
        from d
       group by x,y
        for update;
    So, the only alternative I have (I think) is the "LOCK TABLE d PART of the LINE in MODE.
    Is the above correct... to obtain row locks the same as the "select" for the update?

    Note: I use Db10g v.2
    Thank you
    SIM

    When you draw a select... Updated, it's immediately another session in standby mode until you release the lock.
    TABLE LOCK is a bit different, the other session will run in standby mode after an UPDATE statement. If the other session, run an UPDATE statement before your own session, you will wait for the release lock.
    So, it's different behaviors. Conclusion: they are not same.

    Nicolas.

  • How can I write the trigger for the global temporary Table

    Hi Grus,
    How can I write the trigger for the global temporary Table.

    I created the TWG with trigger using the script below.


    CREATE A GLOBAL_TEMP GLOBAL TEMPORARY TABLE
    (
    EMP_C_NAME VARCHAR2 (20 BYTE)
    )
    ON COMMIT PRESERVE ROWS;


    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE, UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    BEGIN
    INSERT INTO VALUES EMPNAME (: OLD.) EMP_C_NAME);
    END;
    /


    trigger was created successfully, but her would not insert EMPNAME Table...

    Please guide if mistaken or not? If not wanting to give a correct syntax with example


    Thanks in advance,
    Arun M M
    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    
    you are referencing old value in insert stmt.
    
    BEGIN
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    END;
    

    then run your app, it works very well...

    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    (
    EMP_C_NAME VARCHAR2(20 BYTE)
    )
    ON COMMIT PRESERVE ROWS;
    
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    dbms_output.put_line(:OLD.EMP_C_NAME);
    END;
    /
    
    create table EMPNAME as select * from GLOBAL_TEMP where 1=2
    
    insert into GLOBAL_TEMP values('fgfdgd');
    commit;
    select * from GLOBAL_TEMP;
    select * from EMPNAME;
    
    output:
    1 rows inserted
    commit succeeded.
    EMP_C_NAME
    --------------------
    fgfdgd               
    
    1 rows selected
    
    EMP_C_NAME
    --------------------
    fgfdgd               
    
    1 rows selected
    

    He got Arun

    Published by: OraclePLSQL on December 28, 2010 18:07

  • I have a MBP of 2009 end. I updated the material to 8 GB of ram with an SSD of 240gig. I want to run the new OSX, but is not on the list approved for the update. Anyone know why?

    I have a MBP of 2009 end. I updated the material to 8 GB of ram with an SSD of 240gig. I want to run the new OSX, but is not on the list approved for the update. Anyone know why?

    It is a decision that was made by Apple.  El Capitan is the newest OSX that will support a 2009 MBP.

    This is not uncommon.  My 2006 MBP came with Tiger, but is limited to OSX Snow Leopard.

    Old hardware ends up by becoming obsolete with newer technology.

    Ciao.

  • I can't get rid of thanks for the update of firefox or modules at startup

    Whenever I run Firefox, in addition to my home page, I get "Thanks for the update" pages of Mozilla, colorful tabs, No Script and Undo Closed Tabs Button. I tried all the usual methods to get rid of them (reset the home page, and al.) and nothing does not remove the Add-ons (and it does not work for the Mozilla page!). It is not only annoying, but it significantly slows down Firefox the.

    I like Firefox and use since it began and I don't want to stop now, but this inability to control it is frustrating and, frankly, disappointing. I hope that the tendency to become more like other browsers does not speed; for many users, the fact that Firefox was not like the others is what has him us in the first place.

    I'd appreciate any help to solve my dilemma.

    Hello, this can happen when firefox is not able to correctly save preferences in the profile folder. Please try this: click on the menu button, then click on Help (?) > troubleshooting information > profile folder - 'show the file'. then a new window will open. in this search on a file named user.js window (it can be used to overwrite your custom settings). where it is present, delete or rename this file and then restart firefox.

    For more information and other steps, please also see: How to fix preferences that will not save

  • Satellite 4090 BIOS number - message "ready for the update BIOS... ' appears

    Hi all! Excuse my poor English because I'm french.

    A friend gives me his cell phone (a Satellite exactly 4090CDS) because he had a problem.
    In fact, the problem is that when I turn on the computer, I have a single message (not even the toshiba red logo) that is "ready for the update of the BIOS. Place the BIOS update floppy in the drive and press any key when you are ready to move forward."

    So I go to the french site of toshiba, in the BIOS download, I find that I must download this update: http://support.toshiba-tro.de/tools/bios/satellite/4030-4060-100/bios_820.zip

    OK, I download and unpack it on a floppy disk and I start the laptop with the disjette, he said that the update has been successful and it restarts automatically.
    This time, the Red toshiba logo appears, but then I have a black screen with a message:

    Bad checksum (CMOS) *.
    Check the system. Then press the [F1] key.

    And after that, I can't do anything, not even, press F1. If I restart the laptop, I myself meet once more with the first message «Ready for the update of the BIOS...» "and it's still the same.

    If someone could help me understand what the problem is, that would be fine.
    Thank you.

    Bastien.

    It sounds as if your CMOS chip has a problem. It is possible to s that the CMOS battery has failed and the BIOS settings are lost.
    Maybe the RTC battery is empty. In this case, you should connect the AC adapter to charge the battery of the CCF.
    Please note that the RTC battery (CMOS battery) can be fluffed once the main laptop battery has been recharged. In this case, the charge process may take several hours.

    But if after this long process of load this message appears again then I guess the battery is dead.
    I suggest that you only contact your ASP closest to get your phone checked.

  • When I updated the shock of the clans for my daughter on his iPad, it has its own apple ID. and iCloud, my ID apple came on his id for the update, where it has its own apple ID now. Please can someone tell me why the update came not through its id.

    When I updated the shock of the clans for my daughter on his iPad, it has its own apple ID. and iCloud, my ID apple came on his id for the update, where it has its own apple ID now. Please can someone tell me why the update came not through its ID thanks

    It seems that if the application has been downloaded on his iPad while it is connected to your Apple ID. If so, he'll always want to be updated with your Apple ID.

    You must remove the application from his iPad and then download it again while it is connected to its own code of Apple.

  • "Look for the update is not available at this time. Try again later. »

    I use a Photon on the Sprint 3 G EVDO network. When I open the settings app and click the option to check the software update from Motorola, the following screen appears: "look for the update is not available at this time. Try again later. "When I'm on a Wi - Fi network, a similar message appears (no screenshots):" your device is up to date! No update is necessary at this time. "Can someone please provide more information about what exactly is the message originally in my screenshot below to appear? Thank you for your help.

    If you go to Menu > settings > Data Manager > delivery data > social apps > Sync only over wifi. If this box is checked, and that you are connected to 3g / 4g and no wifi, you will get the server is not available because you are not connected to our servers. As soon as you connect to the wifi it reconnect to our servers and see no upgrade is available or an update if one is available. Your phone works as expected.

    Mark

    Support Forums Manager

  • The error code is 'Windows Update error 80072ee2'. SO how to fix in a step-by-step fashion. I added the site proposed for the update in my antivirus while list.

    The error code is 'Windows Update error 80072ee2'. SO how to fix in a step-by-step fashion. I added the site proposed for the update in my antivirus while list.

    Hi Sarma_RN,

    1. When you receive the error message?

    2. update you are trying to install?

    3. When was the last time you were able to install updates?

    If Windows Update, error 80072ee2 during updates, the Windows Update servers may experience an unusually high number of requests for updates. Close Windows Update, wait 10 to 15 minutes, and then run Windows Update again. Alternatively, you can wait for automatic update of Windows run at its next scheduled time.

    These errors can occur caused by one of the following problems:

    • Applications or processes that interfere with Internet communications
    • Problems on your computer
    • Strong Internet activity
    • Recoverable database errors

    See the Microsoft article and try the steps mentioned below.

    You may encounter temporary connection related errors when you use Windows Update or Microsoft Update to install updates

    http://support.Microsoft.com/kb/836941

    I hope this helps!

    Halima S - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • I am running Windows 7 and noticed that Windows updates did not work. The parameters are defined for the update every day. When I went to update manually returned an error WindowsUpdate_80070017. MSFT site was no help. Any recommendations?

    I am running Windows 7 and noticed that Windows updates did not work. The parameters are defined for the update every day. When I went to update manually returned an error WindowsUpdate_80070017.  MSFT site was no help. Any recommendations?

    Since neither updates Jan - 10 have installed, I'm going to hand you Support MS in the hope that they can resolve the problem. See below.

    That being said, is an interpretation of the 80070017 - cyclic redundancy check error "a device attached to the system does not work," which suggests that a hardware problem might be the cause of the error (although I must say that it is a very low possibility in this case).

    Good luck!

    =======================

    Visit the Microsoft Solution Center and antivirus security for resources and tools to keep your PC safe and healthy. If you have problems with the installation of the update itself, visit the Microsoft Update Support for resources and tools to keep your PC updated with the latest updates.

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • Look for the update 80010108 error code

    I am running Windows Vista 2006 version on my computer. Now I am trying to upgrade my computer and this error code 80010108 has to happen. How do I do?

    Hello

    1 during how long have you had the problem?
    2. don't you make changes before the problem?

    Look for the updates failed in the update history.

    I suggest that you put your computer in a clean boot State, then try to install the updates

     
    Note: Restart your computer as usual by following step 7

    See also:
     
    You cannot install some programs or updates
    http://support.Microsoft.com/kb/822798

  • FRM - 40603:Records is no longer reserved for the update. Query for changes

    Hi I have a form that has been developing 6i and upgraded to 11g form work well in 6i, but when I try to do the same function in 11g get this error

    FRM - 40603:Records is no longer reserved for the update. Query for changes
    When I commit this execute_query (for_update); It is the form to clear values when it loads, the error comes when I try to delete

    How can I do this

    Action: If you want to change the block, you will need to re - interview.

    Captureerror3.PNG

    I use When-Timer-Expired (WTE) trigger

    You have a 'relationship' defined between the blocks of your master and detail? If so, simply update your master block and the block of details will automatically be re-interviewed. If you cannot use a relationship, then you can use can create a timer in the trigger that updates the database, then in the trigger When-Timer-Expired (WTE) you can go to the retail block and run a query. For example: / * the sample on change trigger * /.

    DECLARE
      timer_id  TIMER;
    BEGIN
    ....your code here that performs the update....
      /* Now create an instance of a timer */
      timer_id := Create_Timer ('upd_detail',1,NO_REPEAT);
    END;/* Sample Form Level When-Timer-Expired trigger */
    DECLARE
      timer_id  TIMER;
    BEGIN
      -- Find the timer first
      timer_id := FIND_TIMER('upd_detail');
      IF NOT ID_NULL(timer_id) THEN
          GO_BLOCK('DETAIL_BLOCK');
          Execute_Query;
      END IF;
    END;
    
  • I have windows 8 in my computer toshiba laptop. After you set up windows for the updates it says «restoration of the changes...» Impossible to install the important updates'... What do I do?

    I have windows 8 in my computer toshiba laptop. After you set up windows for the updates it says «restoration of the changes...» Impossible to install the important updates'... What do I do?

    Hello

    Please, try the suggestions mentioned here and see if they help you:

    http://www.thewindowsclub.com/failure-configuring-Windows-updates

    Hope this helps, good luck :)

  • I installed Lightroom 4.4, serial number [removed-kglad]. Is there an Option for the update of Lightroom 6?

    I installed Lightroom 4.4, serial number [removed-kglad]. Is there an Option for the update of Lightroom 6?

    major version changes are paid upgrades, free updates not.

    Products

  • Hi, I installed Windows 10 on my II Surface Pro today and I lost my ADobe Acrobat program, installed, but it took a key no. from a previous version. My no. is only for the update to Acrobat XI. Thank you

    Hi, I installed Windows 10 on my II Surface Pro today and I lost my ADobe Acrobat program, installed, but it took a key no. from a previous version. My no. is only for the update to Acrobat XI. Thank you

    Hey Samy,

    Please read: error: "this serial number is not for a product calling it" | CS6 cs5, CS5.5,

    Hope that helps!

    Kind regards

    Sheena

Maybe you are looking for

  • Answer the questions? /??

    could someone tell me how to look up a question to which you have claimed in the past to see if it has been answered here? Thank you

  • Cannot create the folder on the storage device

    My flash player works well, but lately, I can't create a folder: it simply indicates: cannot create the folder?

  • Err1err3 Boot failure Insert system disk and press enter

    OK lets see if you can crack this for me, it started a week ago for me. If I leave my computer on as usual, he would go on the eve, duh. BUT now it would not start up instead of this I have a black screen and reboot I go to the blue HP screen with fo

  • SVG showing is not on my screen, but the text it is.

    HelloDetermined to get this SVG of a logo to display. Don't know what the problem is that I'm not on the screen. In Illustrator, I used "recorded under" and chose .svg. Should I have used 'export' instead? (it's an idea)< class header = "header image

  • Error tracking in ID CC2014

    Having a serious problem with follow-up of errors randomly in InDesign CC2014. Sometimes the documents will be displayed with the text lines that seem to have lost all followed - the text appear just physically a line in a text box.Examples:How those