Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Difference between Insert and Append?

Posted on 2011-03-08
16
Medium Priority
?
2,147 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

722 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