• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2391
  • Last Modified:

Difference between Insert and Append?

Difference between Insert and Append in Oracle?
0
Rao_S
Asked:
Rao_S
  • 6
  • 6
  • 4
1 Solution
 
Rao_SAuthor Commented:
My Insert statement in my packaed procedure only produced the following error:
ORA-00001: unique constraint (AEHER01.PKEH_ER_ERRORS_HISTORY) violated
0
 
anumosesCommented:
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
 
slightwv (䄆 Netminder) Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
anumosesCommented:
append is  if you are using in a control file in sql loader?
0
 
slightwv (䄆 Netminder) Commented:
There is that but since they mention a package and procedure I have to assume this inst related to sql loader.
0
 
Rao_SAuthor Commented:
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
 
anumosesCommented:
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
 
anumosesCommented:
sending a link to know more on sql loader


http://psoug.org/reference/sqlloader.html
0
 
Rao_SAuthor Commented:
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
 
anumosesCommented:
can you post the calling package procedure?
0
 
slightwv (䄆 Netminder) Commented:
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
 
Rao_SAuthor Commented:
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
 
Rao_SAuthor Commented:
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
 
anumosesCommented:
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
 
Rao_SAuthor Commented:
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
 
slightwv (䄆 Netminder) Commented:
The APPEND hint does nothing to solve the unique constraint violation.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now