Results 1 to 6 of 6

Thread: Inserting new rows in a table with out hard coding.

  1. #1
    Join Date
    Oct 2006
    Posts
    5

    Inserting new rows in a table with out hard coding.

    HI,
    I'm trying to insert a new row into a table without hardcoding the value. How do I do that. Is their an example someone can provide me. Thanks.

    The problem goes something like this below.

    empid is to be 1 greater than the largest existing empid
    ename will be your Oracle userid
    rank should be whichever rank is associated with the lowest-paid salesperson.
    If there is more than one lowest-paid salesperson then select the minimum rank.
    salary should be 10% more than the lowest-paid salesperson. If there is more than one lowest-paid salesperson then select the minimum salary.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You have to get the result using SELECT and use that to insert

    INSERT INTO table
    SELECT query

  3. #3
    Join Date
    Oct 2006
    Posts
    5

    thanks

    thanks, I'll try that.

  4. #4
    Join Date
    Sep 2006
    Posts
    9

    Solution

    Try this one

    insert into new_table
    (select * from old_table)


    I hope this works...

  5. #5
    Join Date
    Oct 2005
    Posts
    2,557
    There are several things going on with this homework question/problem. The first has to do with using a sequence, more than likely adding a new empid one more than the current one is driven off of a sequence. The second has to do with using built-in system variables/values (keyword: user). The third involves ranking and selection of minimum, and the last is using an in-line change to a current value (set salary*1.1).

    What does your attempt look like?

  6. #6
    Join Date
    Nov 2006
    Posts
    2
    maybe something like the following will do:


    create sequence xxx nocache;

    insert into ttt (id,username, job,rank, sal)
    select (xxx.nextval, user, 'salesperson',min(rank) over (partition by job ), min(sal) over (partition by job )
    from ttt
    where job = 'salesperson'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •