Insert a sequence in select statement

Hi,
I want to create a table like:
create table test as
select a, b, c, NR
from source
NR should be a number got out from a sequence. How do I have to adopt the statement to make it run?
Thanks for help,
Walter

Exactly...
use
create table test as
select a, b, c, NR.nextval
from sourceThank you....

Similar Messages

  • How to insert variable value using select statement - Oracle function

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this.
    thanks

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this. Do not select Case_Status from inner select, so null will be inserted then after inserting it update the case status with m_caseStatus.
    Regards.

  • How to insert ORACLE HINT into select statement....

    Hi team,
    Can you please suggest me how to add an Oracle hint to point the Program to BSAD~1.
    Index BSAD1 has all three fields MANDT, BUKRS, AUGDT which are there in the where clause. But as per the execution plan index BSAD0 is being used which is the primary one.
    Also the stats for this table are are current.
    Thanks in Advance.
    Puneet.

    Hi punnet, look at this example:
      SELECT MAX( kkop~augbd )
      INTO it_gen_docs-augbd
      FROM ( fkkvkp AS vkp INNER JOIN dfkkop AS kkop
         ON vkpvkont = kkopvkont ) INNER JOIN dfkkko AS kkko
         ON kkopaugbl = kkkoopbel
      WHERE vkp~exvko = ti_cuentas-exvko
            AND kkop~bukrs = p_bukrs
            AND kkop~blart IN r_blart
            AND kkop~augst = '9'
            AND kkko~blart IN r_blartd
    %_HINTS ORACLE 'INDEX("DFKKOP" "DFKKOP~Z07")'.
    DFKKOP is the table name and DFKKOP~Z07 is the index.
    I hope this helps you.

  • T-SQL - PL/SQL conversion: insert into ... select problem

    Hi!
    If I have an insert into ... select statement in T-SQL without a 'from' clause:
    bq. insert into sometable (foo, bar) \\ select 5, case when @bar=5 then 4 else 3 end
    its translation is:
    bq. INSERT INTO sometable \\ ( foo, bar ) \\ VALUES ( 5, CASE \\ WHEN 5 = 5 THEN 4 \\ ELSE 3 \\ END col );
    and I got: ORA-00917: "missing comma" for that. I'm not sure if it's a bug in the migration code, or is there a trick so that I can use 'CASE' in an insert into .. values statement somehow?
    Zoli

    You have to remove the column name. I just simplified your test case to check and it's working:
    CREATE TABLE test(
      id NUMBER
    INSERT
      INTO test(id)
      VALUES(CASE WHEN 5=5 THEN 4 ELSE 3 END)
    SELECT *
      FROM test
    ;C.

  • Sequence error in select statement

    Does anyone know why I get the following error when I run the code below. If so, how can it be fixed.
    Thanks in advance,
    John C
    ORA-02287 sequence number not allowed here
    INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
    SELECT DISTINCT A.CREATIVE,
    B.CMPGN_KEY,
    PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
    FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
    ROCEONOF.NACQ0211_2_FINAL@OGD A
    WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM');

    John
    It is the DISTINCT which is causing the trouble. How about:
    INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
    SELECT COL1, COL2, PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
    FROM
    (SELECT DISTINCT A.CREATIVE COL1, B.CMPGN_KEY COL2
    FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
    ROCEONOF.NACQ0211_2_FINAL@OGD A
    WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM'));
    Incidentally, judging by the column names, it appears that the columns in your insert statement are not listed in the same order as in the select statement, which of course they should be.

  • Smart scan not working with Insert Select statements

    We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
    Can you please help us to explain this behavior?

    There is a specific exadata forum - you would do better to post the question there: Exadata
    I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
    Regards
    Jonathan Lewis

  • Number of rows inserted is different in bulk insert using select statement

    I am facing a problem in bulk insert using SELECT statement.
    My sql statement is like below.
    strQuery :='INSERT INTO TAB3
    (SELECT t1.c1,t2.c2
    FROM TAB1 t1, TAB2 t2
    WHERE t1.c1 = t2.c1
    AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
    EXECUTE IMMEDIATE strQuery ;
    These SQL statements are inside a procedure. And this procedure is called from C#.
    The number of rows returned by the "SELECT" query is 70.
    On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
    But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
    And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
    On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
    Anybody faced these kind of issues?
    Can anyone tell what would be the reason of this issue..? any other work around for this...?
    I am using Oracle 10g R2 version.
    Edited by: user13339527 on Jun 29, 2010 3:55 AM
    Edited by: user13339527 on Jun 29, 2010 3:56 AM

    You have very likely concurrent transactions on the database:
    >
    By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
    >
    If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
    Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
    You can try to run your test with:
    set  transaction isolation level  serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
    like:
    wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46

  • Insert using select statement

    Hi,
    I am trying to insert values using select statement. But this is not working
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    VALUES
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;
    Please let me know what i am missing..
    Thanks
    Sudhir

    Try this
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;Note: when you are selecting a value using select statement, you should not specify the keyword "values".
    i assume you have already assigned value for your bind variable :P1_PROJECTS and rest of the functions will return some value.
    Regards,
    Prazy

  • Fields sequence in the select statement

    experts, help needed
    itab has following fields,
    vbeln posnr erdat erzet vkorg vtweg
    kunnr posnr matnr bmeng status.
    i have written like this
    SELECT avbeln aerdat aerzet avkorg a~vtweg
    akunnr bposnr b~matnr
    FROM vbak AS a INNER JOIN vbap AS b
    ON avbeln = bvbeln
    INTO TABLE itab1
    FOR ALL ENTRIES IN itab
    WHERE a~vbeln = itab-vbeln.
    endif.
    but my internal table fields sequence are different. so i changed the posnr field in the select query to the second place.
    SELECT avbeln  bposnr  aerdat aerzet avkorg avtweg
    akunnr bmatnr
    FROM vbak AS a INNER JOIN vbap AS b
    ON avbeln = bvbeln
    INTO TABLE itab1
    FOR ALL ENTRIES IN itab
    WHERE a~vbeln = itab-vbeln.
    endif.
    so in above two select statements which one is right , according to coding standards,?
    in this case do i need to use the into corresponding fields addition because i am not selecting bmeng , status fields into the itab?

    Hi,
    Of the two select statements,
    SELECT a~vbeln b~posnr a~erdat a~erzet a~vkorg a~vtweg
    a~kunnr b~matnr
    FROM vbak AS a INNER JOIN vbap AS b
    ON a~vbeln = b~vbeln
    INTO TABLE itab1
    FOR ALL ENTRIES IN itab
    WHERE a~vbeln = itab-vbeln.
    is the better one. I,e specifyiig the field sequence exactly as you have in the internal table. Even according to standards, this is better.
    If you are chaning the sequence of select fields, then you have to use the INTO CORRESPONDING FILEDS OF TABLE addition, so that the system itself finds the relevant order of fields and fill them automatically.
    This is a additional work which has to be performed by the compiler.
    Thus its better to use INTO CORRESPONDING FILEDS OF TABLE only when you are using select * , or when you are not sure of the field sequence inthe table.
    Regards,
    Vik

  • Insert select statement or insert in cursor

    hi all,
    i need a performance compare for: insert operation in cursor one by one and select statement insert,
    for example:
    1. insert into TableA (ColumA,ColumnB) select A, B from TableB;
    2. cursor my_cur is select A, B from TableB
    for my_rec in my_cur loop
    insert into TableA (ColumA,ColumnB) values (my_rec.A, my_rec.B);
    end loop;
    also "bulk collect into" can be used.
    Which one has a better performance?
    Thanks for your help,
    kadriye

    What's stopping you from making 100,000 rows of test data and trying it for yourself?
    Edit: I was bored enough to do it myself.
    Starting insert as select 22-JUL-08 11.43.19.544000000 +01:00
    finished insert as select. 22-JUL-08 11.43.19.825000000 +01:00
    starting cursor loop 22-JUL-08 11.43.21.497000000 +01:00
    finished cursor loop 22-JUL-08 11.43.35.185000000 +01:00
    The two second gap between the two is for the delete.
    Message was edited by:
    Dave Hemming

  • Select Statement takes more time after immediate insert statement..

    Hello,
    I found below scenario
    1. I have table TABLE1 which has index on COL1 field. It has around 40 columns and 100000 rows.
    2. whenever i insert 100000 rows in bulk with changing indexed key column and executing SELECT statement in same session then it takes around 3 mins to complete.
    3. However, if i open new session and execute same select statement then it returns in 2-3 seconds.
    I didnt get anything in XPLAN.. :(
    I felt Buffer Clean is cause to take time. please let me know your opinion.
    Thanks in Advance
    Sach

    sach09 wrote:
    Hello,
    I found below scenario
    1. I have table TABLE1 which has index on COL1 field. It has around 40 columns and 100000 rows.
    2. whenever i insert 100000 rows in bulk with changing indexed key column and executing SELECT statement in same session then it takes around 3 mins to complete.
    3. However, if i open new session and execute same select statement then it returns in 2-3 seconds.
    I didnt get anything in XPLAN.. :(
    I felt Buffer Clean is cause to take time. please let me know your opinion.Are you running the query in the other session after running it from the first?
    Aman....

  • SQL insert with select statement having strange results

    So I have the below sql (edited a bit). Now here's the problem.
    I can run the select statement just fine, i get 48 rows back. When I run with the insert statement, a total of 9062 rows are inserted. What gives?
    <SQL>
    INSERT INTO mars_aes_data
    (rpt_id, shpdt, blno, stt, shpr_nad, branch_tableS, csgn_nad,
    csgnnm1, foreign_code, pnt_des, des, eccn_no, entity_no,
    odtc_cert_ind, dep_date, equipment_no, haz_flag, schd_no,
    schd_desc, rec_value, iso_ulti_dest, odtc_exempt, itn,
    liscence_no, liscence_flag, liscence_code, mblno, mot,
    cntry_load, pnt_load, origin_state, airline_prefix, qty1, qty2,
    ref_val, related, routed_flag, scac, odtc_indicator, seal_no,
    line_no, port_export, port_unlading, shipnum, shprnm1, veh_title,
    total_value, odtc_cat_code, unit1, unit2)
    SELECT 49, schemaP.tableS.shpdt, schemaP.tableS.blno,
    schemaP.tableS.stt, schemaP.tableS.shpr_nad,
    schemaP.tableM.branch_tableS, schemaP.tableS.csgn_nad,
    schemaP.tableS.csgnnm1, schemaP.tableD.foreign_code,
    schemaP.tableS.pnt_des, schemaP.tableS.des,
    schemaP.tableD.eccn_no, schemaP.tableN.entity_no,
    schemaP.tableD.odtc_cert_ind, schemaP.tableM.dep_date,
    schemaP.tableM.equipment_no, schemaP.tableM.haz_flag,
    schemaP.tableD.schd_no, schemaP.tableD.schd_desc,
    schemaP.tableD.rec_value,
    schemaP.tableM.iso_ulti_dest,
    schemaP.tableD.odtc_exempt, schemaP.tableM.itn,
    schemaP.tableD.liscence_no,
    schemaP.tableM.liscence_flag,
    schemaP.tableD.liscence_code, schemaP.tableS.mblno,
    schemaP.tableM.mot, schemaP.tableS.cntry_load,
    schemaP.tableS.pnt_load, schemaP.tableM.origin_state,
    schemaP.tableM.airline_prefix, schemaP.tableD.qty1,
    schemaP.tableD.qty2,
    schemaC.func_getRefs@link (schemaP.tableS.ptt, 'ZYX'),
    schemaP.tableM.related, schemaP.tableM.routed_flag,
    schemaP.tableM.scac, schemaP.tableD.odtc_indicator,
    schemaP.tableM.seal_no, schemaP.tableD.line_no,
    schemaP.tableM.port_export,
    schemaP.tableM.port_unlading, schemaP.tableS.shipnum,
    schemaP.tableS.shprnm1, schemaP.tableV.veh_title,
    schemaP.tableM.total_value,
    schemaP.tableD.odtc_cat_code, schemaP.tableD.unit1,
    schemaP.tableD.unit2
    FROM schemaP.tableD@link,
    schemaP.tableM@link,
    schemaP.tableN@link,
    schemaP.tableS@link,
    schemaP.tableV@link
    WHERE tableM.answer IN ('123', '456')
    AND SUBSTR (tableS.area, 1, 1) IN ('A', 'S')
    AND entity_no IN
    ('A',
    'B',
    'C',
    'D',
    'E',
    AND TO_DATE (SUBSTR (tableM.time_stamp, 1, 8), 'YYYYMMDD')
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'
    AND tableN.shipment= tableD.shipment(+)
    AND tableN.shipment= tableS.shipnum
    AND tableN.shipment= tableM.shipment(+)
    AND tableN.shipment= tableV.shipment(+)
    <SQL>
    Edited by: user11263048 on Jun 12, 2009 7:23 AM
    Edited by: user11263048 on Jun 12, 2009 7:27 AM

    Can you change this:
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'To this:
    BETWEEN TO_DATE('01-Mar-2009', 'DD-MON-YYYY')
    AND TO_DATE('31-Mar-2009','DD-MON-YYYY')That may make no difference but you should never rely on implicit conversions like that, they're always likely to cause you nasty surprises.
    If you're still getting the discrepancy, instead of and INSERT-SELECT, can you try a CREATE TABLE AS SELECT... just to see if you get the same result.

  • Behaviour of insert ... select statement

    Hi,
    If we use insert ... select statement like
    insert into TableA
    Select
    from TableB;
    and if TableB have 250000 rows then what will be the action for it..
    will all 250000 rows fetched to database buffer and if index scans are performed on it and then all rows inserted into TableA
    or
    it will do it parallel
    We are loading large data and facing performance problems for delaying index scans.
    Just Curious :)
    Rushang.

    it's not a secret. oracle will perform the select, using indexes if it decides to (depends on source table size, stats, optimizer mode, etc, etc). rows may be pulled back to memory be written to temp space (e.g., if you were returning many, many rows which needed to be grouped). the rows will then be inserted.
    so, if you have an index on tableb.col1, then oracle may use the index. or it may do a FTS. either way, it will only select the needed rows to be inserted.
    the insert does not prevent the select from working as it would normally.

  • Only select statements work (update/insert hang)

    Hi, I am running CF MX version 7,0,2,142559 Standard Edition
    and ColdFusion is hanging everytime I attempt an insert or update
    statement again Oracle 8i and 9i using the jdbc thin driver and an
    odbc socket driver.
    Select statements work fine. I have tried everything I could
    think of and I get the same results. All rights are given to the
    datasource and the user. I can do insert and update statement via
    another application (Toad) with the same Oracle user.
    Any suggestions??? I don't see any hot fixes for this but
    that doesn't mean one doesn't exist.
    Also, many times it causes the system cpu utlization to stick
    at 100% until I restart ColdFusion.
    Thanks for any help.

    Hi,
    I had similar results on Oracle 10G while using cfmx 7.02. I
    actually updated the macromedia_drivers.jar from the coldfusion
    support site.
    http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=42dcb10a
    An update to the datadirect JDBC drivers. Try that. If not,
    make sure you have the latest JDBC drivers from Oracle. Since
    previous versions would make the update/insert;s hang.

  • Select statement Table Join sequence (Performance)

    Hi,
    I have 3 tables Header (Hdr), Item (Itm) and Schedule Line (Sdl) table. The number of entries is max in Sdl table (Eg: Hdr = 1000; Item = 20000 and Sdl = 200000 records). I need to join these 3 tables in my SELECT statement to fetch the required records.
    Case A:
    Header AS HDR
    JOIN Item AS ITM
    ON HDRORDID = ITMORDID
    AND HDRVRSIOID = ITMVRSIOID
    JOIN ScheduleLine AS SDL
    ON ITMITMID = SDLITMID
    Case B:
    ScheduleLine AS SDL
    JOIN Item AS ITM
    ON ITMITMID = SDLITMID
    JOIN Header AS HDR
    ON HDRORDID = ITMORDID
    AND HDRVRSIOID = ITMVRSIOID
    Questions:
    1) The performance of the Select query is really bad with Case A and very good (really fast) with Case B. Will the number of records in the tables used determine the sequence of join in the Select statement ?
    2) If yes, is this independent of database used ? That is, will the behaviour be the same in all databases (Eg: Oracle, DB2, SQL Server, etc) ?
    Appreciate your help.
    Thanks,
    Karthik

    I believe that the performance discrepancy between the two versions is caused by you not specifying the joins correctly (i.e. not qualifying the header and item at schedule level as I mentioned previously).
    CAse A.
    Header AS HDR
    JOIN Item AS ITM
    ON HDRORDID = ITMORDID
    AND HDRVRSIOID = ITMVRSIOID
    JOIN ScheduleLine AS SDL
    ON ITMITMID = SDLITMID
    reads all 1000 hDRs, joins all 20000 items correctly to these BUT then joins schedule lines only by item id so there will be a very large number of matches. i.e. any item with itemid 10 will match to EVERY SDL with itemid 10. as there are 20000 items and 200000 schedule lines this will be massive!
    Case B:
    ScheduleLine AS SDL
    JOIN Item AS ITM
    ON ITMITMID = SDLITMID
    JOIN Header AS HDR
    ON HDRORDID = ITMORDID
    AND HDRVRSIOID = ITMVRSIOID
    This will not have the same amount of DB traffic as the SDL is now the driving force. It will still match more than you intend but will only be reading the items redundantly trather than the more voluminous schedules.
    Basically, your sql is wrong and should qualify the matches right down to schedule line level as per my earlier post. When you have changed the sql, try the two alternatives again and see if there is any performance differences. I suspect that there will not be, but it will be interesting to find out for sure.

Maybe you are looking for

  • ALV Grid with Excel

    Hi guys, I need show the Alv Gride Report and Excel mutualy. My program have six internal tables, and each internal table, need put in a sheet diferent of Excel. Is this possible? I found some classes on se24 but I didn´t find example here. Can you h

  • Apple TV - Slow Slideshow.

    I've selected '2 seconds' in "Time Per Slide' and 'dissolve' in 'Transition' but the images are showing for twice the usual length. 400 images make a 31min25sec show, that equals 4.68 seconds per slide not 2! What's going wrong? Can anyone help?

  • Third party battery recommendation

    Hi all, I am thinking about buying a new battery for my 15" Powerbook (FW 800). Anyone have recommendations for a good third party battery? I've found numerous references to the NuPower battery (though, does it matter that it's 11.1 V instead of 10.8

  • Splitting the timeline into two scenes

    Let me explain, I spent the last week shooting a movie for an English project that's due on Tuesday. I gave myself two days for the editing, because it really shouldn't of been too hard. I still don't think it would've been hard at all if Canon hadn'

  • PS crash when I use transform in animation mode!

    PS crash and close itself often when I use free transform tool(ctrl+t) on some selected area of an image. It happens in animation mode when Animation palette is shown (convert to frame animation I choose) and I working on certain frame. What it is an