INSERT - SELECT

Hello

I need to insert into the table salary_dep values. In the first column, I want to insert the value of the sequence, in further four columns I want to insert values to select. This statement should explain what I want to do (of course the assertion is incorrect, it is for explanation):

INSERT INTO salary_dep (sal_ID, employe_id, JOB_ID, SALARY, department_id) values)

new_seq. NEXTVAL, JOB_ID, SALARY, select EMPLOYEE_ID department_id from employee where department_id = 60);

create the table salary_dep

(sal_ID NUMBER (6,0),)

EMPLOYE_ID NUMBER (6.0).

JOB_ID VARCHAR2 (10 BYTE),

NUMBER (8.2) OF SALARY.

DEPARTMENT_ID NUMBER (4,0));

You cannot combine values in an insert and select. Try

INSERT INTO salary_dep (sal_ID, EMPLOYEE_ID, JOB_ID, SALARY, DEPARTMENT_ID)
select new_seq.NEXTVAL, EMPLOYEE_ID, JOB_ID, SALARY, DEPARTMENT_ID from employees where department_ID = 60;

Tags: Database

Similar Questions

  • Using a variable in an Insert / Select

    Oracle 11 g 2

    It is a block of the size of the code. I want to use a variable in the clause values an Insert / Select using the execute immediate statement.

    g_sysdate date := sysdate
    

    I can't ' use sysdate directly because it is a long-term process. We attribute sysdate to g_sysdate at the beginning of the procedure and we stored in several tables. Therefore, it has the same value everywhere.

    I'm getting ORA-00904: "G_SYSDATE": invalid identifier

    create table usa.work_time
    ( id number ,
      work_status_id number ,
      work_task_id number ,
      txt_msg varchar2(255)
    )
    /
    
    create table usa.work_time_arc
    ( id number ,
      work_status_id number ,
      work_task_id number ,
      txt_msg varchar2(255),
      archived_dt date
    )
    /
    
    insert into usa.work_time values(1,2,3,'hello');
    
    commit ;
    
    DECLARE
       v_query varchar2(2000);
       g_sysdate date := sysdate ;
       v_tbl_arc varchar2(61) := 'usa.work_time_arc';
       v_tbl_src varchar2(61) := 'usa.work_time';
       v_tab_cols varchar2(2000) := 'id,work_status_id,work_task_id,txt_msg';
       v_id number := 9521;
    BEGIN
       v_query := 'insert /*+ append */ into '||v_tbl_arc || ' (' || v_tab_cols || ',archived_dt)' || 
                                  'select ' || v_tab_cols || ',g_sysdate from ' || v_tbl_src || 
                               ' where id = :id';
       dbms_output.put_line(v_query);
       
       execute immediate v_query using v_id ;
    END ;
    /
    
    ERROR at line 1:
    ORA-00904: "G_SYSDATE": invalid identifier
    ORA-06512: at line 14
    
    
    
    

    That should do it.

    DECLARE
       v_query varchar2(2000);
       g_sysdate date := sysdate ;
       v_tbl_arc varchar2(61) := 'usa.work_time_arc';
       v_tbl_src varchar2(61) := 'usa.work_time';
       v_tab_cols varchar2(2000) := 'id,work_status_id,work_task_id,txt_msg';
       v_id number := 9521;
    BEGIN
       v_query := 'insert /*+ append */ into '||v_tbl_arc || ' (' || v_tab_cols || ',archived_dt)' ||
                                  'select ' || v_tab_cols || ',:g_sysdate from ' || v_tbl_src ||
                               ' where id = :id';
       dbms_output.put_line(v_query);  
    
       execute immediate v_query using g_sysdate, v_id ;
    END ;
    /
    
  • Insert select on the same table: possible without side effects?

    I have a very large table T1 containing millions of records. I need to treat its lines and create a few new lines based on selection.

    Table T1 contains events and one of them, with the code 100, is created by the further development of other events inside the table.

    My code is as follows:

    insert /*+append */ into T1 (code,...) values (100, c1,c2,...)
    select c1,c2... from T1 where (code=20 or code=10) and <other conditions>...
    
    

    as you can see I'm extract T1 lines to insert again in T1 with a different code and I use the direct path in order to get good performance.

    My fear is: choose is made from the same table I risk data loss? In general it is a good practice? Or is it better to create another table?

    Hello

    No I don't think that there may be loss of data. But that may depend on the behavior of the application and your where clause.

    I will explain how it is treated, so you can see if it's ok:

    1. the table is locked because of the insert add, (as)

    2 lines are read by select and make compatible from the State that was at the beginning of the query - 1.

    3 rows are inserted at the end, after the high-water line

    4 columns for new lines are sorted to be merged in the index

    5. high watermark is adjusted - visible new lines and lock is released

    Note that 2. and 3. occur at the same time: rows are inserted all read.

    Note that anyone can choose in the table during the operation - they see the changes committed only - if the State 1.

    all other DML are waiting for the lock being released, and will see new ranks and then

    If you have things that prevent the direct-path insert, append the hint will be ignored. So, if you must rely on close to 1. then the best lock explicitly with table lock. But I don't think that you need.

    Kind regards

    Franck.

  • Insert selected in several checked uncheck the delete record

    Hi all

    I have a detailed block I add a checkbox not database once check the records is inserted into the temporary table

    the same records uncheck the box delete records

    IAM has inserted when checking the records of the table

    but when I have a check only check all records are deleted in my temporary table

    WHEN-BOX-CHANGE

    declare

    v_app_user_id integer (10);

    number of v_count;

    Start

    v_app_user_id: = dtc_util.get_global_value('dtc_global.user_id');

    go_block ('RULE_ITEM');

    premier_enregistrement;

    loop

    SELECT count (1) in the dtc_rule_item_lock v_count

    where rule_item_id =: rule_item.rule_item_id;

    If Checkbox_Checked ('rule_item.checkout') and v_count = 0 then

    insert into dtc_rule_item_lock values (:rule_item.rule_item_id, v_app_user_id, sysdate);

    ELSIF: RULE_ITEM. BOX = 'n' then

    DELETE FROM dtc_rule_item_lock

    where exists (select 'x' from dtc_rule_item dtcl

    where dtcl.rule_item_id =: rule_item.rule_item_id);

    end if;

    When the output: system.last_record = "TRUE";

    next_record;

    end loop;

    premier_enregistrement;

    If form_success or sqlcode = 0 then

    message ("documents saved successfully in the database '");

    message (' ', no_acknowledge);

    FORMS_DDL ('COMMIT');

    on the other

    message ("error saving documents: ' |") SQLERRM);

    message (' ', no_acknowledge);

    end if;

    end;

    Let me help you for this

    Thank you

    Olivier

    I guess there is the clause does not. You check against dtc_rule_item, I guess that is dtc_rule_item_lock.

  • the non-null values insert select

    Please could you help me on this:

    INSERT INTO new_table (ID, hobby, country, internal_id, cat)

    SELECT ID, hobby, country internal_id,

    Max (CASE cat WHEN = 'ben' THEN 1

    WHAT cat = 'ale' THEN 2

    WHAT cat = 'inf' THEN 3

    WHAT cat = "cad" THEN 4

    WHAT cat = 'juv' THEN 5

    WHAT cat = 'sen' THEN 6

    WHAT cat = 'teacher' THEN 7

    END)

    Ancienne_table GROUP BY ID, hobby, country, internal_id;

    the lines on ancienne_table have duplicates regs as follows:

    IDCountryHobbyInternal_IDCAT
    1OmanRugby Union63180Juv
    1OmanRugby Union63180Teacher
    1OmanRugby Union63180Juv

    the request requires the output as follows:

    IDCountryHobbyInternal_IDCAT
    1OmanRugby Union631807

    because cat = 'juv' (5) is less cat =' teacher (7).

    all columns are not null and the primary key of the new_table is ID + hobby

    The script displays the following output:

    01400 00000 - 'impossible to insert NULL into (%s)' because does not recognize the function max.

    Thanks in advance.

    Kind regards.

    Actually there are values not in the range of cat. There is an error in the old data table.

    I proceeded to remove the lines out of reach in the cat because column that are not relevant in this case.

    The parameters I use Oracle are:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for 64-bit Windows: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    Thank you very much. You are so helpful.

    Kind regards.

  • Question of the insertion-selection

    Hi all

    I need help with this issue:

    [code]

        with table2 as
    (
        select 'N' col1,1 NR from dual union all
        select 'N',2 from dual union all
        select 'S',3   from dual union all
        select 'S',4  from dual union all
        select 'S',5 from dual union all
        select 'N',6  from dual union all
        select 'N',7  from dual union all
        select 'S',8  from dual
       )
       
            INSERT INTO table1 aa
            SELECT        
                CASE
                WHEN pl.col1 = 'N'   THEN '10'
                WHEN pl.col1 = 'S'   THEN
                                 ............
                                 .....
            FROM table2 PL 
            WHERE ....
    

    [/ code]

    Table 1 has a column

    How can insert into table 1, the value

    [code]

            insert '10' into first(1)  row of table1 when DML process first row of table2  AND has in col1=N
            insert '10' into second(2)  ......
           
                 insert '11' into (3) row of table1 when DML process 3 row of table2 and has in col1=S (it should be 11 (10 inserted in previous row(max value in table1)  and sum + 1)
                 insert '12' into (4) row of table1 when DML process 4 row of table2 and has in col1=S (it should be 12 (11 inserted in previous row and sum + 1)
                 insert '13' into (5) row of table1 when DML process 5 row of table2 and has in col1=S (it should be 13 (12 inserted in previous row and sum + 1)
            insert '10' into (6) row of table2
            insert '10' into (7) row of table2
                 insert '14' into (5) row of table1 when DML process 5 row of table2 and has in col1=S (it should be 14 (13 inserted in previous rows because max value in table1 is 13 and sum + 1)
    

    [/ code]

    It is my goal in table1:

    [code]

    1--> 10
    2--> 10
    3--> 11
    4--> 12
    5--> 13
    6--> 10
    7--> 10
    8--> 14
    

    [/ code]

    Thanks in advance for any help

    Hello

    You can use the ROW_NUMBER analytic function to generate consecutive numbers.

    Here's a way to do what you asked:

    INSERT INTO table1 (num_1)

    SELECT THE CHECK BOX

    WHEN col1 = ' don't

    THEN 10

    ANOTHER 10 + ROW_NUMBER () OVER (PARTITION BY col1

    ORDER BY NULL

    )

    END

    FROM table2

    ;

  • Insert select with the id auto incream

    CREATE TABLE LOG
    (NUMBER OF 'ID',
    VARCHAR2 (30 BYTE) "ROLEUSER."
    VARCHAR2 (30 BYTE) "ROLENAME",.
    "studentId" VARCHAR2 (11 BYTE)
    )
    then I insert in the newspaper (ROLEUSER, ROLENAME, studentID) (select ROLEUSER, ROLENAME, studentID of table a, b).
    where a.userid = buserid)
    I want to get every row I insert the id auto insert with number of automatic increase
    then I have insert into Log(ROLEUSER, ROLENAME, studentID)( select ROLEUSER, ROLENAME, studentID from table a, b
    

    Use

    insert into Log(ID, ROLEUSER, ROLENAME, studentID)( select ROWNUM, ROLEUSER, ROLENAME, studentID from table a, b
    where a.userid=buserid)
    
  • Urgent: DELETE, INSERT, SELECT INTO, UPDATE Performance problem

    Hello

    NEED HELP TO OPTIMIZE the INSERT (insertion in select):
    =================================================
    We have a report.

    According to the current design the following steps are used to populate the custom table that is used to signal the end:

    (1) REMOVE all records of the custom table XXX_TEMP_REP.
    (2) INSERT records in the custom of table XXX_TEMP_REP (assumes all records associated with type A)
    using
    INSERT... IN... SELECT...
    statement.

    (3) update records in XXX_TEMP_REP
    using a custom logic for records populated.

    (4) INSERT records in the custom of table XXX_TEMP_REP (records associated with type B)
    using
    INSERT... IN... SELECT...
    statement.

    Collected statistics related to Insert statement are:

    Wait event information
    ---------------------

    Event expects 460 SID: db file sequential read
    P1 text: file No.
    P1 The value: 20
    P2 text: block #.
    P2 Value: 435039
    P3 text: blocks
    P3 Value: 1


    Session statistics
    -----------------

    size: 293,84 M
    Parse count (hard): 34
    Parse count (total): 1217
    the user undertakes: 3

    Transaction and Rollback Information
    -----------------------------------

    Rollback used: 35.1796875 M
    Rollback Records: 355886
    Rollback Segment number: 12
    Rollback Segment name: _SYSSMU12$
    Logical IOs: 1627182
    Physical IOs: 136409
    RBS Startng measure ID: 14
    Transaction start time: 29/09/10 04:22:11
    Transaction_Status: ACTIVE

    Please suggest how this can be optimized.

    Kind regards
    Ngandu

    Hello

    Y at - it nothing to do with the Oracle Forms tool?

    François

  • Support for mandatory request - insert, select from the same table

    Hi all

    I need your help to write queries effectively.
    Oracle Version: 10.2.0.3.0
    OPERATING SYSTEM: UNIX

    I have a METRICS_TBL that is mentioned below table.

    CYCLE_DATE METRIC VALUE
    08/17/2008 COST-TV 100
    08/17/2008 COST-JOURNAL 50
    08/17/2008 COST-POSTALMAIL 25
    08/17/2008-PROD-TV 10
    08/17/2008-PROD-JOURNAL 25
    08/17/2008-PROD-POSTALMAIL 5

    Any data above, I have to add (Insert into select METRICS_TBL METRICS_TBL) at the same table with the records as mentioned below.

    2008-08-17 COSTPERPROD-TV 10
    08/17/2008-COSTPERPROD-LOG 2
    2008-08-17 COST PROD-POSTALMAIL 5

    Basically, I need to calculate the cost per product for each category. Depending on the settings available, metric should also be changed as COSTPERPROD and values should be cost/prod under each category.

    Can someone help me with the query.

    Thank you

    Something like this:

    INSERT INTO metrics_tbl
    (cycle_date, metrics, value)
    SELECT cost.cycle_date
             , 'COSTPERPROD-'||cost.mtype
             ,cost.value / prod.value
    FROM  (
       select cycle_date,substr(metrics, 1, 4) mtype, substrmetrics,instr(metrics,'-')+1) mmetric
       where substr(metrics, 1, 4) = 'PROD'
       ) prod
    INNER JOIN (   select cycle_date,substr(metrics, 1, 4) mtype, substrmetrics,instr(metrics,'-')+1) mmetric
       where substr(metrics, 1, 4) = 'COST'
       ) cost on cost.cycle_date = prod.cycle_date and cost.mmetric = prod.mmetric
    

    Ideally you would divide your METRICS column into two: one for the thing you're measuring (e.g. TV or NEWSPAPER) and the other for the metric (COST, PROD, COSTPERPROD etc.). That's what I did in the views online. Without it, it's kinda a mess and behave so, if the table becomes much more.

    HTH

    Nigel cordially

    Edited by: nthomas on January 14, 2009 15:57 - small correction SQL

  • Insert/select a single application!

    Hi, I have the following query that inserts a new row in the users table

    SELECT a.areaID, b.SID FROM areas a, u users WHERE u.userID =? AND u.areaIDFK = a.areaID

    The users table also has a user name, which is a primary key


    I wanted to know how can I insert a line as described and ALSO returns the corresponding user name without having to make a second query?

    Hi, I have the following query that inserts a new row in the users table

    Well, no. You have a SELECT statement.

    Maybe you're talking about how to get the value of a sequence number that was inserted just:

    SQL> declare
      2     new_id number;
      3  begin
      4     insert into users (userid) values (users_seq.nextval) returning userid into new_id;
      5     dbms_output.put_line('new userid = ' || new_id);
      6  end;
      7  /
    new userid = 19
    
    PL/SQL procedure successfully completed.
    
  • Merge / insert / select

    SQL> merge into dbsid_lookup a using
      2  (select dbsidlookup_id from dbsid_lookup,servers,dbsids) b
      3  on (b."ID" = a.serverlookup_id and b.dbsid_id = a.sidlookup_id)
      4  when matched then
      5  update set a.sidlookup_id = (select dbsid_id from dbsids where dbsid_name = 'tcsprd')
      6  when not matched then
      7  insert (a.serverlookup_id,a.sidlookup_id)
      8  values ( select "ID",dbsid_id from servers,dbsids where host_name = 'bscdb01' and dbsid_name = 'tcsprd' );
    The sky gives me an error that says:
    ERROR at line 8:
    ORA-00936: missing expression
    I must be missing something simple so it is frustrating.

    I think you need to maybe adjust or replace conditional with your appropriate State of health. Otherwise, the code should work.

    Kind regards.

    LOULOU.

  • Action - item Menu insert &gt; select &gt; free Transfom &gt; Warp?

    Hi all

    As the title suggests, I would like to create an action for "select > free Transfom > Warp". The STRING for my selection must currently be triggered by clicking on the distortion grid in the mode of selection of processing.

    I would like to find a way to create an action, so I can link to a key. for example every time that I have an active selection, running that action would automatically enter the DEFORMATION mode for the outline of this particular selection.

    any ideas?

    Adobe conditional Action only take on a limited number of condition. The condition to test is one of them.  If there is a selection active document. you just need to record an action for the condition. Your version of photoshop needs to take supported conditional actions. The layer change will also be the active layer target or have a single well-known known name or a known level of layer in the layer stack, so the action can target the layer.  Any selection will trigger the execution of one continuous piece as disconnected from the areas of selection. All actions that are used must be in the same game of action and the action defined. All should not be renamed and actions cannot be renamed or moved or copied in other action games.

  • Connection from Oracle to DB2 LUW and Asian data insertion/selection.

    Hello

    I have configured the connectivity between Oracle and DB2 LUW, using DG40DBC but my requirement is to see the characters Asian (Chinese, Japanese, etc). Then, when I select the data through DB DB2 link I get of the question marks (?). We need to change the settings in the configuration files to support this language?

    Any help is very appreciated!

    Thank you
    Steve.

    Isql instruction is not able to display characters unicode is partly justified. In my (Linux with LANG value UTF8) env it displays Chinese and Japanese characters.

    You can also try to use the unicode equivalent to "isql" called "iusql. In addition, please provide the character set of your DB2 database.

    Published by: kgronau on January 16, 2012 06:31

    Also DG4ODBC displays correctly using your ODBC from above and these DG4ODBC settings:
    HS_FDS_SHAREABLE_NAME =/home/odbc64/unixODBC/2.3/lib/libodbc.so
    HS_NLS_NCHAR = UCS2
    HS_LANGUAGE = AMERICAN_AMERICA. AL32UTF8

    For a DB2 database using this character set parameter:
    Database code page = 1208
    Database of codeset = UTF - 8

  • Check out when a last accessed table (select, insert, update) with time stamp. Auditing enabled

    Hello world

    IM pretty new to audit the database. Auditing is enabled in the database. I would like to retrieve the news all of the objects belonged to a certain pattern when it was last accessed (select, insert, update) with time stamp. Is there any script for this? Your time and your reply is greatly appreciated. Thank you.

    Database version: 11.2.0.4

    Enable audit is not quite enough to get the details when the table is updated/inserted/selected.

    You must activate audting on the object level, then you may only be able to see your report of your choice.

    SELECT OBJ_NAME, ACTION_NAME, to_char (timestamp, ' dd/mm/yyyy, hh') of sys.dba_audit_object.

  • 2015 Dreamweaver does not have ready php functions (insert, delete and select)

    Hello all the dreamweaver configuration is correct, but when I use the ready functions insert, select, delete, login (php in the database) does not work, I tried everything already and what works is to do it manually. What can you do for me?

    See here http://www.dmxzone.com/go/21842/enable-server-behaviors-and-data-bindings-panel-support-fo r-dreamweaver-cc

Maybe you are looking for

  • Unable to connect my iPhone 6 to apple ID

    Morning, I have an iMac connected to my apple PB ID but I am not able to connect my iPhone 6 to even apple ID. Rpet error Id or password Could someone help? THX

  • PIXMAR MX432 PRINTER

    Hello: I'm trying to connect my PIXMA MX432 printer to my new computer Windows 10. I can't the location. The driver is still available? I downloaded a driver from the 430 series, but it does not work. Help, please. Thank you Howardf

  • I can only start using the list of Windows XP

    Original title: WINDOWS XP STARTUP W/DISC PROBLEMS I have a problem starting my desktop xp computer. I can ONLY start with the XP disk, of course, I have to press 'R' over and over again. After a few tries, it starts well, how can I start up without

  • Sony Xperia Weather App display incorrect time on Sony Xperia XZ

    In the United Kingdom, the clocks are back 1 hour this morning. The network provided on the phone time is correct, however the Sony Xperia weather weather application always shows the clock an hour before.

  • HP Pavilion dv3 Notebook PC - cannot use Bluetooth to transfer files from mobile phone to laptop

    Please help me how to solve my problem using the bluetooth device. because I can not send the file using the blutooth device... ANOTHER PROBLEM... MY AUDIO DEVICE... WHEN I PLAY MUSIC to the ITUNES HELP he stopped for 3 seconds and continued to songs