Behaviour of CurrVal - can anyone explain this?

Hi All,
I am expiriencing some "strange" behaviour of CurrVal.
I will try to represent it with simple expample.
Let's have one table and one sequence:
create table TestCurrVal (A number, b number);
create sequence SeqTestCurrVal start with 1;and some sample data in the table
insert into TestCurrVal(A, B) VALUES (1,1);
insert into TestCurrVal(A, B) VALUES (1,2);
insert into TestCurrVal(A, B) VALUES (2,1);What I want to do is to select all rows from TestCurrVal table ordered by column A. If the value in this coulmn is different by previous value I want to get next sequence value and if it is the same - to use last sequence value. So expected result is the following one:
         A          B     A_PREV PROBLEMATIC_VALUE
         1          1                            1
         1          2          1                 1
         2          1          1                 2I've tried with this statement:
select a, b, a_prev,
  case
    when a_prev is null or a_prev <> a then SeqTestCurrVal.NextVal
    else SeqTestCurrVal.CurrVal
  end as problematic_value
from (
  select a,
    lag(a) over (order by a) AS a_Prev,
    b
  from TestCurrVal
  order by a
);but the result is
         A          B     A_PREV PROBLEMATIC_VALUE
         1          1                            1
         1          2          1                 2
         2          1          1                 3So it seems that on every row it update the sequence even if case clause is not performed and regardless NexVal is not reached.
Do you have any idea why this happens? ...or/and if you have any workaroud? (but without loosing sequence numbers) (...the only workaround that I have in mind is joining the statement with distinct values and generated sequences for each of those values...but maybe something simple can be introduced)
And finally some "cleanup" statements:
drop table TestCurrVal;
drop sequence SeqTestCurrVal; Best Regards
Message was edited by:
Michail

This is how SEQUENCE works. When it is in the SELECT statement, it is always incremented. http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/pseudocolumns002.htm#i1006157
"Within a single SQL statement containing a reference to NEXTVAL, Oracle increments the sequence once: <...> For each row returned by the outer query block of a SELECT statement."
A simple example:
SQL> CREATE SEQUENCE Test;
Sequence created.
SQL>
SQL> SELECT
  2     Level,
  3     CASE
  4      WHEN 1 < 3 THEN Test.NextVal
  5      ELSE Test.CurrVal
  6     END
  7     A
  8  FROM
  9     Dual
10  CONNECT BY
11     Level <=4;
     LEVEL          A
         1          1
         2          2
         3          3
         4          4
SQL>
SQL> DROP SEQUENCE Test;
Sequence dropped.Basically, Oracle detected the NEXTVAL and will now increment the record for each record. Note, that NEXTVAL and CURRVAL are equivalent in a single statement, because even NEXTVAL stays the same for each record:
SQL> CREATE SEQUENCE Test;
Sequence created.
SQL>
SQL> SELECT
  2     Level,
  3     Test.NextVal,
  4     Test.NextVal
  5  FROM
  6     Dual
  7  CONNECT BY
  8     Level <=4;
     LEVEL    NEXTVAL    NEXTVAL
         1          1          1
         2          2          2
         3          3          3
         4          4          4
SQL>
SQL> DROP SEQUENCE Test;
Sequence dropped.Therefore, it is probably better to decrement the NEXTVAL by 1 (or whatever the INCREMENT BY value is, which can be queried) and exclude the first record.
SQL> CREATE SEQUENCE Test;
Sequence created.
SQL>
SQL> WITH
  2     TestCurrVal
  3  AS
  4     (
  5      SELECT 1 A, 1 B FROM Dual UNION ALL
  6      SELECT 1 A, 2 B FROM Dual UNION ALL
  7      SELECT 2 A, 1 B FROM Dual
  8     )
  9  SELECT
10     A,
11     B,
12     A_Prev,
13     Test.NextVal
14     - CASE
15        WHEN A_Prev IS NULL AND Test.NextVal > 1 THEN 1
16        ELSE 0
17       END Problematic_Value
18  FROM
19     (
20      SELECT
21             A,
22             Lag(A) OVER (ORDER BY A) a_Prev,
23             B
24      FROM
25             TestCurrVal
26      ORDER BY
27             A
28     );
         A          B     A_PREV PROBLEMATIC_VALUE
         1          1                            1
         1          2          1                 2
         2          1          1                 3
SQL>
SQL>
SQL> DROP SEQUENCE Test;
Sequence dropped.

Similar Messages

  • Can anyone explain this to me, please. It's a static section question.

    Can anyone explain this to me, please. It's a static section question.
    I came across the following style of programming recently and I would like to know what the Static section is actually doing in the class. Thx.
    Here is the code.
    public class ClassA {
         private static Hashtable ClassAList = new Hashtable();
         private ClassB cB;
         private Vector goodLink;
         private Hashtable classCList;
         static
              ClassA cA = new ClassA();
              ClassAList.put("whatever", cA);
         public static ClassA getClassA()
              return (ClassA) ClassAList.get("whatever");

    hi,
    The static section shall be loaded before it's constructor is called. (i.e at the time of loading the class). Therefore making it available for any other objects to call.
    hope this clarifies ur question
    prasanna

  • Can anyone explain this: Numeric or Value Error Line 1

    I have a stored procedure that starts out like so:
    PROCEDURE test_proc(param1 IN VARCHAR2, param2 IN VARCHAR2, param3 OUT
    SYS_REFCURSOR) IS
    v_var varchar2(5);
    BEGIN
    SELECT * FROM. . .
    The procedure tested fine in PL/SQL Developer. When calling from
    ODP.NET like so. . .
    OracleCommand cmd = new OracleCommand("test_proc", <connection>);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("param1", "somevalue");
    cmd.Parameters.Add("param2", "XX");
    cmd.Parameters.Add("param3", OracleDbType.RefCursor,
    ParameterDirection.Output);
    DataSet ds = new DataSet();
    OracleDataAdapter da = new OracleDataAdapter(cmd);
    con.Open();
    da.fill(ds);
    con.Close();
    . . .the procedure executed as expected. If I changed the value of
    param2 to "XXX" or any value three chars long I got the "ORA-06502:
    Numeric or Value Error at Line 1" error.
    After beating my head against the wall for hours, I tried changing the
    size of v_var to 50, and the error disappeared. Mind you, the error
    was being thrown long before v_var was being set further down in the
    proc. Even more interesting is that the possible values of v_var were
    all less than 5 chars wide. Most interesting: the value of p_param2 had nothing whatever to do with v_var.
    Can anyone explain this?

    Hi,
    Is your database 9206 by chance? Re: Error ORA-06502 PL/SQL
    Cheers,
    Greg

  • Can anyone explain this query.?

    Can anyone explain this query.?
    select nvl(s.p_id,q.p_id),nvl(s.p_type,q.p_type),nvl(s.p_line,q.p_line),
    nvl(s.sales2004,0),nvl(s.sales2005,0),nvl(q.quota2004,0),nvl(q.quota2005,0)
    from sales s
    full outer join quota q on(s.p_id = q.p_id and s.p_type=q.p_type and s.p_line=q.p_line)

    from sales s full outer join quota qTable quota is outer joined to table sales , if there are no matching records in table quota then also the query retuns the sales record with null values for the corresponding quota record columns
    NVL() has been used to handle such cases

  • HT3275 Please can anyone explain this to me

    Please can anyone explain this to me - thank you -
    Time Machine couldn't complete the backup to time capsule - The backup disk image “/Volumes/Data-1/Alyson’s iMac.sparsebundle” is already in use.

    The explanation is a long standing bug in Lion and Mountain Lion, but what you might really be asking is how to fix the problem.
    Pull the power cord from the back of the Time Capsule
    Wait a few minutes
    Plug the power cord back in
    If that does not fix the problem you will need to dig deeper.  See #C12 in Pondini's excellent Time Machine - Troubleshooting.
    http://pondini.org/TM/Troubleshooting.html

  • When i go to my music and play a song it sounds like my headphones are blown but when i play songs on youtube they sound fine, can anyone explain this to me? please and thank you

    when i go to my music and play a song it sounds like my headphones are blown but when i play songs on youtube they sound fine, can anyone explain this to me? please and thank you

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Unsync all music and resync
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.      

  • TS3988 I have an icloud account and I view my mail with Mail V5.2. I recieve my email but the senders get messages saying the delivery failed. Can anyone explain this or help me.

    I have an icloud account and I view my mail with Mail V5.2. I recieve my email but the senders get messages saying the delivery failed. Can anyone explain this or help me.

    Thank you for replying.    Yes I deleted the old email address..   

  • I went to silence my iPhone 5s and had a box pop up--looked like one of those boxes telling me turning on Location Services would help--telling me I needed to change my password within 60 minutes.....I turned the phone off.  Can anyone explain this to me?

    I went to silence my iPhone 5s and had a box pop up--looked like one of those boxes telling me turning on Location Services would help--telling me I needed to change my password within 60 minutes.....I turned the phone off.  Can anyone explain this to me?

    I went to silence my iPhone 5s and had a box pop up--looked like one of those boxes telling me turning on Location Services would help--telling me I needed to change my password within 60 minutes.....I turned the phone off.  Can anyone explain this to me?

  • HT1430 I downloaded the lateest update and I can't turn off my apps like I did on 6os. The 7os is different and I can't seem to find out if apps turn off now by just closing them. Can anyone explain this to me? Please

    I downloaded the lateest update and I can't turn off my apps like I did on 6os. The 7os is different and I can't seem to find out if apps turn off now by just closing them. Can anyone explain this to me? Please

    Double tap the Home button and swipe the app preview page up
    iOS 7  also allows apps to run while they aren't open.
    You can manage these here:
    Settings > General > Background App Refresh

  • Post Moved Can anyone explain this baffling puzz...

    Post moved to Other BB Queries http://community.bt.com/t5/Other-BB-Queries/Can-anyone-explain-this-baffling-puzzle-with-BT-Total-BB...
    If you want to say thanks for a helpful answer,please click on the Ratings star on the left-hand side If the reply answers your question then please mark as ’Mark as Accepted Solution’

    I tend to think that the comments about MAC address filtering and wireless security are a bit misleading - if these things were the problem then it would not work at all as opposed to working sporadically.
    I must admit, reading your post I had exactly the same problem moving into a new house last year, my desktop PC in my room would get terrible wireless reception with constant erroring and was practically unusable whilst a laptop sat next to it was just fine. I tried a million different things and eventually bought an external wireless antenna like the one here:
    Edimax EA-IO7D 7dBi Indoor Omni-Directional High Gain Antenna with Desktop Stand - 1m Cable
    It solved the problem for me though I am still mystified as to what the problem is - I suspect that there is something in the environment causing interference though I don't know what. My house is of average size and fairly modern with thin walls so I would not anticipate any problems.
    Some things to try are to move the PC right next to the hub (or vice versa, whichever is easier) and see if this improves things or borrow a wireless router from a friend, turn off all encryption and see what signal strength you get there.

  • The home button has stopped working on my iphone 5c. Did the same a few months ago and recovered 24hrs later. Can anyone explain this problem. Phone still in warranty. Had steam issue recently but this was after last home button episode.

    Have an iphone 5c 8g. The home button has stopped working. Did the same a few months ago and recovered 24hrs later. Can anyone explain this problem. Phone still in warranty. Had steam issue recently but this was after last home button episode and no evidence of damage.

    If you are playing in hockey arenas a lot or if you are bringing it into bathroom same time as shower it may not seem like much but overtime the steam can acquire and build up in the phones usb dock flex cable swell as the home button flex cable. Bring again into apple store and should be covered under warranty again. could also be a delay in a 8gb 5c software may just be very lag.

  • Can anyone explain this behavior and tell me how to fix it?

    Using NetBeans 6.5 on Windows, Glassfish v2.1
    I have a JSF application with a page that has a tab set.
    On one of the tabs I have a panel with company information.
    One of the components on the page is an InputText field with the value bound to a session bean variable.
    The tab also has an Add button.
    Here is what the JSP looks like for the input text and button components
       <h:inputText binding="#{MainPage.companyNameTF}" id="companyNameTF" readonly="#{SessionBean1.readOnlyFlag}"
       <h:commandButton action="#{MainPage.mainAddBtn_action}" disabled="#{SessionBean1.disableEdit}" id="mainAddBtn"
            style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; left: 425px; top: 380px; position: absolute; width: 75px" value="Add"/>
         This is all plain vanilla stuff and I would expect that when the Add button is pushed, the session bean property would be filled with
    the value entered in the input text field.
    In the java code for the page, I have a method to process the Add button push.
    Originally, it just called a method in the session bean to check that a value was entered in the input text field by checking the bound
    session bean property.
    For some reason, that was not getting filled and I was getting either a null or empty string rather than the value in the text field.
    I added some checking in the method that processes the Add button push so I could check the values in the debugger.
    Here is a sample of that code:
        public String mainAddBtn_action() {
            String s = sb1.getCompanyName();
            s = (String)this.companyNameTF.getValue();
            s = (String)this.companyNameTF.getSubmittedValue();I check this in the debugger and NONE of the variants that I have listed have the value that was entered into the text field.
    The submittedValue is null and the others are empty strings (that is what they were initalized to).
    This is all pertty straight forward stuff and I am at a loss to explain what is happening.
    Can anyone expain this behavior, and, most important, how can I force the values to be present when the Add button is pushed.
    I have never experienced this problem before, and have no clue what is causing it.
    Thanks.

    Basically, the component bindings are just being used in plain vanilla get/set modes.
    I set them to "" when I do a clear for the fields and they are set to a value via the text field.
    No other action other than to read the values via get to insert them into the database.
    And, I always use the get/set methods rather than just setting the value directly.
    This is what is so strange about this behavior - I have created dozens of database add/update/delete pages using this same model and have not had a problem with them - even in a tab context.
    Not a clue why this one is different.
    I did notice that I had an error on the page (in IE7, you get a small triangle warning sign when something is not right).
    I figured that might be the problem - maybe buggering up the rendering process.
    I tracked that down and do not get that anymore (it had to do with the PDF display I was trying to get working a while back), but that did not resolve the problem.
    I don't think there are any tab conflicts - none of the components are shared between tabs, but I will see what happens when I move a couple of the components out of the tab context.
    I noticed that it seems to skip a cycle. Here is what I can do.
    1) Fill in text fields and add a record - works fine the first time.
    2) Clear the text fields
    3) Enter new data in the text fields and push Add
    4) I get an error saying fields are blank from my data check process.
    5) Enter new data and push Add - the record is added with the new data.
    My work around is to not enter data in step 3 and just accept the error message in step 4, then go ahead and enter the real data in step 5.
    Very ugly, but it works every time.

  • Can anyone explain this? ORA-01722

    Hi all,
    Can anyone understand this?
    I have 3 database servers both running on windows 2000 advanced server, they're used by the development team. Also we have our production database.
    The 3 databases are cloned from the production, so database configuration parameters are all equal. Today I've received a query from the development team to run on the production, the query is just simple like this:
    SELECT *
    FROM x
    WHERE x.field_v = 177762522
    I get this error
    ORA-01722: invalid number
    this is a hudge table, and the fiedl_v is a varchar2(9) type.
    The worst thing is that on the others 3 databases this query returns results, except on the production.
    So, can anyone explain me why does the implicit (char to number) conversion occours on the development databases , and fails on the production? What are the main reasons that can influence datatype conversion like this one?
    Both databases have the 9.0.6 patch.
    The 3 development BD's are totally cloned from the production.
    Thanks.

    William:
    There is no guarantee on the order of evaluation of the predicates. Even with your isnum function, the invalid number could arise. The only safe way is to compare strings to strings as in your first example.
    To make the isnum "safe", you would need something more like:
    SELECT *
    FROM (SELECT *
          FROM x
          WHERE isnum(x.field_v) = 'Y' and
                ROWNUM > 0)
    WHERE x.field_v = 177762522;The ROWNUM > 0 predicate in the in-line view will prevent predicate pushing and guarantee that the isnum condition is evaluated first.
    John

  • Can ANYONE explain this IDIOCY?

    If I have an IFieldObject or ITextObject with the default height of 221 twips for an Arial 8.25pt or Tahoma Bold 8.25 font.
    Why is that a IBoxObject where I set the Top the same as my IField or ITextObject and set the bottom to the Top + 221 twips, the bottoms DON'T LINE UP. Aren't they all 221 twips in height, right?
    Same goes with the width...It befuddles me to work in this designer and not have things equal. Also, why in the world would they not give the IBoxObject a HEIGTH property?
    How wide is the crSingleLine? 20 twips? I understand that when you set the border the actual height/width grows but the values don't reflect it, is that true?
    Can anyone explain the idocy of the measurements and drawing elements in this, used to be good but now is a piece of crap, product? Is there any documentation on this "feature" anywhere? I can't find anything about this in the user guides or help. I'm using 10.2.3600 (sp1) in VS.Net2005 (w/VB.net)

    I have deleted the last reply because of the language used in it. I am also locking this thread so no more replies can be added to it.
    If you want to get replies to your postings please follow the rules of engagement: https://wiki.sdn.sap.com/wiki/x/FgQ
    Be professional, polite, and give us information we need to help you. Remember "us" is not just SAP but all of us in the forum community. Someone other then an SAP engineer may help you, just like you may one time elect help another community member's posting.
    Please feel free to repost your questions in this forum following the "Rules of Engagement". Not following these rules will get postings deleted or ignored.
    Kind Regards,
    Trevor Dubinsky
    Senior Engineer,
    SAP, Business Objects.

  • Can anyone explain this ADVANCED problem?

    I created a RAM disk on my Performa 6360 (running OS 9.1 136MB RAM) one day and after I rebooted the Mac was not bootable. I did the following to get it to boot, none of which worked.
    1. Booted with extensions off
    2. Booted with the OS 9.x, OS 8.5, OS 8.1, and TTP CD-ROMS
    3. Booted with a Zip disk
    Nothing worked and the Mac was not bootable. I believe I also tried clearing the PRAM and still the mac was not bootable.
    The solution however was to boot from a floppy created with the OS 8.1 CD-ROM some time ago, trash the memory prefs and bang the mac was back and working.
    Can anyone explain why my Mac behaved the way it did in reponse to creating the RAM disk, and why the floppy was the only solution to get it back up and running?
    No mac expert (or those claiming to be experts) have been able to explain why the Mac behaved like this.
    John

    John
    You mentioned 136MB of physical(?) RAM in the Performa, and OS 9.1 (about 55MB needed), but not the size of the RAM Disk. Was VM enabled also, and how much? RAM Disk allocation is part of the System reservation of RAM (which you can see in About This Computer after restarting). If the RAM were in excess of 80MB (I know. I know. But I have used RAM Disks as big as 300MB on my 9500, which has 1GB of RAM.) the System might not have been able to shoehorn itself in at System heap allocation time. Why no message? Possibly because the system (Start Manager and friends) hadn't reached a point where they had voices. The foregoing all happens at system test time, long before OS load time.
    It is also odd that resetting PRAM did not abolish the RAM Disk, unless your backup battery is failing (at 3.3V or less in circuit). Shut Down of desktop machines is usually preceded by the warning that the contents of a RAM Disk will be lost, even though the memory allocation will be made again at the next startup. 'Persistent RAM Disk' is usually available only in PBs—which save the RAM Disk's contents to the HDD, and reload them to the RAM Disk's memory plot at Startup—for good reason. Your eventual solution perhaps holds a key, ie corrupt (and bizarrely so) Memory Preferences.
    Disk Tools floppies are sometimes worth their weight in any scarce commodity that you may wish to name. Only last night I was saved by the floppy for System 7.5.3 after I had unthinkingly put a pure PPC extension into the 7.5.5 System folder on my IIci. The Mac would not find its HDD, to boot from, or to mount it when I tried to boot from a 7.5.3 CD or an external HDD with 7.6.1. When I had trashed the extension, all was sweetness and light again. Floppies one. Christians nil.

Maybe you are looking for

  • 1st gen imac,dual core no power?  Some  helpful advice requested please....

    Please pardon my grammar, sentence syntax and perhaps spelling! Yes I have read all the gloom and doom posts regarding logic boards etc, what are the chances it might be a power supply issue? Cord in and out, pram reset, no power light, no response t

  • Save as method not working when variable is in the name...

    Refer to code below.  "currentWord" contains the string "classthatisverylong". The first "filename" works great.  The second one does not.  How can I get around this?  Is there an easy way? Or even a hard way?  Im open to anything! 'fileName = "T:\Te

  • Kobo books on blackberry playbook

    Everything works on my playbook except a book from Kobo I ordered and can't seem to open. I haven't had any problems in the past. I have downloaded books without a problem. This particular book started okay, but now it just won't open. Any suggestion

  • AS2 Certificate Issue

    Hi all, While loading AS2 certificate of the Trading Partner in our system it is asking for the password to unloack the certificates but when i contacted the Trading Partner they have not set any password for the certificates . Can any one help what

  • SOAP Parameters: Ugly name, can that be changed for something more friendly

    Hi, Everyone, I follow examples here: http://www.oracle-base.com/articles/11g/NativeOracleXmlDbWebServices_11gR1.php ( ours is 11GR2 but the differences are almost none) and created a test procedure and it automatically pubishes it as a SOAP service,