Copy a record ang get its new primary key value

Hello again everyone!

I need to copy a record from a table at the same table. Here is the sample table and data:

CREATE TABLE (PRODUCTS)
ID INTEGER NOT NULL,
DESCRIPTION VARCHAR2 (80).
PRICE NUMERIC (9,2),.
KEY ("ID") PRIMARY CONSTRAINT 'PK_PRODUCTS '.
);

INSERT INTO PRODUCTS (DESCRIPTION, PRICE) VALUES (' PRODUCT 1', 8.5); -You will receive 1 trigger ID
INSERT INTO PRODUCTS (DESCRIPTION, PRICE) VALUES (' PRODUCT 2', 7.0); -You will receive 2 ID by trigger

Now, I need to copy data from product 1 on a new line on the table.

I would use the following SQL statement:

INSERT INTO PRODUCTS (DESCRIPTION, PRICE)
SELECT DESCRIPTION, the PRICE OF PRODUCTS WHERE ID = 1 - assuming that I want to copy 'Product 1'
RETURN ID IN: NEW_ID

But as far as I know, this is not supported by Oracle. Is there no workaround solution to solve the problem?

I can't use procedures, functions, or something like that. Must be a SQL statement.

Once again, thank you all for help.

Best regards

user9936895 wrote:
INSERT INTO PRODUCTS (DESCRIPTION, PRICE) VALUES (' PRODUCT 1', 8.5); -You will receive 1 trigger ID
INSERT INTO PRODUCTS (DESCRIPTION, PRICE) VALUES (' PRODUCT 2', 7.0); -You will receive 2 ID by trigger

I really, really, really hope that your trigger uses a sequence to generate pk

I can't use procedures, functions, or something like that. Must be a SQL statement.

If your trigger uses a sequence to generate the pk, I hope that there is a clause which no values if the KP value is zero...

If Yes, then you could just do:

INSERT INTO PRODUCTS (ID, DESCRIPTION, PRICE)
SELECT id_sequence.nextval, DESCRIPTION, PRICE FROM PRODUCTS WHERE ID=1 --Assuming I want to copy "Product 1"

Tags: Database

Similar Questions

  • How can I just get a new product key?

    How can I just get a new product key?  I'm not just software product key.  I have windows 7 Home premium, but it can only be used on a single computer.  I have a counter top and a netbook.  I spent $124,00 once and I won't spend that again.

    Wednesday, April 14, 2010, 05:55:18 + 0000, genevievey02 wrote:

    > How do I just get a new product key?

    You buy the product again.

    > I don't want to just software product key.

    The software comes with the key when you buy. You have not a
    choice.

    > I have windows 7 Home premium, but it can only be used on a single computer.

    Right, the rule is quite clear. It is a copy (or a license) for
    each computer.

    There is nothing new here. This is exactly the same rule that has been in
    effect on all versions of Windows from at least with Windows 3.1.

    > I have a counter top and a netbook. I spent $124,00 once and I won't spend that again.

    Then, unless you can find a lower price somewhere or you wish to fly,
    you're out of luck.
    Ken Blake, Microsoft MVP (Windows desktop experience) since 2003
    Ken Blake

  • How to get the new activation key when some numbers are taken away and you have received?

    How to get the new activation key when some numbers are taken away and you have received?

    Have a laptop with windows 7 from Dell. Need to re install W7. And I have some numbers are taken as a result of its use.
    How can I get a new code activation or my complete activation code?
    Best regards, W7 user

    How to get the new activation key when some numbers are taken away and you have received?


    Have a laptop with windows 7 from Dell. Need to re install W7. And I have some numbers are taken as a result of its use.
    How can I get a new code activation or my complete activation code?

    Dell provided you with restore/recovery media and/or a way to restore the machine 'default' as a key sequence?  If so - you won't need the number--unless they just sent a DVD of Windows 7 nu - and they are usually not unless you ask.

    They have probably installed using their key, which means that even with a utility like Belarc Advisor or ProduKey - you will not get the product key that matches the one on the sticker.

    Some may have you take several different digital pictures of the sticker from different angles and see if you can decipher the missing characters like that (you'd be surprised to see how that works).

  • Why should I pay to get a new product key when on my computer is incorrect?

    By following the instructions on the internet, I got my product key of the section "Computer" from the Start button. It is only 20 digits and, therefore, will not work.  Why should I pay to get a new product key when on my computer is incorrect?

    Original title: product key

    Sometimes, it might be the battery, or below.  Sometimes they include it in a separate box with the recovery CD disks.  It's the PC manufacturer to decide how they want to, so you will need to call and ask them in particular.  Sorry, we can't be more helpful here.

  • I recently bought adobe photoshop and Premier (2 a) for windows. My computer crashed and I can't use this product because I bought a new macbook. Is it possible that I can download this software on my mac or get a new product key?

    I recently bought adobe photoshop and Premier (2 a) for windows. My computer crashed and I can't use this product because I bought a new macbook. Is it possible that I can download this software on my mac or get a new product key?

    Hey Britney,

    Please visit the following link: a product of Adobe for another language or version of trading platform

    You can download the apps for MAC from here: Download Photoshop Elements | 14, 13, 12, 11, 10

    If you still need help contact our support Chat for the same thing: contact customer service

    *Remember to stay signed with your Adobe ID ( email id used to purchase the subscription ) before accessing the link above*.

    Let us know if that helps.

    Kind regards

    Sandrine Bani

  • Shape of the apex - how to get the primary key value manually?

    Hello

    Whenever I create form by using wizard Apex, he asks me to specify the trigger/sequence/pl/sql function to fill the primary key value.

    However, if I want to specify primary key myself (ie. undetermined generated automatically), how I can clarify that?

    Thanx

    Hello

    You mean by yourself: by hand or by a pl/sql?

    If you say by trigger, the system does not take on what number is sent. If you can give it "manually".

    May I ask what is the reason for this?

    See you soon,.

    Arnaud

  • Trigger - use one to create primary key values

    I'm stuck on a simple use to do a TRIGGER that fires when you add new rows to a table and want to Developer SQL to add the primary key value.

    I seem to be able to relax, but it is not inserted the primary key but giving a SQL error: ORA-00947: not enough values.

    Here's what I have.

    CREATE TABLE HF_fishers

    (

    contact_id INT NOT NULL

    , name VARCHAR (25)

    , last_name VARCHAR (35)

    PRIMARY KEY (contact_id)

    );

    CREATE SEQUENCES HF_fishers_seq.

    Then I ran the following trigger:

    CREATE

    HF_fishers_seq_trigger RELAXATION

    BEFORE INSERTING

    ON HF_fishers

    FOR EACH LINE

    BEGIN

    IF (: new.contact_id IS NULL)

    THEN

    : NEW.contact_id: = NVL (: NEW.contact_id)

    HF_fishers_seq. NEXTVAL

    );

    END IF;

    END HF_fishers_seq_trigger;

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

    Then I executed the following SQL statement that gives the error.

    INSERT INTO HF_fishers VALUES('Jacob','Muller');

    But if I do everything is good except that it defeats the purpose of relaxation.

    INSERT INTO HF_fishers VALUES(1,'Jacob','Muller');

    MySQL has a nice 'AUTO_INCREMENT' command, but from what I understand in Oracle, I need to set up a trigger to automatically increment a column/cell, which in this case I use for the PRIMARY KEY.

    3003916 wrote:

    OK Jaramillo, I tried as you wrote, but what would be an INSERT statement correct?

    -After the code trigger of Jaramillo

    INSERT INTO HF_fishers (first_name, last_name) values ("Jesse", "Owens"); -I have the trigger but he made the mistake of duplicate key.

    INSERT INTO HF_fishers values (hf_fishers_seq.nextval, 'Jesse', "Owens");  -No trigger but get key duplicated,.

    INSERT INTO HF_fishers VALUES(:NEW_contact_id,'Jesse','Ownes'); -works without the trigger but the "get links" dialog box appears. So not much 'automatic' on this issue,.

    My mistake.  Here is the modified version of the trigger. I removed the CONDITIONAL clause and comes to be a part of the body of the trigger.

    So, I created the table, the sequence, the relaxation and ran the first two insert statements and it worked fine.  The third one you have invites SQL + or any tool you use to enter a value if she sees the ":" colon as a variable binding.  Colon only works in a trigger without asking for confirmation.

    Here is the code and my exit I ran home

    DROP TABLE hf_fishers CASCADE CONSTRAINTS PURGE;
    DROP SEQUENCE hf_fishers_seq;
    
    CREATE TABLE hf_fishers
    (
    contact_id   INTEGER NOT NULL
    ,first_name   VARCHAR(25)
    ,last_name    VARCHAR(35)
    ,PRIMARY KEY (contact_id)
    );
    
    CREATE SEQUENCE hf_fishers_seq;
    
    CREATE OR REPLACE TRIGGER hf_fishers_seq_trigger
       BEFORE INSERT
       ON hf_fishers
       FOR EACH ROW
    BEGIN
    
       IF(:NEW.contact_id IS NULL) THEN
          :NEW.contact_id := hf_fishers_seq.NEXTVAL;
       END IF;
    
    END hf_fishers_seq_trigger;
    
    INSERT INTO hf_fishers(first_name, last_name)
         VALUES ('Jesse', 'Owens');  -- Works with the trigger
    
    INSERT INTO hf_fishers
         VALUES (hf_fishers_seq.nextval, 'Jesse', 'Owens');  --Works without using the trigger body code.
    
    SELECT *
      FROM hf_fishers;
    
    COMMIT;
    

    The output

    Deleted table.

    Elapsed time: 00:00:00.05

    Sequence has fallen.

    Elapsed time: 00:00:00.02

    Table created.

    Elapsed time: 00:00:00.03

    Order of creation.

    Elapsed time: 00:00:00.02

    Trigger created.

    Elapsed time: 00:00:01.05

    1 line of creation.

    Elapsed time: 00:00:00.04

    1 line of creation.

    Elapsed time: 00:00:00.01

    CONTACT_ID FIRST NAME LAST NAME

    ---------- ------------------------- -----------------------------------

    1 Jesse Owens

    2 Jesse Owens

    2 selected lines.

    Elapsed time: 00:00:00.04

    Validation complete.

    Elapsed time: 00:00:00.01

  • Get the new activation key

    I bought a copy of windows 7 ultimate Windows.com/genuine after having received a notice that my copy of windows was not authentic. I bought the new activation key for almost $300 and they also sent me an installation CD where I never had to perform a reinstallation. Well my hard drive crashed and I had to purchase and install a new one, which meant the reinstallation of windows. However, I found that in some way I lost my activation code and the cover of the CD that Microsoft sent me contained not one. I called Microsoft support several times to get the reprinted to me activation key. I spent many hours being transferred from one Department to the other until they began to transfer me to the same departments several times. I have my order number, address that was sent to the, date of purchase and all. They can see my order but they can't access information on this topic for a reason, and they issue me a new code. At this point, I'm really upset because I spent a lot of money on this software only to be told that I can't use it. In addition to all this Microsoft has absolutely no way to file a complaint. I am at a loss to know what to do. The only option that Microsoft gives me is to buy a new code, but there is no way I'm paying twice for the same product, I just assumed never to use a Microsoft product to new to be dressed like that. If someone has experienced something similar, I would be grateful for help on how to get this sorted out. Thank you!

    In order to buy key online, you need to create an account.  Others are able to retrieve the key from this account.  Have you tried signing in?

    Always attach your product keys as you would any money because that's what you lose.

    Have you confirmed that the hard drive is dead by starting HD diagnostic CD indicated on the?  If your manufacturer is not listed, then use Seatools CD.

    If the hard drive still has life so here How to recover Windows 7 8 disc product key from unbootable

    How to find your lost Windows or Office product keys

    Retrieves the product key lost (CD - Key) of Windows/MS-Office/SQL Server

  • RadioButton with submit does not insert new primary key/registration

    Hello

    I have a form with radio buttons. Originally, I used the button create automatically generated to send the page, record the value and creates a branch to another page. If the primary key is zero, it would create a new record with a primary key in the sequence.

    I changed the radio button to be 'submit' and now he passes on the next page, but does not create the new key.

    I don't see what is the difference between the two methods, but it is probably simple...

    Any help is greatly appreciated.

    Thank you
    Matt

    I don't see what you're doing. The page that loads the record must be programmed to do a checkout of the line using the element as the PK value if the element is not null. Attribute of the Source of this element should probably also be «Just...» ».

    Scott

  • How to get a new product key

    original title: I bought this labtop to a friend and I reset the computer and he lost the product key. you guys can give me a new product key?

    I bought this labtop to a friend and I reset the computer and he lost the product key. you guys can give me a new product key?

    No, we cannot. check the bottom of your laptop for the 25-digit number, or ask your friend for her.

  • With custom auto-generated primary key value

    How to implement the the custom generated automatically Coordinated as 'ISSUE00001', 'ISSUE00002' ADF entity object.

    Hello
    your PK should be varchar2 if you use oracle DB or what?
    While you use to generate the PK value you expect, you can use the database for him.
    http://www.exploreoracle.com/2010/10/11/sequence-number-for-primary-key-in-Oracle-ADF-JDeveloper/
    in this site, call your function in the dodml method. without using the sequence.
    If (operation == DML_INSERT) {}
    inside to call your function that allows to generate number with the string value. (u concat/join 'FROM' value for your build number max)

    }

    Thks.

  • Difference between the immediate and normal constraint primary key value

    Hello
    I tried the following to understand the difference between immediate constraint set and the primary normal stress
    create table cust (cust_id number ,cust_name varchar2(25));
    
    alter table cust add constraint cust_id_pk primary key(cust_id)
    deferrable initially deferred;
    
    SQL> insert into cust values(1,'raj');
    
    1 row created.
    
    SQL> insert into cust values(1,'sam');
    
    1 row created.
    
    SQL> commit;
    commit
    *
    ERROR at line 1:
    ORA-02091: transaction rolled back
    ORA-00001: unique constraint (SCOTT.CUST_ID_PK) violated
    
    
    SQL> set constraint cust_id_pk immediate;
    
    Constraint set.
    
    SQL> 
    SQL> insert into cust values(1,'lata');
    
    1 row created.
    
    SQL> insert into cust values(1,'lata');
    insert into cust values(1,'lata')
    *
    ERROR at line 1:
    ORA-00001: unique constraint (SCOTT.CUST_ID_PK) violated
    The above error violation even works for a normal constraints primary / unique

    So what is the use of the command

    immediate Set constraint cust_id_pk;


    Thank you

    So what is the use of the command

    In fact, the use of the command when you're dealing with foreign key constraints. As explained below

     SQL>  create table cust (cust_id number ,cust_name varchar2(25), supplier_id number);
    
    Table created.
    
    SQL> create table supp(supplier_id number);
    
    Table created.
    
    SQL> alter table supp add primary key(supplier_id);
    
    Table altered.
    
    SQL>  ALTER TABLE cust ADD CONSTRAINT fk_cust_supp
      2    FOREIGN KEY (supplier_id)
      3    REFERENCES supp (supplier_id)
      4    DEFERRABLE
      5    INITIALLY deferred;
    
    Table altered.
    

    To insert a line in the cust table without entering Ref provider table supp

    SQL> insert into cust values(1,'raj',111);
    
    1 row created.
    

    Line by 1 created successfully (attention this validation is not yet done) because the foreign key constraint is initially deferred.

    Now

    SQL> set constraint fk_cust_supp immediate;
    set constraint fk_cust_supp immediate
    *
    ERROR at line 1:
    ORA-02291: integrity constraint (OWNER.FK_CUST_SUPP) violated - parent key not found
    

    Since Ref no outs in extra table so forced provider violated.

    allows to insert a row in the vendor corresponding with the vendor id in the cust table id

    SQL> insert into supp values(111);
    
    1 row created.
    

    Now, try

    SQL> set constraint fk_cust_supp immediate;
    
    Constraint set.
    

    but now, if you try to insert a row into the table cust without this vendor id in table supp, it give error (since now forced to check from the inserted row, even will not wait for commit)

    SQL>  insert into cust values(3,'bob',222);
     insert into cust values(3,'bob',222)
    *
    ERROR at line 1:
    ORA-02291: integrity constraint (OWNER.FK_CUST_SUPP) violated - parent key not found
    

    Also, in the case of primary key constraints will be checked when you perform VALIDATION, otherwise that it will allow you to insert the second row.

    SQL> alter table cust add constraint cust_id_pk primary key(cust_id)
      2  deferrable initially deferred;
    
    Table altered.
    
    SQL> insert into cust values(1,'raj');
    
    1 row created.
    
    SQL> insert into cust values(1,'sam');
    
    1 row created.
    
    SQL> insert into cust values(1,'bob');
    
    1 row created.
    
    SQL> commit;
    commit
    *
    ERROR at line 1:
    ORA-02091: transaction rolled back
    ORA-00001: unique constraint (OWNER.CUST_ID_PK) violated
    
    SQL> 
    
    SQL> drop table cust;
    
    Table dropped.
    
    SQL> create table cust (cust_id number ,cust_name varchar2(25));
    
    Table created.
    
    SQL> alter table cust add constraint cust_id_pk primary key(cust_id)
      2  deferrable initially deferred;
    
    Table altered.
    
    SQL> set constraint cust_id_pk immediate;
    
    Constraint set.
    
    SQL> insert into cust values(1,'raj');
    
    1 row created.
    
    SQL>  insert into cust values(1,'sam');
     insert into cust values(1,'sam')
    *
    ERROR at line 1:
    ORA-00001: unique constraint (OWNER.CUST_ID_PK) violated
    
    SQL> 
    

    Published by: Azhar Husain on July 27, 2011 12:01

  • My CD key is for Xp, but I got a free upgrade to Vista, how can I get a new CD key now its saying that my Windows is not genuine?

    I have a HP Pavilion laptop, which came with XP on it and XP key on the back sticker. However, when I bought it, it came with a free Vista Upgrade, that I used. Now several years later it says that my copy of Vista is not authentic, but I can't get the CD key to verify that the CD key is for XP, not Vista.

    Any ideas of how to fix cela, or should I just try it backward on a XP machine with old code?

    Thank you!

    Hello

    Did you change your computer?

    I suggest you follow the link and check.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-windows_install/Windows-is-showing-as-not-genuine/6efea9fd-70a9-4530-88c8-93fd7b2d5484

    I also suggest that you follow the link and check

    Genuine Windows: Frequently asked questions

    http://Windows.Microsoft.com/en-us/Windows/help/genuine/FAQ

    Windows could not be validated as authentic

    http://Windows.Microsoft.com/en-us/Windows/help/genuine/validation-error

  • How can I get a new activation key?

    I have recently sysprep has my HDD to move to a newer PC, the installation went well but Win 7 must reactivate. However, I can't use the activation code provided with the original installation disc, so I phoned using the number...

    First of all, after I entered all the numbers I wonder whether this copy of windows is installed on a PC (#1) ou number (#2). It's a family pack for 3 licenses (and I installed it on 3 machines) so I enter #1. Then I get a message telling me that this copy of Windows 7 may not be installed on more than one machine (which is not true) and the line goes dead. So I try again.

    On my second attempt, after you have entered all the numbers and say it is installed that on a single machine (Yes, I had to lie to get past the automated system) I come finally to speak to an advisor. The counselor told me there was a problem with the system and she couldn't do anything, I wondered more but apparently she can't understand me (Yes, I called the number in the United Kingdom) because of my English accent.

    Where should I go from here?

    Still there have been reactivated since its removal from the former regime and the Windows 7 Home Premium license is a license to retail sales.

    Try direct activation phone again and talk with another representative directly:

    Direct activation number: (888) 725-1047

    1-800-936-5700

  • How to get a new product key Act. lol for Acrobat 7 Pro?

    Hello

    Acrobat 7 Pro is obviously not supported by Adobe more and I'm not able to get my application of circulation reactivated. Adobe did ' t give me a new key product so far. How can I get this product key and activation for my application will again?

    Thank you for your support

    aprove

    You must contact Adobe Support by chat or phone when you have the serial number and activation problems.

    Here are some links to help get in touch:

    http://www.Adobe.com/support/chat/ivrchat.html

    http://www.Adobe.com/support/download-install/supportinfo/

Maybe you are looking for

  • Do not open attachments MATLAB in TextEdit

    I understand how to set type on a Mac applications. However, there is a problem. When I receive an email with a ".m" (MATLAB) file, it should open in TextEdit (on a Mac) because this is the app that I put on my machine. I also put types strangers and

  • Add column of worksheet

    Hello, everyone. As the title indicates, I'm looking to add a timestamp column to the worksheet that I created. I had some difficulty with this due to the nature of the program, so let me go into the details a little more. The program I wrote is a lo

  • Maximum number of samples with PCI-6123

    I am facing a strange problem. I can't start a task with more than 1 samples (1000000) mill with my PCI-6123? If I just get money, then that works, no matter how many channels or samplerate. I use DAQmx who must manage up to 16 mill. -cpede

  • calculate pixel intensity in an image in black and white

    Hi all First of all, im new to labview. Now, this question may have been asked before, but I'm not quite sure. OK, so I have an avi video that can be allocated by 50 images. I used imaq threshold and a loop for to put a threshold in each image, which

  • We get an error "NETWORK CONNECTION ERROR, make sure a firewall is not blocking access to the printer.

    * Original title: printer error... I was printing with a printer wireless for months and now all of a sudden I'm getting an error, NETWORK CONNECTION ERROR and then readings make sure that a firewall is not blocking access to the printer.   I checked