Solved

Difference between Insert and Append?

Posted on 2011-03-08
16
2,013 Views
Last Modified: 2012-05-11
Difference between Insert and Append in Oracle?
0
Comment
Question by:Rao_S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 77

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 6

Expert Comment

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

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
 

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 77

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 77

Expert Comment

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to recover a database from a user managed backup

734 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