Insert with Select while Using Merge

Actual Query
MERGE INTO schema1.employees D
   USING (SELECT employee_id, salary, department_id FROM schema2.employees
   WHERE department_id = 80) S
   ON (D.employee_id = S.employee_id)
   WHEN MATCHED THEN
   UPDATE
   SET D.bonus = D.bonus + S.salary*.01
   WHERE (S.salary > 8000)
   WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
   VALUES (S.employee_id, S.salary*.01)
   WHERE (S.salary <= 8000) Is there a possible way to write a select Query in Insert Statement while using Merge.
  WHEN NOT MATCHED THEN
   INSERT
   SELECT * FROM schema2.employees
   WHERE S.salary <= 8000;

it works:
MERGE INTO fifapps.tes2
using dual
on (1=2)
when not matched then insert values(59,'yes');
commit;or
MERGE INTO fifapps.tes2
using dual
on (1=2)
when not matched then insert values ((select 99 from dual),(select'weii' from dual));
commit;Edited by: ʃʃp on Jun 13, 2012 2:03 AM
Edited by: ʃʃp on Jun 13, 2012 2:03 AM

Similar Messages

  • Compilation problem with templates while using option -m64

    Hi,
    I have compilation problem with template while using option -m64.
    No problem while using option -m32.
    @ uname -a
    SunOS snt5010 5.10 Generic_127111-11 sun4v sparc SUNW,SPARC-Enterprise-T5220
    $ CC -V
    CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25
    Here is some C++ program
    ############# foo5.cpp #############
    template <typename T, T N, unsigned long S = sizeof(T) * 8>
    struct static_number_of_ones
    static const T m_value = static_number_of_ones<T, N, S - 1>::m_value >> 1;
    static const unsigned long m_count = static_number_of_ones<T, N, S - 1>::m_count + (static_number_of_ones<T, N, S - 1>::m_value & 0x1);
    template <typename T, T N>
    struct static_number_of_ones<T, N, 0>
    static const T m_value = N;
    static const unsigned long m_count = 0;
    template <typename T, T N>
    struct static_is_power_of_2
    static const bool m_result = (static_number_of_ones<T,N>::m_count == 1);
    template <unsigned long N>
    struct static_number_is_power_of_2
    static const bool m_result = (static_number_of_ones<unsigned long, N>::m_count == 1);
    int main(int argc)
    int ret = 0;
    if (argc > 1)
    ret += static_is_power_of_2<unsigned short, 16>::m_result;
    ret += static_is_power_of_2<unsigned int, 16>::m_result;
    ret += static_is_power_of_2<unsigned long, 16>::m_result;
    ret += static_number_is_power_of_2<16>::m_result;
    else
    ret += static_is_power_of_2<unsigned short, 17>::m_result;
    ret += static_is_power_of_2<unsigned int, 17>::m_result;
    ret += static_is_power_of_2<unsigned long, 17>::m_result;
    ret += static_number_is_power_of_2<17>::m_result;
    return ret;
    Compiation:
    @ CC -m32 foo5.cpp
    // No problem
    @ CC -m64 foo5.cpp
    "foo5.cpp", line 20: Error: An integer constant expression is required here.
    "foo5.cpp", line 36: Where: While specializing "static_is_power_of_2<unsigned long, 16>".
    "foo5.cpp", line 36: Where: Specialized in non-template code.
    "foo5.cpp", line 26: Error: An integer constant expression is required here.
    "foo5.cpp", line 37: Where: While specializing "static_number_is_power_of_2<16>".
    "foo5.cpp", line 37: Where: Specialized in non-template code.
    "foo5.cpp", line 20: Error: An integer constant expression is required here.
    "foo5.cpp", line 43: Where: While specializing "static_is_power_of_2<unsigned long, 17>".
    "foo5.cpp", line 43: Where: Specialized in non-template code.
    "foo5.cpp", line 26: Error: An integer constant expression is required here.
    "foo5.cpp", line 44: Where: While specializing "static_number_is_power_of_2<17>".
    "foo5.cpp", line 44: Where: Specialized in non-template code.
    4 Error(s) detected.
    Predefined macro:
    @ CC -m32 -xdumpmacros=defs foo5.cpp | & tee log32
    @ CC -m64 -xdumpmacros=defs foo5.cpp | & tee log64
    @ diff log32 log64
    7c7
    < #define __TIME__ "09:24:58"
    #define __TIME__ "09:25:38"20c20
    < #define __sparcv8plus 1
    #define __sparcv9 1[snipped]
    =========================
    What is wrong?
    Thanks,
    Alex Vinokur

    Bug 6749491 has been filed for this problem. It will be visible at [http://bugs.sun.com] in a day or two.
    If you have a service contract with Sun, you can ask to have this bug's priority raised, and get a pre-release version of a compiler patch that fixes the problem.
    Otherwise, you can check for new patches from time to time at
    [http://developers.sun.com/sunstudio/downloads/patches/]
    and see whether this bug is listed as fixed.

  • Getting ORA-00001 while using MERGE

    hi there,
    I am loading data from one Oracle table into another, using MERGE. My target table has a primary key constraint on TRANS_DATE, SEQ_NR and FILE_NAME. I have made sure that there are no duplicate rows in the the source table with regard to the target tables's primary key.
    The problem is that I am getting ORA-00001: Primary Key Violated ...
    my code is as follows:
    declare
    begin
    merge into fact_prepaidcalls_tb TARG
    using
    select
    nvl(fact_prepcustomers_tb.subscriberid,0) SUBSCRIBERID,
    accnum ACCNUM,
    sdrdate TRANS_DATE,
    TO_NUMBER(to_char(sdrdate,'yyyymmdd')) DIMDATEID,
    return_timeid(sdrdate) DIMTIMEID,
    return_peaktimeid(to_char(PAY_SDR.SDRDATE,'hh24miss'),SDRDATE) DIMPEAKTIMEID,
    nvl(dim_calltype.dimcalltypeid,0) DIMCALLTYPEID,
    sdrduration CHARGEDURATION,
    nvl(dim_tds_term.DIMTDStermid,9999) DIMTDSTERMID,
    calling CALLING,
    called CALLED,
    cparty CPARTY,
    freetimeused FREETIMEUSED,
    creditused CREDITUSED,
    creditrebate CREDITREBATE,
    servicetax SERVICETAX,
    surcharge SURCHARGE,
    follow FOLLOW,
    nvl(dim_call_location.dimcalllocationid,0) DIMCALLLOCATIONID,
    startbalance STARTBALANCE,
    priceoption PRICEOPTION,
    nvl(dim_cos.dimcosid,0) DIMCOSID,
    nvl(debitrate1,0) DEBITRATE1,
    debitrate2,
    prepaid.pay_sdr.region REGION,
    substr(file_name, instr(file_name,'cdr')) FILE_NAME,
    seq_nr SEQ_NR,
    SYSDATE LOADDATE,
    ORIGINNODE
    from prepaid.pay_sdr, dim_call_location, dim_calltype, dim_cos, dim_tds_term, fact_prepcustomers_tb
    where sdrdate >= to_date('10-Feb-2008 000000','dd-mon-rrrr hh24miss') and
    sdrdate <= to_date('10-Feb-2008 235959','dd-mon-rrrr hh24miss') and
    fact_prepcustomers_tb.msisdn = prepaid.pay_sdr.accnum and
    dim_calltype.calltypeid = prepaid.pay_sdr.type and
    dim_call_location.cellid = prepaid.pay_sdr.region and
    dim_cos.cosid = prepaid.pay_sdr.cos and
    dim_tds_term.termid = prepaid.pay_sdr.term
    ) SOUR
    on
    TARG.TRANS_DATE = SOUR.TRANS_DATE      and          
    TARG.SEQ_NR = SOUR.SEQ_NR      and          
    TARG.FILE_NAME = SOUR.FILE_NAME
    when not matched then
    --load fact data
    insert
    ( SUBSCRIBERID,
    ACCNUM,
    TRANS_DATE,
    DIMDATEID,
    DIMTIMEID,
    DIMPEAKTIMEID,
    DIMCALLTYPEID,
    CHARGEDURATION,
    DIMTDSTERMID,
    CALLING,
    CALLED,
    CPARTY,
    FREETIMEUSED,
    CREDITUSED,
    CREDITREBATE,
    SERVICETAX,
    SURCHARGE,
    FOLLOW,
    DIMCALLLOCATIONID,
    STARTBALANCE,
    PRICEOPTION,
    DIMCOSID,
    DEBITRATE1,
    DEBITRATE2,
    REGION,
    FILE_NAME,
    SEQ_NR,
    LOADDATE,
    CALLCHARGE,
    originnode)
    values
    ( SOUR.subscriberid,
    SOUR.ACCNUM,
    SOUR.TRANS_DATE,
    SOUR.DIMDATEID,
    SOUR.DIMTIMEID,
    SOUR.DIMPEAKTIMEID,
    SOUR.DIMCALLTYPEID,
    SOUR.CHARGEDURATION,
    SOUR.DIMTDSTERMID,
    SOUR.CALLING,
    SOUR.CALLED,
    SOUR.CPARTY,
    SOUR.FREETIMEUSED,
    SOUR.CREDITUSED,
    SOUR.CREDITREBATE,
    SOUR.SERVICETAX,
    SOUR.SURCHARGE,
    SOUR.FOLLOW,
    SOUR.DIMCALLLOCATIONID,
    SOUR.STARTBALANCE,
    SOUR.PRICEOPTION,
    SOUR.DIMCOSID,
    SOUR.DEBITRATE1,
    SOUR.DEBITRATE2,
    SOUR.REGION,
    SOUR.FILE_NAME,
    SOUR.SEQ_NR,
    SOUR.LOADDATE,
    SOUR.DEBITRATE1,
    SOUR.originnode);
    commit;
    end;

    Hi,
    you're missing WHEN MATCHED THEN <update_clause>
    {noformat}
    MERGE <hint> INTO <table_name>
    USING <table_view_or_query>
    ON (<condition>)
    WHEN MATCHED THEN <update_clause>
    DELETE <where_clause>
    WHEN NOT MATCHED THEN <insert_clause>
    [LOG ERRORS <log_errors_clause> <reject limit <integer | unlimited>];
    {noformat}
    Edited by: bobbydj on Sep 18, 2008 4:53 PM
    or you can try and add the primary key in the on condition

  • EMOD - Parse error while using merge fields

    Hello Everyone,
    We are using EMOD for email campaigns. We have renamed "Contact" object to "Rep Contact". When I insert merge fields on Rep Contact object, I get parse error message...
    Parse error in file at line 40: Could not find matching '}' for reference to variable at line 39
    Has anyone else come across this? Are there any restrictions in EMOD for using merge fields?
    Thanks.

    Thanks VK. I checked the source code and it is still perplexing why this error is coming up. It works fine without merge fields. I am pasting the section of html code with merge fields...
    <tr>
    <td valign="top" width="25" bgcolor="#ffffff"> </td>
    <td valign="top" bgcolor="#ffffff"><font face="Arial, Helvetica, sans-serif" style="font-size: 12px">Hello</font> ${Rep Contact.First Name} 
    <p><font face="Arial, Helvetica, sans-serif" style="font-size: 12px">What if there&rsquo;s another flash crash? What if we enter a double dip? These are just a few fears weighing heavily on investors&rsquo; minds in today&rsquo;s environment of uncertainty. <sup>1</sup> </font></p>
    <font face="Arial, Helvetica, sans-serif" style="font-size: 12px">
    <p>View or download: <a>3 ways to address risk-averse clients&rsquo; needs</a>.</p>
    </font>
    </td>
    </tr>

  • How to insert with select in table with object types

    I am in the proces of redesigning some tables, as i have upgraded from
    personal oracle 7 to personal oracle 8i.
    I have constructed an object type Address_type, which is one of the columns
    in a table named DestTable.
    The object type is created as follows:
    CREATE OR REPLACE TYPE pub.address_type
    AS OBJECT
    Street1 varchar2(50),
    Street2 varchar2(50),
    ZipCode varchar2(10));
    The table is created as follows:
    CREATE TABLE pub.DestTable
    (id INTEGER PRIMARY KEY,
    LastName varchar2(30),
    FirstName varchar2(25),
    Address pub.address_type);
    Inserting a single row is ok as i use the following syntax:
    Insert into DestTable(1, '******* ', 'Lawrence', pub.address_type(
    '500 Oracle Parkway', 'Box 59510', '95045'));
    When i try to insert values into the table by selecting from another table i
    cannot do it and cannot figure out what is wrong
    I have used the following syntax:
    Insert into DestTable
    id, name, pub.address_type(Street1, Street2, ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    I have also tried the following syntax:
    Insert into DestTable
    id, name, pub.address_type(Address.Street1, Address.Street2,Address.ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    What is wrong here ?
    null

    Magnus,
    1. Check out the examples on 'insert with subquery' in http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a85397/state21b.htm#2065648
    2. Correct your syntax that repeated the column definition after "insert into ..."
    Insert into DestTable
    id, name, pub.address_type(Street1, Street2, ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    Regards,
    Geoff
    null

  • Issues with selection tools using PS CS6

    OK, I'm having issues with selections in Photoshop CC…   This video shows my issue (which I never had with CS3).  Basically, I go to select an area within an image, and then the selection area disappears, and when I go to move the selection area I am unable to get the selection to "drop".  This happens regardless of whether I'm using my wacom tablet or my trackpad.  My mac is a 2009 macbook pro running 10.8.5.  Updated my OS and wacom tablet with the latest drivers.  I've gone into preferences and disabled the GPU, but to not avail.  Haven't run into this issue at work using CS6 (but i'm on a windows box there) Any ideas?  Any help would be greatly appreciated ;-) http://www.youtube.com/watch?v=FGPla7V9QI8

    say, SAKNR is 10 character field and ur appending only 6 characters, then it will give such type of errors normally.
    before inserting the data to ur Z table use function module... CONVERSION_EXIT_ALPHA_INPUT

  • I am facing lots of problems with security while using Mozilla. How can I send you a detailed report for this?

    I am getting redirected to unknown sites whenever I open any site while using mozilla. Initially I thought that there is a problem with my device, but then I realized that this happens only when using mozilla, not with other browsers like chrome, IE, or opera.
    These sites are mainly having the message 'Ad by ShopDrop'..
    I am pasting below links to few sites to which I get redirected to
    http://offers.bycontext<i></i>.com/scjs/tb/ctxjs/index<i></i>.php?kw2=www.espncricinfo<i></i>.com&affid=1151&subaff_id=725_724&intformat=roll&nextpage=http%3A%2F%2Fwww.espncricinfo<i></i>.com%2F&ch=421&sbrand=ShopDrop&folder=v4.19&typrd=ctx&cu=32929&country=IN&original_country=IN
    http://add0n<i></i>.com/fastest-gmail.html?v=0.1.6&p=0.1.5&type=upgrade

    hello, you have various malicious addons present. please perform all these steps:
    # [[Reset Firefox – easily fix most problems|reset firefox]] (this will keep your bookmarks and passwords)
    # afterwards go to the firefox menu ≡ > addons > extensions and in case there are still extensions listed there, disable them.
    # finally run a full scan of your system with different security tools like the [http://www.malwarebytes.org/products/malwarebytes_free free version of malwarebytes] and [http://www.bleepingcomputer.com/download/adwcleaner/ adwcleaner] to make sure that adware isn't present in other places of your system as well.
    [[Troubleshoot Firefox issues caused by malware]]

  • I am having sound issues with Pottermore while using Safari 6.1. I once muted the sound and now can't unmute it even though the icon tells me it's unmated. I can hear samples of audio books in the store section.  Any ideas?

    I am having sound issues with the website Pottermore while using Safari 6.1. I once muted the sound and now can't unmute it even though the icon tells me it's unmuted. I can hear samples of audio books in the store section.  Any ideas? I have reset Safari.  Website works fine on Firefox.

    I am having sound issues with the website Pottermore while using Safari 6.1. I once muted the sound and now can't unmute it even though the icon tells me it's unmuted. I can hear samples of audio books in the store section.  Any ideas? I have reset Safari.  Website works fine on Firefox.

  • Adding all dimensions while using merging

    HI All,
    I have 2 data providers.
    D1: year, quarter, revenue
    D2: year, country, sale revenue
    now  in webi after using merging i am not able to add all dimensions (year,quarter and country) in same table, please suggest any work around.
    thanks
    Mohit Gupta

    Agree with Sathish ...
    You should only use merged dimension + Details with cardinality of 1:1 and measures in the same table
    Here is another discussion where the same topic was discussed earlier
    Merge dimensions, Combined query, Sub Query

  • #SYNTAX error while using Merge Dimension in webi report

    Hi All,
    # Syntax error when using merge dimension in webi report
    screen shot has been attached.
    iam using BO 4.0 SP6
    checked the datatypes in BW
    they are same in BW in both the queries
    i followed the given links but no result.
    https://websmp230.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/sno/ui_entry/entry.htm?param=69765F6D6F64653D3030312669765F7361706E6F7465735F6E756D6265723D3138343530303526
    https://websmp230.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/sno/ui_entry/entry.htm?param=69765F6D6F64653D3030312669765F7361706E6F7465735F6E756D6265723D3136323339323126
    https://websmp230.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/sno/ui_entry/entry.htm?param=69765F6D6F64653D3030312669765F7361706E6F7465735F6E756D6265723D3137353438313026
    http://scn.sap.com/thread/3592588#15241008
    Need Help!!!!!
    Regards
    Sushma

    Hi Mark,
    Thanks for the reply,
    I did not use any formula,
    I used merge dimension
    Anyways i tried in other system,it s working fine.
    Regards
    sushma

  • Merging calendar with iCloud while using gmail account

    I have a me.com account that I never use - just bought it years ago when I got mobileme and my calendar has always synced easily from my mac to my iphone. I never read the info about the switch to icloud which is probably why I'm confused now. But all the sudden my iphone calendar isn't syncing with my mac calendar. The key is, I don't want to have to change my email to my "me.com" address to use the calendars. Also, would like to use notes but not sure I can without switching to me.com. Any suggestions?

    An iCloud email account is required to sync notes with iCloud.  You don't have to use the email account but it must be present on your phone.  Just create the account, then go to Settings>Mail,Contacts,Calendars>Default Account (in the Mail section) and make sure this is set to your Gmail account.  Then just ignore the iCloud email account.

  • Error while using Merge statement

    Hi,
    Can any one please look at the merge statement and help me understand the error.Thanks in advance.
    MERGE /*+ APPEND */
    INTO intf_lpa_master m
    USING (SELECT std_district_student_id,
    std_grade_code,
    sub_test,
    test_date,
    performance_lvl_code,
    test_lang_code,
    v_student_id,
    v_test_id,
    v_lang_cd,
    v_plc,
    valid_test_date,
    -- school_year,
    -- school_id,
    valid_src_stu_id,
    test_code
    FROM intf_lpa_master_vw
    MINUS
    SELECT std_district_student_id,
    std_grade_code,
    sub_test,
    test_date,
    performance_lvl_code,
    test_lang_code,
    v_student_id,
    v_test_id,
    v_lang_cd,
    v_plc,
    valid_test_date,
    -- school_yr,
    -- school_id,
    valid_src_stu_id,
    test_code
    FROM intf_lpa_master
    WHERE active_flag = 'Y') v
    ON ( m.std_district_student_id = v.std_district_student_id
    AND m.sub_test = v.sub_test
    AND m.test_date = v.test_date)
    WHEN MATCHED
    THEN
    UPDATE SET m.std_grade_code = v.std_grade_code,
    m.performance_lvl_code = v.performance_lvl_code,
    m.test_lang_code = v.test_lang_code,
    m.active_flag = 'Y', -- if we are touching this record, it is to be active.
    m.error_message = NULL, -- refresh these, to properly reconsider records.
    m.create_date = SYSDATE,
    m.record_id = intf_lpa_master_seq.NEXTVAL,
    m.process_row = 'U',
    m.last_update_date = SYSDATE,
    m.last_update_user = 'PRE_PROCESS_LPA - UPDATE',
    -- m.job_id = c_run_id ,
    m.validation_step = NULL, -- refresh these, to properly reconsider records.
    m.v_student_id = v.v_student_id,
    m.v_test_id = v.v_test_id,
    m.v_lang_cd = v.v_lang_cd,
    m.v_plc = v.v_plc,
    m.valid_test_date = v.valid_test_date,
    -- m.school_year = v.schloo_year,
    -- m.school_id = v.school_id,
    m.valid_src_stu_id = v.valid_src_stu_id,
    m.test_code = v.test_code
    WHEN NOT MATCHED
    THEN
    INSERT (
    m.std_district_student_id,
    m.std_grade_code,
    m.sub_test,
    m.test_date,
    m.performance_lvl_code,
    m.test_lang_code,
    m.active_flag,
    m.error_message,
    m.create_date,
    m.record_id,
    m.process_row,
    m.last_update_date,
    m.last_update_user,
    -- m.job_id,
    m.validation_step,
    m.v_student_id,
    m.v_test_id,
    m.v_lang_cd,
    m.v_plc,
    m.valid_test_date,
    -- m. school_year,
    -- m. school_id,
    m.valid_src_stu_id,
    m.test_code)
    VALUES (
    v.std_district_student_id,
    v.std_grade_code,
    v.sub_test,
    v.test_date,
    v.performance_lvl_code,
    v.test_lang_code,
    'Y',
    NULL,
    SYSDATE,
    intf_lpa_master_seq.NEXTVAL,
    'I',
    SYSDATE,
    'PRE_PROCESS_LPA - INSERT',
    -- c_run_id,
    NULL,
    v.v_student_id,
    v.v_test_id,
    v.v_lang_cd,
    v.v_plc,
    v.valid_test_date,
    -- v. school_year,
    -- v. school_id,
    v.valid_src_stut_id,
    v.test_code);
    Error Message :
    ORA-06553 : PLS-306:wrong number or types of arguments in call to 'V'

    There are a couple of thngs wrong here. In the when matched insert column list, you cannot qualify the field name with the table alias. It should be just:
    insert (std_district_student_id, std_grade_code, sub_test ...)Are v_student_id, v_test_id, v_lang_cd, and v_plc really columns in the intf_lpa_master table? I am more used to seeing v_name as a variable naming convention than a column name, but I could be wrong.
    John

  • OIM 11Unknown entity type Account with ID while using linkEventToUser() API

    I would like to link an recon event (which is in status "No User Match Found" ) to an user.The recon event is generated through target recon using reconciliation API
    I am using the API linkEventToUser() but getting the following error.
    <Error> <oracle.iam.reconciliation.impl> <IAM-5010000> <Generic Error/Information: {0}
    oracle.iam.reconciliation.exception.InvalidEventException: Unknown entity type Account with ID 2180,060
    From OIM web console if i check the Link button / option iin event management for this event is greyed out.
    There are already threads on this in the forum but they are old and no replies so i thought to post a fresh thread.
    I am also getting the same error while generating a new recon event.
    The strangest part is that this was working a few weeks back.
    Any help or idea how to proceed is highly appreciated.
    Thanks and Regards,
    Kungo.
    Edited by: Kungo on Oct 25, 2012 3:06 AM

    Any one saw this thread :)
    Is there a way to get attention on this thread from all the Gurus on this forum ?
    Please do let me know.
    Thanks and Regards,
    Kungo

  • Create a followup document with selected items using actions

    Hi Experts,
    We are working on CRM 5.0 with ECC 6.0 as backend.
    As per the clients business process we have to create a service order automatically from a sales order whenever there is a serviceline item with item category ZSRV presents in the sales order. The service order which is created should only contain service line item with item category ZSRV. Which means the action should copy only the selected line items to the service order.
    Now the problem is using the standard method COPY_DOCUMENT, I dont have any option for selecting the line items. I have found a method COPY_DEF_ITEMS which may be the most relavant for my scenario. But I am not able to give the processing parameters for this.
    Can any body help me about how to use the standard method    COPY_DEF_ITEMS.
    Points shall be rewarded for the helpful answer.
    Regards,
    Madhu

    PDF was never designed to support the Flash page curl effect (it didn't exist back then). Anything you try (and you've tried the standard hack) will look like a hack. Personally, I don't think the effort is worth it for an effect that's much overused.

  • 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.

Maybe you are looking for

  • What are different ways to pass variables in a c# program?

    What are different ways to pass variables in a c# program? I was wondering if : var numbers = textBox1.Text.Split(' .Select(int.Parse).ToArray(); var min = numbers.Min(); var max = numbers.Max(); textBox2.Text = string.Format("min: {0} max: {1}", min

  • HP P7-1235 Video

    I have a P7-1235, and recently purchased a Radeon HD 7850, and a new Rosewill 500 Watt PS. I am having trouble disabling onboard video tho as it does not have the option in the BIOS, do I need to completely uninstall the existing video from onboard t

  • Tcov Code Coverage Libraries missing from Sun Studio 12!!!

    Hi, When I try to collect coverage statistics using the -xprofile=tcov I get the following message f90     -xprofile=tcov -w0 -C  -c ./intfaces.f90 -o ./scovintfaces.o f90     -xprofile=tcov -w0 -C  -c ./gcovsrc.f90 -o ./scovsrc.o f90     -xprofile=t

  • Dialup connection on e72 to connect to a wifi netw...

    Hi,   I recently bought e72 . I thought it was easy connecting to my wifi modem, while I am at hme . My issue is that I am having BSNL(NETWORK NAME) broadband network. I have connected it to a wifi. Its not always ON BROADBAND, I need to enter my use

  • How to "synch" an excell file if any changes are made to file?

    I have an 8330 & use media manager. I have "watch folders" operating. Should this function automatically update the file on my blackberry if I make changes on the desktop & visa versa? It isn't keeping the files synchronized automatically, so do I ha