Solved

Difference between Insert and Append?

Posted on 2011-03-08
16
1,837 Views
Last Modified: 2012-05-11
Difference between Insert and Append in Oracle?
0
Comment
Question by:Rao_S
  • 6
  • 6
  • 4
16 Comments
 

Author Comment

by:Rao_S
ID: 35070768
My Insert statement in my packaed procedure only produced the following error:
ORA-00001: unique constraint (AEHER01.PKEH_ER_ERRORS_HISTORY) violated
0
 
LVL 6

Expert Comment

by:anumoses
ID: 35070874
This error is swince the record already exists. So instead of insert in the table , do an update on the table for the existing record
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35070934
There is no 'append' per say in Oracle.  There is an append hint that causes new rows to be 'inserted' above the High-Water mark but I don't think that is what you mean by that term.
0
 
LVL 6

Expert Comment

by:anumoses
ID: 35070959
append is  if you are using in a control file in sql loader?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35071128
There is that but since they mention a package and procedure I have to assume this inst related to sql loader.
0
 

Author Comment

by:Rao_S
ID: 35071223
Why does the Sql Loader use 'APPEND'?
-- SQL Loader Control and Data File created by TOAD
-- Variable length, terminated enclosed data formattingLOAD DATA
INFILE *
BADFILE './ERRORS.BAD'
DISCARDFILE './ERRORS.DSC'
APPEND INTO TABLE AEHER01.TEH_ER_ERRORS
Fields terminated by ";" Optionally enclosed by '"'
(
  ERROR_LOG_PK NULLIF (ERROR_LOG_PK="NULL"),
  MESSAGE_UNIQUE_ID,
  etc............
)
BEGINDATA
310;"11D1DEF534EA1BE0:-57DC5FF7:12767585035:-7FD6";
------------------------------------------------
0
 
LVL 6

Expert Comment

by:anumoses
ID: 35071273
So its not package or procedure as mentioned earlier. Its sql loader control file.
Whats your question? why sql loader used append instead of update?

The APPEND keyword tells SQL Loader to preserve any pre-existing data in the table.
0
 
LVL 6

Expert Comment

by:anumoses
ID: 35071280
sending a link to know more on sql loader


http://psoug.org/reference/sqlloader.html
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Rao_S
ID: 35071349
The error i get is when I execute a packed proc, but I was looking at a  Sql Loader file and I found an APPEND. Hence my question.
0
 
LVL 6

Expert Comment

by:anumoses
ID: 35071363
can you post the calling package procedure?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35071463
You need to ask a single question per question.  The answer to 'APPEND' as it relates to sql loader is answered above.

Why you are getting unique constraint violation, although also already answered, should really be a new question.
0
 

Author Comment

by:Rao_S
ID: 35071479
The calling proc is pretty simple: Here it is:
PROCEDURE SP_LOAD_HISTORY   IS
     
   BEGIN
             BEGIN
                     --call the procedure to insert HISTORY by passing key field values.
                     SP_INSERT_HISTORY_PASS1 ;            
            END;
               BEGIN
                      --call the procedure to insert HISTORY by passing key field values.
                      SP_INSERT_HISTORY_PASS2 ;            
            END;
     
   END;
0
 

Author Comment

by:Rao_S
ID: 35071493
Here is the Packaged Spec:
CREATE OR REPLACE PACKAGE AEHER02.SPKG_ER_LOAD_HISTORY AS
/******************************************************************************
   NAME:       AEHER02.SPKG_ER_LOAD_HISTORY
   PURPOSE:

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2/18/2011      CTZ6233       1. Created this package.
******************************************************************************/
 FUNCTION SF_GET_RETAINED_DAYS  (
      p_system_date                TIMESTAMP WITH LOCAL TIME ZONE,
      p_error_res_tmstp_date   TIMESTAMP WITH LOCAL TIME ZONE
      ) RETURN NUMBER;
   
   PROCEDURE SP_INSERT_HISTORY_PASS1 ;
       
    PROCEDURE SP_INSERT_HISTORY_PASS2 ;

   PROCEDURE SP_LOAD_HISTORY ;
     
   PROCEDURE SP_WRITE_LOG(
      p_error_log_pk                       NUMBER,
      p_message_unique_id             VARCHAR2,
      p_domain                               VARCHAR2,
      p_program_name                   VARCHAR2,
      p_error_res_tmstp                  DATE,
      p_entity_pk                            NUMBER,
      p_active_rentention_days        NUMBER,
      p_payload_retention_days       NUMBER,
      p_archive_retention_days        NUMBER,
      p_table_name                        VARCHAR2,
      p_rows_inserted                     NUMBER,
      p_rows_deleted                      NUMBER,
      p_error_message                   VARCHAR2) ;
     
     
END SPKG_ER_LOAD_HISTORY;

/
0
 
LVL 6

Accepted Solution

by:
anumoses earned 500 total points
ID: 35071607
Answers for your question posted is already given in the above. Please close this question by choosing the answer best fits your need and then ask a new question for the package error.
0
 

Author Comment

by:Rao_S
ID: 35071849
The package has 4 procs and a function. Its a pretty simple package actually.
The calling proc calls pass1 proc and pass2 proc, they in turn call the function to check if the row has to be written to a history table. If it is wrriten to a history table then the row is deleted from the main table. And I capture all errors and log in a log table so that I can schedule this job and check the log table next day.
I added the /*+ APPEND*/ hint to the insert statement and am running the proc, (its going to take 1/2 hr to run)  lets see what happens!
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35071875
The APPEND hint does nothing to solve the unique constraint violation.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now