Merge Statement in PL/SQL

Hi
I am using a merge statement where i am updating and inserting records in table 2 from table 1.
I want to log the no. of rows updated and new rows inserted in the log table.
If i am not wrong, we can use sql%rowcount but i need help as how to use this statement.
Please suggest a solution.
Thanks

user11018028 wrote:
Will the sql%rowcount will give the no. of updated rows OR no. of newly inserted rows OR the sum of both in case of a merge statement.Total number of rows that changed (SUM).

Similar Messages

  • Merge statement

    i would like to know if it is possible to identify the row that is causing the problem when you use a merge statement in pl/sql. i know if you create a cursor and then loop through the data you can identify the column but what about if i have only a merge that will either insert or update. is it possible to identify which row of data cause the problem? thanks

    You can use an Error Logging Table<br>
    <br>
    Nicolas.

  • Error logging in merge statement

    how to handle error logging in merge statement??
    thanks in advance!!!

    Welcome to the forum!
    Whenever you post please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    how to handle error logging in merge statement??
    >
    Do it the way the documentation tells you to.
    See the error_logging_clause of the MERGE statement in the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
    It contains an example of using error logging with MERGE
    >
    error_logging_clause
    The error_logging_clause has the same behavior in a MERGE statement as in an INSERT statement. Refer to the INSERT statement error_logging_clause for more information.
    See Also:
    "Inserting Into a Table with Error Logging: Example"

  • How to use Inner join of table as Source in Merge statement in SQL

    Hi All,
        I am trying to make source as multiple tables output using Join while coding there is no any syntax error but when i am executing this statement is giving following error
    Following is the query 
    Merge Into EmpDept Target
    Using (select E.Address,e.Design,e.EmailId,e.EmpId,e.Ename,e.ManagerId, e.Salary,D.DeptId,D.DeptName,D.Location from Employee E Inner join Dept D on E.DeptId=D.DeptId )As Source (Address,Design,EmailId,EmpId,EName,ManagerId,Salary,DeptId,DeptName,Location)
    On Source.EmpId=Target.EmpId
    when not matched then
    Insert (Target.Address,Target.Design,Target.EmailId,Target.EmpId,Target.Ename,Target.ManagerId, Target.Salary,Target.DeptId,Target.DeptName,Target.Location)
    values
    (Address,Design,EmailId,EmpId,EName,ManagerId, Salary,DeptId,DeptName,Location)
    When matched then 
    Update set Target.Address = Source.Address ,Target.Design = Source.Design,Target.EmailId      = Source.EmailId     ,Target.Ename       = Source.Ename      ,Target.ManagerId = Source.ManagerId , Target.Salary        = Source.Salary       ,Target.DeptId      = Source.DeptId      ,Target.DeptName = Source.DeptName ,Target.Location    = Source.Location;
    This is error while executing the above merge statement 
    The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.
    Please suggest me where i am wrong.. 
    Niraj Sevalkar

    MERGE INTO EmpDept Target
    Using (SELECT E.Address,
    e.Design,
    e.EmailId,
    e.EmpId,
    e.Ename,
    e.ManagerId,
    e.Salary,
    D.DeptId,
    D.DeptName,
    D.Location
    FROM Employee E
    INNER JOIN Dept D
    ON E.DeptId = D.DeptId) AS Source (Address, Design, EmailId, EmpId, EName, ManagerId, Salary, DeptId, DeptName, Location)
    ON Source.EmpId = Target.EmpId
    WHEN NOT matched THEN
    INSERT (Address,
    Design,
    EmailId,
    EmpId,
    Ename,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    VALUES (Address,
    Design,
    EmailId,
    EmpId,
    EName,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    WHEN matched THEN
    UPDATE SET Address = Source.Address,
    Design = Source.Design,
    EmailId = Source.EmailId,
    Ename = Source.Ename,
    ManagerId = Source.ManagerId,
    Salary = Source.Salary,
    DeptId = Source.DeptId,
    DeptName = Source.DeptName,
    Location = Source.Location;

  • Can u rectify the error  in merge statement in sql

    hi to all,
    i had created a duplicate table of emp with the name of copy_emp with no records.
    by using merge statement i want to update the existing rows and insert new rows into copy_emp table as follows ......
    merge into copy_emp c
    using emp e
    on(c.empno=e.empno) --------> here the error is ........ invalid column name
    when matched then
    update set c.empno=e.empno,.....
    when not matched then
    insert values(e.empno,e.job,e.sal........);

    merge into copy_emp c
    using emp e
    on(c.empno=e.empno) --------> here the error is ........ invalid column name
    when matched then
    update set c.ename=e.ename,.....
    when not matched then
    insert values(e.empno,e.job,e.sal........);
    take off empno from update clause.

  • Managing the first application of the MERGE statement in an ETL logic - SQL Server 2012

    Hi,
    in order to feed a fact table of a dwh from a staging table I'm using the MERGE statement in order to control insert and update operations. It is possible that the staging table has duplicate rows respect to the fields controlled in the merge condition:
    when I run the first time the MERGE statement unwanted rows could be inserted in the fact table.
    Does the MERGE statement allow to manage this case or do I need to filter data from the staging table before to write them into the fact table?
    Many thanks

    Hi Anuj,
    thank for your reply. Unfortunately the DISTINCT in the using clause isn't enough for my case: I need to read a subset of fields of a staging table and for this subset I could have duplicate rows, but also I need to the change date of the rows inserted in
    the staging table and I cannot include this date in the distincted columns.
    However the answer is that I need to handle the staging data before to write them into the fact table.
    Thanks
    Yes
    One more thing to note is when running MERGE statement subsequently in case there are multiple records which matches the update criteria then default behavior of MERGE is to throw an error indicating that it tried to update same record twice.
    So in any case you need to make sure you eliminate duplicates before applying MERGE over it at first.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Can sql merge statement be used in a batch (oracle 10g)?

    Hello,
    I am trying to insert into an oracle table multiple rows of values selected from a web page. Can I use a merge statement as a preparedStatement to avoid inserting duplicate records?
    Does anybody have any examples they would like to share?
    Any suggestions are greatly appreciated.
    Thank you,
    Logan

    I've implemented this by batch inserting into a temp table then running a merge then dropping the temp table.
    public void mergeMethod() {
            final String createsql = "CREATE TABLE temp (a INTEGER, b INTEGER, c INTEGER)";
            final String insertsql = "INSERT INTO temp (a, b, c) VALUES (?,?,?)";
            final String mergesql = "MERGE INTO my_table A " +
               "USING temp B ON (A.a = B.a AND A.b = B.b) " +
               "WHEN MATCHED THEN UPDATE SET A.c = B.c " +
               "WHEN NOT MATCHED THEN INSERT (A.id, A.a, A.b, A.c) " +
               "VALUES (my_seq.Nextval,B.a,B.b,B.c)";
            final String dropsql = "DROP TABLE temp";
         Connection conn = null;
         Statement cs = null;
         Statement ms = null;
         Statement ds = null;
         PreparedStatement ps = null;
         boolean retValue = false;
         try {
              conn = getConnection();
              conn.setAutoCommit(false);
              cs = conn.createStatement();
              ms = conn.createStatement();
              ds = conn.createStatement();
              ps = conn.prepareStatement(insertsql);
              for (int i=0; i< 10; i++){
                   ps.setInt(1, i);
                   ps.setInt(2, i+1);
                   ps.setInt(3, i+2);
                   ps.addBatch();
              // create temp table
              cs.execute(createsql);
              // execute in batch
              final int updateCount[] = ps.executeBatch();
              // merge the two tables
              ms.execute(mergesql);
              // drop the temp table
              ds.execute(dropsql);
              conn.commit();
              System.out.println("Rows is updated: " + updateCount.length);
         } catch (final SQLException e) {
              if (conn != null) {
                  conn.rollback();
              throw e;
         } finally {
              if (ps != null) {
                  ps.close();
              if (cs != null) {
                  cs.close();
              if (ms != null) {
                  ms.close();
              if (ds != null) {
                  ds.close();
              if (conn != null) {
                  conn.close();
    }

  • Current flag on merge statement T-SQL

    Hi there,
    I was using Type 2 for one of our Fact table.... and need to put a flag to know which one is the Current record...
    I couldnt able to figure how to implement logic in the merge statement... Can anyone guide me please
    this is an example Query ....I was using like this for my fact table...
    Basically I need to track CustomerName and City... So I need a Currentflag (Y) for latest record....
    MERGE INTO [dbo].[TargetCustomer] AS TRG
    USING [dbo].[MyCustomers] AS SRC
    ON TRG.[CustomerID] = SRC.[CustomerID]
    AND TRG.[CustomerName]=SRC.[CustomerName]
    AND TRG.[City]=SRC.[City]
    WHEN MATCHED THEN
    UPDATE SET
    TRG.[Province]=SRC.[Province]
    -- TRG.[Current Flag] = 'N'
    WHEN NOT MATCHED THEN
    INSERT ([CustomerID]
    ,[CustomerName]
    ,[City]
    ,[Province]
    ,[LastUpdate]
    ,[Current Flag]
    VALUES (
    [CustomerID]
    ,[CustomerName]
    ,[City]
    ,[Province]
    ,[LastUpdate]
    ,'Y'

    it should be like this
    INSERT INTO [dbo].TargetCustomer
    [CustomerID]
    ,[CustomerName]
    ,[City]
    ,[Province]
    ,[LastUpdate]
    ,[Current Flag]
    SELECT
    [CustomerID]
    ,[CustomerName]
    ,[City]
    ,[Province]
    ,[LastUpdate]
    ,'Y'
    FROM
    MERGE INTO [dbo].[TargetCustomer] AS TRG
    USING [dbo].[MyCustomers] AS SRC
    ON TRG.[CustomerID] = SRC.[CustomerID]
    AND TRG.[CustomerName]=SRC.[CustomerName]
    AND TRG.[City]=SRC.[City]
    WHEN MATCHED THEN
    UPDATE SET
    LastUpdate = GETDATE(),
    TRG.[Current Flag] = 'N'
    WHEN NOT MATCHED THEN
    INSERT ([CustomerID]
    ,[CustomerName]
    ,[City]
    ,[Province]
    ,[LastUpdate]
    ,[Current Flag]
    VALUES (
    [CustomerID]
    ,[CustomerName]
    ,[City]
    ,[Province]
    ,[LastUpdate]
    ,'Y'
    OUTPUT $Action AS Action,
    SRC.CustomerID,
    SRC.[CustomerName],
    SRC.[City],
    SRC.[Province],
    SRC.[LastUpdate]
    )AS t
    [CustomerID]
    ,[CustomerName]
    ,[City]
    ,[Province]
    ,[LastUpdate]
    WHERE Action = 'UPDATE';
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Issue with Oracle Merge statements (PL/SQL: ORA-00913: too many values)

    Hi All,
    I am using the below merge statement and I am getting too many rows issues when I am compiling.
    BEGIN
    FOR te_rec IN ( SELECT /*+ parallel(ts,4) */ te.dtv_acct_num FROM telcos_eligible te, telcos_setup ts, telcos_partners tp
    WHERE tp.telcos_name = UPPER((p_telcos_name))
    AND ts.partner_id = tp.partner_id
    AND te.ts_id = ts.ts_id ) LOOP
    MERGE INTO tcs_accounts
    USING (
    SELECT /*+ DRIVING_SITE(a) */account_id, a.subscriber_id, status, account_type FROM account@tcs_to_paris a WHERE a.subscriber_id = te_rec.dtv_acct_num
    ) paris_accounts
    ON (tcs_accounts.subscriber_id = paris_accounts.subscriber_id)
    WHEN MATCHED THEN
    UPDATE SET
    account_type = paris_accounts.account_type,
    subscriber_id = paris_acounts.subscriber_id,
    status = paris_accounts.status
    WHEN NOT MATCHED THEN
    INSERT(account_id, subscriber_id, status_account_type)
    VALUES(paris_accounts.account_id, paris_accounts.subscriber_id, paris_accounts.status, paris_accounts.account_type);
    END LOOP;
    END;
    Can you let me know what is the issue here.
    Thanks,
    MK.

    Hi,
    Maddy wrote:
    ... WHEN NOT MATCHED THEN
    INSERT(account_id, subscriber_id, status_account_type)
    VALUES(paris_accounts.account_id, paris_accounts.subscriber_id, paris_accounts.status, paris_accounts.account_type);This is one of the many times when a little formatting can really help you. Anybody can forget a column (or have an extra one, or type a _ when they mean ,) but if you write code like this
    INSERT (               account_id,                 subscriber_id,                                  status_account_type)
    VALUES (paris_accounts.account_id,  paris_accounts.subscriber_id,  paris_accounts.status,  paris_accounts.account_type);you might spot the error yourself.
    Always format your code. When you post any formatted text on thsi site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Error executing a stored procedure from SSIS using the MERGE statement between databases

    Good morning,
    I'm trying to execute from SSIS a stored procedure that compares the content of two tables on different databases in the same server and updates one of them. To perform this action, I've created a stored procedure in the destination database and I'm
    comparing the data between tables with the MERGE statement. When I execute the procedure on the destination database the error that I obtain is:
    "Msg 916, Level 14, State 1, Procedure RefreshDestinationTable, Line 13
    The server principal "XXXX" is not able to access the database "XXXX" under the current security context."
    Some things to take in account:
    1. I've created a temporary table on the same destination database to check if the problem was on the MERGE statement and it works fine.
    2. I've created the procedure with the option "WITH EXECUTE AS DBO".
    I've read that it can be a problem of permissions but I don't know if I'm executing the procedure from SSIS to which user/login I should give permissions and which.
    Could you give me some tip to continue investigating how to solve the problem?
    Thank you,
    Virgilio

    Read Erland's article http://www.sommarskog.se/grantperm.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Instead of trigger is NOT firing for merge statements in Oracle 10gR2

    The trigger fires fine for a update statement, but not when I use a merge statement
    with an update clause. Instead I get the normal error for the view ( which is a union all view, and therefore not updatable.)
    The error is :-
    ORA-01733: virtual column not allowed here
    oracle release is 10.2.0.2 for AIX 64L
    Is this a known bug ?
    I've used a multi-table insert statement to work around the problem for inserts, but
    for updates, I'd really like to be able to use a merge statement instead of an update.
    Mark.

    This is my cut-down version :-
    In this case case I'm getting an :-
    ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP BY, etc.
    rather then the ora-01733 error I get in the real code ( which is an update from an involved
    XML expression - cast to a table form)
    create table a ( a int primary key , b char(30) ) ;
    create table b ( a int primary key , b char(30) ) ;
    create view vw_a as
    select *
    from a
    union all
    select *
    from b ;
    ALTER VIEW vw_a ADD (
    PRIMARY KEY
    (a) DISABLE);
    DROP TRIGGER TRG_IO_U_ALL_AB;
    CREATE OR REPLACE trigger TRG_IO_U_ALL_AB
    instead of update ON vw_a
    for each row
    begin
    update a targ
    set b = :new.b
    where targ.a = :new.a
    if SQL%ROWCOUNT = 0
    then
         update b targ
         set b      = :new.b
         where targ.a = :new.a
    end if ;
    end ;
    insert into a values (1,'one');
    insert into a values (2,'two');
    insert into a values (3,'three');
    insert into b values (4,'quatre');
    insert into b values (5,'cinq');
    insert into b values (6,'six');
    commit;
    create table c as select a + 3 as a, b from a ;
    commit;
    merge into vw_a targ
    using (select * from c ) src
    on ( targ.a = src.a )
    when matched
    then update
    set targ.b = src. b
    select * from vw_a ;
    rollback ;
    update vw_a b
    set b = ( select c.b from c where b.a = c.a )
    where exists ( select c.b from c where b.a = c.a ) ;
    select * from vw_a ;
    rollback ;

  • Help needed in MERGE statement

    Hi,
    I am new to PL/SQL, I want to update a table called "final_test" based on the below query result.
    1. I want to check whether that particular record is present or not in my "final_test" table.
    2. If its present in the "final_test" table and the process_status got changed then I want to update that alone in my "final_test" table.
    3. If its not present then I want to insert that record into my "final_test" table.
    Basically I am retrieving the report and its status for a particular date.
    select
    b.id,
    a.name,
    a.t_name,
    c.process_status,
    c.time_process
    from rep_tab_map a, j_tab_map b, proc_status c
    where a.t_name=b.t_name
    and b.id=c.id (+)
    and trunc(c.date_start)=trunc(sysdate -1)
    group by a.name,b.id,c.process_status,c.time_process,a.t_name
    order by 2
    I thought of using Merge statement but i am not sure what i have to use in ":USING" and "ON" clause.
    Please help me with MERGE or with someother way.
    Thanks

    Assuming final_test has same structure as select list in your query:
    merge
      into final_test a
      using (
             select  b.id,
                     a.name,
                     a.t_name,
                     c.process_status,
                     c.time_process
               from  rep_tab_map a,
                     j_tab_map b,
                     proc_status c
               where a.t_name=b.t_name
                 and b.id=c.id(+)
                 and trunc(c.date_start)=trunc(sysdate -1)
               group by a.name,b.id,c.process_status,c.time_process,a.t_name
            ) b
      on (b.id = a.id)
      when matched then update set a.name = case a.process_status
                                              when b.process_status then a.name
                                              else b.name
                                            end,
                                   a.t_name = case a.process_status
                                                when b.process_status then a.t_name
                                                else b.t_name
                                              end,
                                   a.process_status = b.process_status,
                                   a.time_process = case a.process_status
                                                      when b.process_status then a.time_process
                                                      else b.time_process
                                                    end
      when not matched then insert(
                                   a.id,
                                   a.name,
                                   a.t_name,
                                   a.process_status,
                                   a.time_process
                            values(
                                   b.id,
                                   b.name,
                                   b.t_name,
                                   b.process_status,
                                   b.time_process
    /SY.

  • Problem in Merge statement

    Hi All,
    I am using merge statement to update 30000 records from the tables having 55 lacs records.
    But it is taking much time as i have to kill the session after 12 hours,as it was still going on.
    If,Same update i m doing using cursors,it will finish in less than 3 hours.
    Merge i was using is :-
    MERGE INTO Table1 a
    USING (SELECT MAX (TO_DATE ( TO_CHAR (contact_date, 'dd/mm/yyyy')
    || contact_time,
    'dd/mm/yyyy HH24:Mi:SS'
    ) m_condate,
    appl_id
    FROM Table2 b,
    (SELECT DISTINCT acc_no acc_no
    FROM Table3, Table1
    WHERE acc_no=appl_id AND delinquent_flag= 'Y'
    AND financier_id='NEWACLOS') d
    WHERE d.acc_no = b.appl_id
    AND ( contacted_by IS NOT NULL
    OR followup_branch_code IS NOT NULL
    GROUP BY appl_id) c
    ON (a.appl_id = c.appl_id AND a.delinquent_flag = 'Y')
    WHEN MATCHED THEN
    UPDATE
    SET last_contact_date = c.m_condate;
    In this query table 1 has 30000 records and table2 and table 3 have 3670955 and 555674 records respectively.
    Please suggest,what i am doing wrong in merge,because as per my understanding merge statement is much better than updates or updates using cursors.
    Required info is as follows:
    SQL> show parameter user_dump_dest
    NAME TYPE VALUE
    user_dump_dest string /opt/oracle/admin/FINCLUAT/udu
    mp
    SQL> show parameter optimizer
    NAME TYPE VALUE
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 100
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    SQL> show parameter db_file_multi
    NAME TYPE VALUE
    db_file_multiblock_read_count integer 16
    SQL> show parameter db_block_size
    NAME TYPE VALUE
    db_block_size integer 8192
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL> select
    2 sname     ,
    3 pname     ,
    4 pval1     ,
    5 pval2
    6 from
    7 sys.aux_stats$;
    sys.aux_stats$
    ERROR at line 7:
    ORA-00942: table or view does not exist
    Elapsed: 00:00:00.05
    SQL> explain plan for
    2 -- put your statement here
    3 MERGE INTO cs_case_info a
    4      USING (SELECT MAX (TO_DATE ( TO_CHAR (contact_date, 'dd/mm/yyyy')
    5                          || contact_time,
    6                          'dd/mm/yyyy HH24:Mi:SS'
    7                          )
    8                ) m_condate,
    9                appl_id
    10           FROM CS_CASE_DETAILS_ACLOS b,
    11                (SELECT DISTINCT acc_no acc_no
    12                FROM NEWACLOS_RESEARCH_HIST_AYLA, cs_case_info
    13                WHERE acc_no=appl_id AND delinquent_flag= 'Y'
    14                AND financier_id='NEWACLOS') d
    15           WHERE d.acc_no = b.appl_id
    16           AND ( contacted_by IS NOT NULL
    17                OR followup_branch_code IS NOT NULL
    18                )
    19           GROUP BY appl_id) c
    20      ON (a.appl_id = c.appl_id AND a.delinquent_flag = 'Y')
    21      WHEN MATCHED THEN
    22      UPDATE
    23           SET last_contact_date = c.m_condate
    24      ;
    Explained.
    Elapsed: 00:00:00.08
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
    | 0 | MERGE STATEMENT | | 47156 | 874K| | 128K (1)|
    | 1 | MERGE | CS_CASE_INFO | | | | |
    | 2 | VIEW | | | | | |
    | 3 | HASH JOIN | | 47156 | 36M| 5672K| 128K (1)|
    | 4 | VIEW | | 47156 | 5111K| | 82339 (1)|
    | 5 | SORT GROUP BY | | 47156 | 4236K| 298M| 82339 (1)|
    | 6 | HASH JOIN | | 2820K| 247M| 10M| 60621 (1)|
    | 7 | HASH JOIN | | 216K| 7830K| | 6985 (1)|
    | 8 | VIEW | index$_join$_012 | 11033 | 258K| | 1583 (1)|
    | 9 | HASH JOIN | | | | | |
    | 10 | INDEX RANGE SCAN | IDX_CCI_DEL | 11033 | 258K| | 768 (1)|
    | 11 | INDEX RANGE SCAN | CS_CASE_INFO_UK | 11033 | 258K| | 821 (1)|
    | 12 | INDEX FAST FULL SCAN| IDX_NACL_RSH_ACC_NO | 5539K| 68M| | 5382 (1)|
    | 13 | TABLE ACCESS FULL | CS_CASE_DETAILS_ACLOS | 3670K| 192M| | 41477 (1)|
    | 14 | TABLE ACCESS FULL | CS_CASE_INFO | 304K| 205M| | 35975 (1)|
    Note
    - 'PLAN_TABLE' is old version
    24 rows selected.
    Elapsed: 00:00:01.04
    SQL> rollback;
    Rollback complete.
    Elapsed: 00:00:00.03
    SQL> set autotrace traceonly arraysize 100
    SQL> alter session set events '10046 trace name context forever, level 8';
    ERROR:
    ORA-01031: insufficient privileges
    Elapsed: 00:00:00.04
    SQL>      disconnect
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>      spool off
    Edited by: user4528984 on May 5, 2009 10:37 PM

    For one thing, alias your tables and use that in the column specifications (table1.column1 = table2.column3 for example)...
          SELECT
             DISTINCT
                acc_no acc_no
          FROM Table3, Table1
          WHERE acc_no            = appl_id
          AND   delinquent_flag   = 'Y'
          AND   financier_id      = 'NEWACLOS'We don't know what your tables look like, what columns come from where. Try and help us help you, assume we know NOTHING about YOUR system, because more likely than naught, that's going to be the case.
    In addition to that, please read through this which will give you a better-er idea of how to post a tuning related question, you've not provided near enough information for us to intelligently help you.
    HOW TO: Post a SQL statement tuning request - template posting

  • Using hints in MERGE statement

    i have a merge statement
    in that statement for select clause i am using index hints
    can i use it
    whether that will increase the performance or the reverse will happen
    any comments

    Hints should always be your last option. First try tune the sql without using any hints, most of the cases you will be ok. Over time when the table statistics(ex. rows) changes considerably hints may be negative impact.

  • FORALL MERGE statement works in local database but not over database link

    Given "list", a collection of NUMBER's, the following FORALL ... MERGE statement should copy the appropriate data if the record specified by the list exists on both databases.
    forall i in 1..list.count
    merge into tbl@remote t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    But this does not work. No exceptions, but target table's record is unchanged and "sql%rowcount" is 0.
    If the target table is in the local database, the exact same statement works:
    forall i in 1..list.count
    merge into tbl2 t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    Does anyone have a clue why this may be a problem?
    Both databases are on Oracle 10g.
    Edited by: user652538 on 2009. 6. 12 오전 11:29
    Edited by: user652538 on 2009. 6. 12 오전 11:31
    Edited by: user652538 on 2009. 6. 12 오전 11:45

    Should throw an error in my opinion. The underlying reason for not working is basically because of
    SQL> merge into   t@remote t1
         using   (    select   sys.odcinumberlist (1) from dual) t2
            on   (1 = 1)
    when matched
    then
       update set i = 1
    Error at line 4
    ORA-22804: remote operations not permitted on object tables or user-defined type columnsSame reason as e.g.
    insert into t@remote select * from table(sys.odcinumberlist(1,2,3))doesn't work.

Maybe you are looking for