Use the currval whenever I need it

Hello,
I defined a sequence : MySequence_seq
I defined 2 Procedures :
1/ Initproc encloses a MySequence_seq.nextval
2/ GetProc encloses a MySequence_seq.currval
But when I call GetProc I get a "ORA-08002 :sequence SEQ1.CURRVAL is not yet defined in this session".
I thought one nextval was enough and then I could invoke a currval whenever I want.
The same issue with SQL*PLUS : if I connect call a nextval and then a currval it works. If I close then re-connect and call currval it doesn't work.
My need : having an absolute unique ID I can get whenever I want without performing a nextval (which will increments the ID) anytime I want the last value generated. Perhaps it's not possible with a sequence...so should I manage on my own (PL/SQL + a given field of my table storing this last value) ?
Any help greatly appreciated.
Jerome.

The manual says From: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96536/ch2123.htm#1300856
"Table: USER_SEQUENCES/ALL_SEQUENCES
LAST_NUMBER : Last sequence number written to disk. If a sequence uses caching, the number written to disk is the last number placed in the sequence cache. This number is likely to be greater than the last sequence number that was used."
This mean that the numbers X obtained by the proposed method, even if apparently persistent through sessions, are NOT a replacement for the number Y obtained from sequence.CURRVAL, and therefore cannot fulfill the function requested in the thread, because:
1. they are not unique: you can get same X for different Y
2. they are not stable: you can get different X for same Y (when X is read more than one time)
You can see this from the following test:
CREATE OR REPLACE PROCEDURE test_seq(p_iters      NUMBER,
                                     p_sleep_time NUMBER := 0) AS
    v_seq1   NUMBER;
    v_seq10  NUMBER;
    v_seq2   NUMBER;
    v_seq20  NUMBER;
    v_seqnos NUMBER := 0;
    v_diffs1 NUMBER := 0;
    v_diffs2 NUMBER := 0;
BEGIN
    FOR i IN 1 .. p_iters LOOP
        IF MOD(i, 10) = 1 THEN
            SELECT mysequence_seq.NEXTVAL
              INTO v_seq1
              FROM dual;
            v_seqnos := v_seqnos + 1;
        END IF;
        SELECT mysequence_seq.CURRVAL,
               last_number - 1
          INTO v_seq1,
               v_seq2
          FROM user_sequences
         WHERE sequence_name = 'MYSEQUENCE_SEQ';
        IF v_seq1 <> v_seq10 AND v_seq2 = v_seq20 THEN
            v_diffs1 := v_diffs1 + 1;
        END IF;
        IF v_seq1 = v_seq10 AND v_seq2 <> v_seq20 THEN
            v_diffs2 := v_diffs2 + 1;
        END IF;
        v_seq10 := v_seq1;
        v_seq20 := v_seq2;
        dbms_lock.sleep(p_sleep_time);
    END LOOP;
    dbms_output.put_line('Sequence.CURRVAL calls: ' || p_iters);
    dbms_output.put_line('Generated sequence numbers: ' || v_seqnos);
    dbms_output.put_line('Not unique numbers: ' || v_diffs1);
    dbms_output.put_line('Not stable numbers: ' || v_diffs2);
END;
Running from session #1:
SET SERVEROUT ON
EXEC test_seq(200, 0.1);
you get:
Sequence.CURRVAL calls: 200
Generated sequence numbers: 20
Not unique numbers: 17   <<******
Not stable numbers: 15   <<******
While running in parallel from session #2 of the same user:
SET SERVEROUT OFF
EXEC test_seq(10000);
EXEC test_seq(10000);

Similar Messages

  • I have had to replace a faulty hard-drive on my imac. Some applications (incl iphoto) are telling me that my OSX (10.82?) isnt recent enough to use the application. I need 10.9. I have upgraded to Maverick but this remains the case. Any help?

    I have had to replace a faulty hard-drive on my imac. Some applications (incl iphoto) are telling me that my OSX (10.82?) isnt recent enough to use the application. I need 10.9. I have upgraded to Maverick but this remains the case. Any help?

    If your Mac is from the age of Mac OS X 10.8.2:
    How to find your Mac's model and age?
    Contact AppleCare to request the prebundled iPhoto be uploaded to the Mac App Store, or the Mac App Store support.
    This is just a user to user forum.  This link goes direct to the Apple Store support:
    http://www.apple.com/support/mac/app-store/contact.html?form=account&topic=MacAp pStoreAccountandBilling

  • Hello, I've installed Lion but now it says I can't use the Cloud as I need the Apple ID Password to use Back to My Mac. I've obtained several new Apple ID passwords which work ok on my phone but doesn't seem to be the password it's looking for?

    Hello, I've installed Lion but now it says I can't use the Cloud as I need the Apple ID Password to use Back to My Mac. I've obtained several new Apple ID passwords which work ok on my phone but doesn't seem to be the password it's looking for.Does anyone know what's needed please ??

    It's probably looking for the Apple ID & Password you used to purchase Lion, or ML as the case may be.
    Thse are the Mountain Lion forums, is that what you meant?

  • Use the sales employee, you need an HR master record

    hi:
      when I  do vpe1 in sd model ,it prompt two transport   request . 
       In order to use the sales employee, you need an HR master record. If you do not use the Human Resources application component (HR), you can transport the HR tables that you need for creating, changing  or displaying a sales employee from client 000 into the target client.
    How should i do?

    I'm moving this thread to the SD forum.... This is a funtional issue not a technical one.
    Regards
    Juan

  • I have a new iMac and want to use my HP 7300 All in One and to use the "Fax"feature I need a phone port on computer and of course, this computer does not have one.  Are there any aftermarket devices for USB to phone that would work in this case?

    I have a new iMac and want to use my HP 7300 "All in One and cannot use the fax feature because there is no phone port is there a solution for this?BACellli

    You don't need a phone port on the iMac. The HP 7300 DeskJet Pro has an internal modem, you connect the printer's modem connection directly to your phone line. Please re-read the install directions that came with the printer.

  • Please help! i have broken my iphone, screens is totally smashed and black, photos are not on my icloud on pc for some reason, how do i get them onto my icloud without being able to use the phone? despratly need to acsess these photos on my pc.

    please help, i have smashed my iphone 4 and the screen is black, but phone is still turned on and ringing. i had set it up icloud on my phone and pc before hand but not sure if i did it correctly as no photos are showing up on my pc, is there anyway i can get the photos from my phone to icloud via the pc, not being able to use the phone atall? or would i need to go on setting on the phone? please help i really need the photos of my children

    Don't try to use iCloud for this.  Instead, import them to your computer using your usb cable as explained here: http://support.apple.com/kb/HT4083.  That will import photos and videos from your camera roll.  You might also want to back it up before repairing or replacing it.  You can do this by connecting it to your computer, opening iTunes, then going to File>Devices>Back Up; and to File>Devices>Transfer Purchases.  This backup can later be restored to your repaired or replaced phone to recover your data.

  • Using the mask tool.. need help

    The StudentFilmmakers magazine has an Adobe forum with an After Effects section and we have a few questions that need answers. Here is a link to one and below is the question.
    http://www.studentfilmmakers.com/bb/showthread.php?t=4830
    "Hey! I'm experiencing After fx for the first time.... and I wonder how I use the mask tool to remove something in a movie clip.
    I have a clip with a boy jumping on a trampoline....then I want to cut out the background and insert a mountain cliff so it seems that he falls from the cliff.....
    How ?? "
    We love Adobe products and we feature film and video makers from out networking section each issue. We very much apreciaete help from professionals or knowlegable people. You are welcome to put your links in your signature and we do reward our posters and feature networkers in the magazine.

    Better answer??
    - Place the movie in the timeline creating a new composition of the size of your footage or drag it onto the "create new Comp" icon.
    - interpret your footage properly
    - use the pen tool and start to draw a mask around your jumping trampoline guy at the very first frame of your timeline
    - open the mask properties of your movie layer and click the stopwatch icon to create a keyframe for the mask shape properties
    - now move one frame forward in the timeline and readjust the mask - keyframes will be added automatically for you
    - if done, move next frame in timeline and readjust your mask
    - if done, move next frame in timeline and readjust your mask
    - if done, move next frame in timeline and readjust your mask
    - if done, move next frame in timeline and readjust your mask
    - if done, move next frame in timeline and readjust your mask
    - if done, move next frame in timeline and readjust your mask
    - ... if done with all, click the "show transparency" button of your comp window. place your mountain underneath the masked movie and you're done.
    this is called rotoscoping and makes a lot of fun.
    if your actor was shot in front of a green screen or a blue box, you could use the Ae keying plugs and make this process a lot easier, of course i would not recommend a desk lamp for lighting your scene and not a $ 100,- videocamera from Wal Mart.
    better answer?

  • Scan the mailbox Content using the exchange powershell commands (need urgent info)

    hi,
    Is there any way where in i can scan the mail content of each mailbox user and classify that these no of voice or video or text messages are there in user inbox using the powershell.
    My requirement
    1) is to collect the voice , video, text etc... messages for inbox of each exchange user. Is there any command that gives the type of message, text, voice, video, etc.?
    2) I am an administrator and i want to monitor the mailbox users and there content .Do we know whether ,this requires a login into the individual mailbox with the user credentials?
    Please reply me @ [email protected]
    Advanced thanks for your help...
    Thanks
    Shiva

    Use "search-mailbox" command to search the mailbox based on subject,date,attachement,sender etc...
    $users = Get-content "c\users.txt"
    To get the details only
    $users | SEARCH-MAILBOX –SearchQuery subject:"Payment_for_" -TargetMailbox "adminmailbox" -TargetFolder "queryfolder"-LogOnly -LogLevel Full

  • How do i start USING the application? i need step by step directions.

    Hi, I have a HP Officejet Pro 8600 e-all-in-one printer N911-a.  I would like to start using the applications installed on the printer.  HOWEVER, I do not know how to start, so that I can personalize them.  For example, how do I scan my receipts?  I have no idea how to get started.  Can someone PLEASE give me step by step directions on how to first access the application and then to personalize them and then print it?
    Thank you.

    How do I start using the reciept scanner

  • Tried to update ipad2 for the first time. now can´t use the ipad saying i need to turn off `find me`in icloud. HELP

    tried to update ipad2 for the first time. now can`t use ipad and it is saying i need to turn off `find me`in icloud. HELP

    You can access iCloud.com on a computer to turn it off.
    http://support.apple.com/kb/PH2702
    More >  http://support.apple.com/kb/HT5818

  • HT4567 I have a new iPad 2.  I also have an older Macbook Pro with Mac OS 10.5.8.  When I connect my iPad to my Mac, it says that I cannot use the iPad because I need iTunes v 7.0 or higher.  When I try to update iTunes, it says I have latest version 6.8.

    I cannot get my iPad 2 (brand new) to work with my MacBook pro.  It says I need iTunes 7.0, but when I go to  update iTunes on my MAC, it says I have teh latest version 10.6.3.  I have Mac OS 10.5.8 on my MacBook Pro.  Any help would be appreciated.  Do I need to upgrade my OS?  If so, which version?

    In order to download iTunes 10.7, which requires OS X 10.6.8, you have to buy OS X 10.6. It's available from the online Apple store, in the US by calling 800-MY-APPLE, or online here.  After OS X 10.6 installation, run Software Update until there are no more updates available, at which point you'll be at OS X 10.6.8 and can install iTunes 10.7.

  • Help. Deleted Quicktime using the Trash and I need to get it back!

    Hi,
    Quicktime was not playing .avi files so I though I'd delete it and reinstall it to clear up the problem. So I dragged Quicktime into the trash and emptied it. When I tried to reinstall it I got a message saying that Quicktime cannot be installed on this disk because Quicktime X is already present. I need to get Quicktime back, can anybody help me please?

    Extract the QuickTime X player from your Mac OS X 10.6 DVD and then run the combo updater for your Mac OS X version.
    If you want QuickTime 7, it's here.
    If you can't play a given AVI, install Perian. If you still can't play it, it probably can't be played in Mac OS X.
    (57456)

  • HT1296 I do not want to use the cloud, but I need to sync my notes with my mac pro. How do I do this?

    Prior to iOS 6, I was happily syncing my iPads and iPhone with my Mac Pro.
    This process included syncing my Notes between all of these systems.
    Now I am told that I need to use iCloud to sync my Notes. 8(
    Is there a way to sync Notes without being forced to use iCloud (this feels like a distenctly Microsoft type of change not a Steve Jobs type of Apple upgrade)

    Use a different IMAP (mail) account as described here:
    http://support.apple.com/kb/HT4191

  • I did software update for IOS 8 and my I phone 5s coming very slow while using the Internet please I need advise

    I did software update iOS 8 for my I phone 5s after That my phone coming very slow when i using internet

    Hi ..
    Reset the device:
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    If that doesn't help, tap Settings > General > Reset > Reset All Settings
    If that doesn't help, tap Settings > General > Reset > Reset Network Settings
    You will have to re enter your Wi-Fi password.
    No data is lsot due to a reset.
    If nothing above has helped, try here >  iOS: Troubleshooting Wi-Fi networks and connections

  • Someone else signed in to their App Store on my iPad and now I can't get it to clear to get mine. My updates are in limbo and can't use the downloads. I need help to get this resolved

    My friend used my ipad2 to log into her App Store and now I cannot get her information off mine. It keeps coming up as her and my apps are in limbo rendering them useless. I have rebooted as well as log into iTunes to manage my account. None of this helped. I don't know what to do. Can anyone help?

    Settings->App and iTunes Stores-> Apple Id ->Sign out... Sign in again with your Apple ID.

Maybe you are looking for

  • Bridge CC just got very slow

    I am a very old and experienced Ps/Br professional, but can't get around this. My Bridge CC (on a very nice and fast quad core Windows 7 PC), at some point became very slow. Even in the Essentials layout, just going through the thumbnails (already 10

  • Keynote file from 6.5.2 won't open in either Keynote 6.2 or Keynote

    Hello, I'm having problems opening Keynote (.key) files sent from a colleague.  I've tried to open the file in Keynote 6.2, but get the error ""File.key" can't be opened" and in Keynote 5.3, but get the error "Unable to open "File.key" because it isn

  • Redirect based on source IP address????

    I have a site that I don't want our competitors to view! By tracking code, I have managed to obtain their source IP addresses. After looking around, there is a .php solution to my problem but my host is not well suited to .php files (although it does

  • Shortcut Remapping: Show Current Song

    I've been able to navigate to the currently paying song just fine. But one of my FAVORITE shortcuts in iTunes is Cmd-L, Show Current Song. It shows me the song that is playing, in whatever venue it is playing it in, be it playlist or album or whateve

  • Firefox doesn't respond when opening a new tab until the page loads completely

    When I open a page in a new tab, Firefox freezes until the new page loads completely. I can't switch tabs or do anything. It then works normally. Older versions of Firefox did not have this problem; it only started after I updated a few months ago. W