in combination with the function sequence

Hello

I have a problem with a sequence in combination with a function.

I want to generate a kind of a hardware inventory report that contains some kind of a hardware ID (a number not repetitive, auto-increment, allowed deviations). However, I have to keep track of what material ID I used to which material of the inventory, for reasons of traceability. Another important requirement is that whenever the report is run, that the returned hardware IDs are never repeated. If repeatedly runs for the same hardware in the inventory must always return new material ID.

So I was about to create a simple function from PL/SQL where I spend my data of traceability as parameters. Then the function uses internally a sequence (nextval) to generate a new hardware ID, then stores the new ID of material by related values in the input in a table (autonomous transaction) parameters and returns the new ID.

It works pretty well so far.

Now the tricky part: I want where I want to go back the same ID in different columns of a SQL statement.

Let me give you an example:
CREATE SEQUENCE XXX_TEST_SEQ
MINVALUE 1 MAXVALUE 999999999999999999999999999
INCREMENT BY 1 START WITH 1
NOCACHE NOORDER NOCYCLE;


CREATE PACKAGE XXX_TEST_PKG AUTHID CURRENT_USER AS
FUNCTION get_id(p_someparameter NUMBER) RETURN NUMBER;
END XXX_TEST_PKG;


CREATE PACKAGE BODY XXX_TEST_PKG AS
FUNCTION get_id(p_someparameter NUMBER) RETURN NUMBER IS
  l_new_id NUMBER;
BEGIN
  SELECT XXX_TEST_SEQ.NEXTVAL
    INTO l_new_id
    FROM DUAL;
    /* do some more logic, e.g. store the freshly generated ID 
        together with the input parameter values in some tracing table */
  RETURN l_new_id;
END get_id;
END XXX_TEST_PKG;
It is a simplified version of the function for demo.

We will use:
-- 1) this works as expected:
select xxx_test_pkg.get_id(1) from dual;

XXX_TEST_PKG.GET_ID(1) 
------------------------ 
1                        


-- 2) this returns two different numbers:
select xxx_test_pkg.get_id(1) as id_one
    ,  xxx_test_pkg.get_id(1) as id_two
from dual;

ID_ONE                 ID_TWO                 
---------------------- ---------------------- 
2                      3                      


-- 3) This is the problematic case: I want to return the same ID two times:
select my_id as id
     , my_id as same_id
 from (select xxx_test_pkg.get_id(1) as my_id from dual);

ID                     SAME_ID                
---------------------- ---------------------- 
4                      5                      


-- 4) CURVAL on these sequence does not work:
select my_id as id
     , xxx_test_seq.curval as same_id
 from (select xxx_test_pkg.get_id(1) as my_id from dual);

SQL Error: ORA-00904: "XXX_TEST_SEQ"."CURVAL": invalid identifier


-- 5) This gives the output that I need, but why?
select my_id as id
     , xxx_test_seq.nextval as same_id
 from (select xxx_test_pkg.get_id(1) as my_id from dual);
 
ID                     SAME_ID                
---------------------- ---------------------- 
7                      7                      
Query 3 is one who gives me headaches. I need to return the same ID in different columns. But it returns only two different pieces of identification. I know that the optimizer will merge the two select statements into one and therefore perform the function twice. Someone knows how can I avoid this?

Which is a little strange to me, it's the query 5 is really what I need, but at first glance I would say that he should not do. I would say that using nextval would be me again another number sequence.

It's confusing... Can someone explain this and advise how can I build a query if I can get the same ID twice by line?


I know that I can totally get rid of the sequence in my function and use something different, but I was wondering if I can avoid to change my function.


Thank you
David.

Oracle's FUSION query inline with the outer query block, which causes the function being called twice.

Instead of MATERIALIZING suspicion, or relying on ROWNUM = 1 effect predicate aside, I would explicitly tell the optimizer to not do so via the NO_MERGE indicator.

select my_id as id
     , my_id as same_id
from (select /*+ NO_MERGE */ xxx_test_pkg.get_id(1) as my_id from dual);

Tags: Database

Similar Questions

  • Question A100 - 01 Q satellite in combination with the Syncmaster 226BW

    Hello
    I need help. I have problems with "A100 - 01 Q" in combination with the Syncmaster 226BW, the problem seems to be the display driver, there is no new version available on toshiba.com. Would you mind and give me some advice?

    I need a new driver for the Gefroce 7600 GO... (Modelltype: A100 PSAAR)

    Thank you!

    You have searched the site Toshiba us compatible graphics driver?
    It was big mistake.

    You perform a search on the European driver of Toshiba site. This laptop A100 PSAAR was designed in the EMEA regions.

    Then please visit this site;
    http://EU.computers.Toshiba-Europe.com/cgi-bin/ToshibaCSG/download_drivers_bios.jsp?service=EU

    Choose your model of laptop just in the form of download and download driver compatible ;)

    In addition, you could test the graphics drivers nVidia 3 sites like www.omegadrivers.net and www.laptopvideo2go.com

    Best regards

  • Kalonline-works until I get the anti-piracy icon so stop saying: there is a problem with the function of anti-hacking

    I play kalonline (RPG game), when to start the game it works up until I get the anti-piracy icon so stop saying: there is a problem with the function of anti-hacking. the program stops. I am the admin of it say kal computer run it in administrator mode and I did and I delete and reinstall the game. Solve the problem in win 7 by a right click and run as administrator, they wanted to work in win xp it all fits on how to solve this problem. These are the things, I was told to do to fix it.
    Hello

    It comes to KalOnline.

    Your error message can be corrected by following these steps:

    1. run KalOnline in Administrator Mode.

    2 uninstall KalOnline d_lete the entire Inixsoft folder, then reinstall the game.
    I did it and and it has not worked. then I was told that this was causing the problem

    Please check your computer system.

    This problem has occurred by a kind of problem of piracy.

    And if you have used a kind of memory-editing program, it could be happen too.

    So if your receipt similar to, then please remove it.
    I have none of these things on my computer. All I know is that people who have not updated windows xp can play the game and people who win 7 can play the game if they right click icon and run as administrator, that I still say side here but no way to prove it.

    Hello

    I suggest you to get in touch with the manufacturer of games and see if there are any other fix for this problem.

  • A toolbar with the function showing keys is located at the top of my screen-how to remove

    Original title: function keys
    A toolbar with the function showing keys is located at the top of my screen.  When I click on any of the icons that they do not work.  How can I remove the toolbar of the my computer screen function?

    Hello

    a toolbar with function keys at the top of the screen does not part of vista

    Contact the manufacturer of your computer

  • Sir, iam not at all satisfied with the functionality of windows vista, I need immediate upgrading to windows 7, please please give me this, I have the version of the license of vista,.

    Remember - this is a public forum so never post private information such as numbers of mail or telephone!

    Ideas:

    • Programs you are Sir, iam, not at all satisfied with the functionality of windows vista, I need immediate upgrading to windows 7, please please give me this, I have the version of the license for vista, problems with
    • Error messages
    • Recent changes to your computer
    • What you have already tried to solve the problem

    For any question on Windows 7:

    http://social.answers.Microsoft.com/forums/en-us/category/Windows7

    Link above is Windows 7 Forum for questions on Windows 7.

    Windows 7 questions should be directed to the it.

    You are in the Vista Forums.

    See you soon.

    Mick Murphy - Microsoft partner

  • A that someone finds a solution or a mouse that works to align it with the function?

    OT: Mouse Snap to.

    A that someone finds a solution or a mouse that works to align it with the function? I see that this topic has been posted a few times, it's pretty frustrating to not have it.  And like someone else posted, I mean the option 'Automatically move pointer to the default in a dialog box button'.

    Take a look at this: Windows 7: the mouse - Snap to default button see option 2 on the download registry key.  I would always back up your registry in case where.

  • Having the problem with the function on SG300 Dhcp / 500?

    Having the problem with the function on SG300 Dhcp / 500? now I can use the dhcp server on the two model, but have a problem.

    My problem is when I create

    VLAN 1: 192.168.0.1/24 dhcp pool 192.168.0.10 - 250

    VLAN 10: 192.168.10.10 - 250 192.168.10.1/24 dhcp pool

    case 1

    I plug the pc to vlan 1 can I get ip 192.168.0.11. But when I change this pc to a new port in vlan 2 I always get the same ip address. why I can not get IP of vlan2.

    case 1

    I plug the pc to vlan 2 I can get ip 192.168.10.11. But when I change this pc to a new port in the vlan 1 I always get the same ip address. why I can not get IP of vlan1.

    but when I have access to the switch and remove the link after that that i will get correct IP.

    I think this is the bug of this firmware. Could you help this case.

    This is a known bug that is the setting of Cisco

    Sent by Cisco Support technique iPad App

  • Router Cisco Small business with the functionality of the link aggregation

    Hi all!

    can someone tell me if there is a router from Cisco Small business with the functionality of the link aggregation? (I want to connect two 4 Mbps SDSL for flow)  The RV082 can do?

    Best regards

    You would need a RV016, who takes in charge up to 7 WAN ports. RV082 has only two WAN ports.

  • Does SOUL used in combination with the hierarchy of position for purchase requisitions

    Hello

    We use the hierarchy of position for purchase requisitions.

    Can we use management engine approval in combination with the hierarchy of existing post for purchase requisitions for workflow routing more flexible?

    Kind regards

    Natalia

    Hi Natalia,

    Using hierarchy Position in the SOUL is supported only in R12, please refer to the following document:

    Using SOUL, creating approval routing at a certain Position in the hierarchy of Position HR [ID 1501433.1]

    Hope this helps,

    Please, if this response has answered/solved your question/query, please mark it as correct or useful to facilitate the correct answers to the members of the community.

  • Does anyone know how to use the movement of scroller with the function of the fluid width?

    Hi all

    Does anyone know how to use the movement of scroller with the function of the fluid width?

    Thanks, Federico

    This feature is not yet implemented.

  • Question about merging with the function of the background

    Hello, I was wondering if someone can tell me when it is useful to use the fusion with the function of the background.  I see nothing in the documentation on the subject. It seems to me that you can make your changes on the master slide, and you would not need the feature.  If I'm misunderstanding please let me know, thanks.

    Hello

    Is not safe to be comprehensive here, just my ideas. If you merge objects with the background on a master slide, you can save on the size of the file, because the background is an image, compared to several objects. You will not be able to edit these objects more. Also the slide background will always be behind any object. For slides model objects you can have them either on top, where they sit on top of the stack, or not. If you have objects of time during the rest of the project, they will always be on top of the slide background, but if you slide model objects, they'll be on top of the object of time during the rest of the project, unless you put that one always on top. You can disable to show slides on normal leaves model objects, separately from the power off from the slide background. Some of my ideas. For objects that I still want to be with the background, I'd prefer to merge. For objects that do not always, I will keep the separately and it is of course always the case for the button of interactive form that you cannot merge with the background (which is just an image, non-interactive).

    Lilybiri

  • Tiara dac combined with the NI PCIe-6259 does not send the data

    Hello

    I have a card OR PCIe-6259 & DIAdem 11.2.0 (version 2010) on a windows 7 PC.

    Inputs outputs & analog analog + digital are configured in MAX 9.8.0f0. (Global virtual channels)

    When I run a dac, entered analog works perfectly.

    Outputs analog and digital does not work. Only one of the four analog outputs give the value that has been send.

    In the past, I had the same problems with this version of DIAdem in combination with a third party USB card, but this has been resolved by the new firmware & software drivers.

    Someone who has had similar problems?

    Thank you.

    After trying many things, I finally found the solution.

    In the output ==> pilot ==> options pilot "weighting the digital bus" must be verified.

  • Error with the function "Open/create/overwrite file" with cancel button

    I have attached a very simple VI who embodies what I want to do with my function to open the file. I just want to stop the rest of my program (theoretically embedded in the Structure box) to run if the user deigns to do not to specify a file location.

    However, if you click on the button cancel an error is produced before the rest of the program is running. If ignore you the error and continue, the "canceled" properly true made variable and the Structure of business runs correctly. "" I just want to remove the error message given to me by LabVIEW.

    Any ideas on why or how?

    Read the help of LabVIEW on automatic error handling.

    In your case, you can just wire the output of cluster of error to the structure of your business.

  • How to write to .subckt with the function I - V

    Hi all

    Now, I am trying to build a Spice model for a type of diode high voltage for 13 Multisim. Because I do not have the LED electronic settings, and I only have the function of the I - V, I tried to write a file .subckt for him.

    Assuming that the anode is A1 and the cathode is A2, the current flowing through the diode can be expressed only by the function:

    I=((0.581*(V(A1)-V(A2))*(V(A1)-V(A2))/3/3-18.4*(V(A1)-V(A2))/3+144.66)/1000)*U((V(A1)-V(A2))-53)

    With her, I wrote a .subckt:

    . SUBCKT LED A1 A2
    B1 A2 A1 I=((0.581*(V(A1)-V(A2))*(V(A1)-V(A2))/3/3-18.4*(V(A1)-V(A2))/3+144.66)/1000)*U((V(A1)-V(A2))-53)
    . ENDS LED

    This model works well under the IV parser in Multisim 13, but when I connect 2 or 3 of them in series and make a simple circuit simulation, I always get the error report and not always not correct the error.

    Any body can help me to check if my .subckt is correct or not? Thank you.

    It seems that the convergence error is caused by a discontinuity the diode to connection 53V.  Run DC scan using the test circuit.

    To prevent the discontinuity, use the express following with the fi works instead. You can give it a small current when V (A1, A2) is less to 0V.

    B1 A1 A2 I=if(((V(A1)-V(A2))-51)>0,((0.581*(V(A1)-V(A2))*(V(A1)-V(A2))/3/3-18.4*(V(A1)-V(A2))/3+144.66)/1000),-230u)

    The attached circuit have a resistance using convergence.

    You can simplify your expression for readability:

    -(V, (A1), (A2) V) = V (A1, A2)

    -If you can do the expression in this form, it will simply be the calculation ax ^ 2 + bx + c

  • Problem with the function keys

    Hi a few days ago my computer did an automatic update of windows.  This combination of time keyboard shortcuts in my Microsoft Flight Simulator 2004 have changed.  For example, ctrl + any Fkey and shift-several different keys do not work.  Some commands are not options in games keyboard assignments.

    Is there a way to restore my original keyboard settings?

    Thank you...

    Are you sure that Windows Update caused this?

    Restore your computer (by using the system restore) to a previous state - before you install the updates and see if it restores the 'fn' and other features with FS 2004.

    See http://support.microsoft.com/kb/306084 (assuming you are using Windows XP, because the game is compatible with XP and legacy OS)

    If restore fixed the problem with the keys on the keyboard and FS2004, manually install the updates one: after the installation of each update, restart the computer, try to play the game and check if the problem reappears at all.

    This, until you have installed all Windows updates.

    MRI!

Maybe you are looking for

  • Add the .jar to the Windows Server 2003 Group Policy

    So I have an executable JAR file that is intended to run our ads system employee. It reads the data from a separate txt file and displays it in a JFrame. My goal is to have this launch when you connect to all the computers in the workstation. The pro

  • Software update = more heat... Impossible... Yes? .. .wrong

    My computer has updated last night... auto update (the last update). It contained 15 new updates, anyway... when I got home the next day I turned on my computer, to find all works 5 to 10 degrees warmer... ahh? It's technically impossible... but its

  • HP envy 15 t-ae100: touchscreen driver

    I wonder if there is any monitor driver available for the touch screen of my computer laptop hp envy 15 t-ae100. I am currently using driver generic PnP monitor with a maximum resolution of 1366 x 768. I really need full HD 1920 x 1080, because appli

  • How to disable the USB port and change DVD drive to read-only?

    I have upgraded my Vista Home Premium from window to window 7 Ultimatum. I tried to disable the USB port and and change the configuration of DVD room to read only via the bios, but I wasn't able to do. The bios always the same, whether it was when I

  • Vista 64-bit for XP Professional downgrade

    I have problems to run a number of games on the Vista 64 Bit OS, so decided to buy and run a clean installation of XP Professional. I have run the XP installation, but tells me that I don't have install disks (they work fine under Vista!). I have a 5